Search in sources :

Example 96 with RendezvousAffinityFunction

use of org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction in project ignite by apache.

the class IgniteWalRecoverySeveralRestartsTest method getConfiguration.

/**
 * {@inheritDoc}
 */
@Override
protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(gridName);
    CacheConfiguration<Integer, IndexedObject> ccfg = new CacheConfiguration<>(cacheName);
    ccfg.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);
    ccfg.setRebalanceMode(CacheRebalanceMode.NONE);
    ccfg.setIndexedTypes(Integer.class, IndexedObject.class);
    ccfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
    // 64 per node
    ccfg.setAffinity(new RendezvousAffinityFunction(false, 64 * 4));
    ccfg.setReadFromBackup(true);
    cfg.setCacheConfiguration(ccfg);
    DataStorageConfiguration memCfg = new DataStorageConfiguration().setDefaultDataRegionConfiguration(new DataRegionConfiguration().setMaxSize(500 * 1024 * 1024).setPersistenceEnabled(true)).setWalMode(WALMode.LOG_ONLY).setPageSize(PAGE_SIZE);
    cfg.setDataStorageConfiguration(memCfg);
    cfg.setMarshaller(null);
    BinaryConfiguration binCfg = new BinaryConfiguration();
    binCfg.setCompactFooter(false);
    cfg.setBinaryConfiguration(binCfg);
    return cfg;
}
Also used : DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) BinaryConfiguration(org.apache.ignite.configuration.BinaryConfiguration) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 97 with RendezvousAffinityFunction

use of org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction in project ignite by apache.

the class IgniteWalRecoverySeveralRestartsTest method testWalRecoveryWithDynamicCacheLargeObjects.

/**
 * @throws Exception if failed.
 */
public void testWalRecoveryWithDynamicCacheLargeObjects() throws Exception {
    try {
        IgniteEx ignite = startGrid(1);
        ignite.active(true);
        CacheConfiguration<Integer, IndexedObject> dynCacheCfg = new CacheConfiguration<>();
        dynCacheCfg.setName("dyncache");
        dynCacheCfg.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);
        dynCacheCfg.setRebalanceMode(CacheRebalanceMode.NONE);
        dynCacheCfg.setIndexedTypes(Integer.class, IndexedObject.class);
        dynCacheCfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
        // 64 per node
        dynCacheCfg.setAffinity(new RendezvousAffinityFunction(false, 64 * 4));
        dynCacheCfg.setReadFromBackup(true);
        ignite.getOrCreateCache(dynCacheCfg);
        try (IgniteDataStreamer<Integer, IndexedObject> dataLdr = ignite.dataStreamer("dyncache")) {
            for (int i = 0; i < LARGE_KEYS_COUNT; ++i) {
                if (i % (LARGE_KEYS_COUNT / 100) == 0)
                    info("Loading " + i * 100 / LARGE_KEYS_COUNT + "%");
                IndexedObject obj = new IndexedObject(i);
                obj.payload = new byte[PAGE_SIZE + 2];
                dataLdr.addData(i, obj);
            }
        }
        for (int restartCnt = 0; restartCnt < 5; ++restartCnt) {
            stopGrid(1, true);
            info("Restart #" + restartCnt);
            U.sleep(500);
            ignite = startGrid(1);
            ignite.active(true);
            ThreadLocalRandom locRandom = ThreadLocalRandom.current();
            IgniteCache<Integer, IndexedObject> cache = ignite.getOrCreateCache(dynCacheCfg);
            for (int i = 0; i < LARGE_KEYS_COUNT; ++i) {
                IndexedObject val = cache.get(locRandom.nextInt(LARGE_KEYS_COUNT));
                assertNotNull(val);
                assertEquals(PAGE_SIZE + 2, val.payload.length);
            }
        }
    } finally {
        stopAllGrids();
    }
}
Also used : IgniteEx(org.apache.ignite.internal.IgniteEx) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 98 with RendezvousAffinityFunction

use of org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction in project ignite by apache.

the class IgniteWalRecoveryTest method getConfiguration.

/**
 * {@inheritDoc}
 */
@Override
protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(gridName);
    CacheConfiguration<Integer, IndexedObject> ccfg = new CacheConfiguration<>(cacheName);
    ccfg.setAtomicityMode(CacheAtomicityMode.ATOMIC);
    ccfg.setRebalanceMode(CacheRebalanceMode.SYNC);
    ccfg.setAffinity(new RendezvousAffinityFunction(false, 32));
    ccfg.setNodeFilter(new RemoteNodeFilter());
    ccfg.setIndexedTypes(Integer.class, IndexedObject.class);
    cfg.setCacheConfiguration(ccfg);
    DataStorageConfiguration dbCfg = new DataStorageConfiguration();
    dbCfg.setPageSize(4 * 1024);
    DataRegionConfiguration memPlcCfg = new DataRegionConfiguration();
    memPlcCfg.setName("dfltDataRegion");
    memPlcCfg.setInitialSize(1024 * 1024 * 1024);
    memPlcCfg.setMaxSize(1024 * 1024 * 1024);
    memPlcCfg.setPersistenceEnabled(true);
    dbCfg.setDefaultDataRegionConfiguration(memPlcCfg);
    dbCfg.setWalRecordIteratorBufferSize(1024 * 1024);
    dbCfg.setWalHistorySize(2);
    if (logOnly)
        dbCfg.setWalMode(WALMode.LOG_ONLY);
    if (walSegmentSize != 0)
        dbCfg.setWalSegmentSize(walSegmentSize);
    cfg.setDataStorageConfiguration(dbCfg);
    cfg.setMarshaller(null);
    BinaryConfiguration binCfg = new BinaryConfiguration();
    binCfg.setCompactFooter(false);
    cfg.setBinaryConfiguration(binCfg);
    if (!getTestIgniteInstanceName(0).equals(gridName))
        cfg.setUserAttributes(F.asMap(HAS_CACHE, true));
    return cfg;
}
Also used : DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) BinaryConfiguration(org.apache.ignite.configuration.BinaryConfiguration) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 99 with RendezvousAffinityFunction

use of org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction in project ignite by apache.

the class IgniteWalRecoveryTest method testTxRecordsConsistency.

/**
 * Test that all DataRecord WAL records are within transaction boundaries - PREPARED and COMMITTED markers.
 *
 * @throws Exception If any fail.
 */
public void testTxRecordsConsistency() throws Exception {
    System.setProperty(IgniteSystemProperties.IGNITE_WAL_LOG_TX_RECORDS, "true");
    IgniteEx ignite = (IgniteEx) startGrids(3);
    ignite.active(true);
    try {
        final String cacheName = "transactional";
        CacheConfiguration<Object, Object> cacheConfiguration = new CacheConfiguration<>(cacheName).setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL).setAffinity(new RendezvousAffinityFunction(false, 32)).setCacheMode(CacheMode.PARTITIONED).setRebalanceMode(CacheRebalanceMode.SYNC).setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC).setBackups(0);
        ignite.createCache(cacheConfiguration);
        IgniteCache<Object, Object> cache = ignite.cache(cacheName);
        GridCacheSharedContext<Object, Object> sharedCtx = ignite.context().cache().context();
        GridCacheDatabaseSharedManager db = (GridCacheDatabaseSharedManager) sharedCtx.database();
        db.waitForCheckpoint("test");
        db.enableCheckpoints(false).get();
        // Log something to know where to start.
        WALPointer startPtr = sharedCtx.wal().log(new MemoryRecoveryRecord(U.currentTimeMillis()));
        final int transactions = 100;
        final int operationsPerTransaction = 40;
        Random random = new Random();
        for (int t = 1; t <= transactions; t++) {
            Transaction tx = ignite.transactions().txStart(TransactionConcurrency.OPTIMISTIC, TransactionIsolation.READ_COMMITTED);
            for (int op = 0; op < operationsPerTransaction; op++) {
                int key = random.nextInt(1000) + 1;
                Object value;
                if (random.nextBoolean())
                    value = randomString(random) + key;
                else
                    value = new BigObject(key);
                cache.put(key, value);
            }
            if (random.nextBoolean()) {
                tx.commit();
            } else {
                tx.rollback();
            }
            if (t % 50 == 0)
                log.info("Finished transaction " + t);
        }
        Set<GridCacheVersion> activeTransactions = new HashSet<>();
        // Check that all DataRecords are within PREPARED and COMMITTED tx records.
        try (WALIterator it = sharedCtx.wal().replay(startPtr)) {
            while (it.hasNext()) {
                IgniteBiTuple<WALPointer, WALRecord> tup = it.next();
                WALRecord rec = tup.get2();
                if (rec instanceof TxRecord) {
                    TxRecord txRecord = (TxRecord) rec;
                    GridCacheVersion txId = txRecord.nearXidVersion();
                    switch(txRecord.state()) {
                        case PREPARED:
                            assert !activeTransactions.contains(txId) : "Transaction is already present " + txRecord;
                            activeTransactions.add(txId);
                            break;
                        case COMMITTED:
                            assert activeTransactions.contains(txId) : "No PREPARE marker for transaction " + txRecord;
                            activeTransactions.remove(txId);
                            break;
                        case ROLLED_BACK:
                            activeTransactions.remove(txId);
                            break;
                        default:
                            throw new IllegalStateException("Unknown Tx state of record " + txRecord);
                    }
                } else if (rec instanceof DataRecord) {
                    DataRecord dataRecord = (DataRecord) rec;
                    for (DataEntry entry : dataRecord.writeEntries()) {
                        GridCacheVersion txId = entry.nearXidVersion();
                        assert activeTransactions.contains(txId) : "No transaction for entry " + entry;
                    }
                }
            }
        }
    } finally {
        System.clearProperty(IgniteSystemProperties.IGNITE_WAL_LOG_TX_RECORDS);
        stopAllGrids();
    }
}
Also used : WALRecord(org.apache.ignite.internal.pagemem.wal.record.WALRecord) MemoryRecoveryRecord(org.apache.ignite.internal.pagemem.wal.record.MemoryRecoveryRecord) DataEntry(org.apache.ignite.internal.pagemem.wal.record.DataEntry) GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) Random(java.util.Random) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) WALIterator(org.apache.ignite.internal.pagemem.wal.WALIterator) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) DataRecord(org.apache.ignite.internal.pagemem.wal.record.DataRecord) WALPointer(org.apache.ignite.internal.pagemem.wal.WALPointer) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) HashSet(java.util.HashSet) GridCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager) TxRecord(org.apache.ignite.internal.pagemem.wal.record.TxRecord) Transaction(org.apache.ignite.transactions.Transaction) IgniteEx(org.apache.ignite.internal.IgniteEx)

Example 100 with RendezvousAffinityFunction

use of org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction in project ignite by apache.

the class WalCompactionTest method getConfiguration.

/**
 * {@inheritDoc}
 */
@Override
protected IgniteConfiguration getConfiguration(String name) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(name);
    cfg.setDiscoverySpi(new TcpDiscoverySpi().setIpFinder(IP_FINDER));
    cfg.setDataStorageConfiguration(new DataStorageConfiguration().setDefaultDataRegionConfiguration(new DataRegionConfiguration().setPersistenceEnabled(true).setMaxSize(200 * 1024 * 1024)).setWalMode(WALMode.LOG_ONLY).setWalSegmentSize(WAL_SEGMENT_SIZE).setWalHistorySize(500).setWalCompactionEnabled(true));
    CacheConfiguration ccfg = new CacheConfiguration();
    ccfg.setName("cache");
    ccfg.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);
    ccfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
    ccfg.setAffinity(new RendezvousAffinityFunction(false, 16));
    ccfg.setBackups(0);
    cfg.setCacheConfiguration(ccfg);
    cfg.setConsistentId(name);
    return cfg;
}
Also used : DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) TcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)

Aggregations

RendezvousAffinityFunction (org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction)142 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)126 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)71 TcpDiscoverySpi (org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)48 DataRegionConfiguration (org.apache.ignite.configuration.DataRegionConfiguration)33 DataStorageConfiguration (org.apache.ignite.configuration.DataStorageConfiguration)33 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)11 Ignite (org.apache.ignite.Ignite)11 IgniteEx (org.apache.ignite.internal.IgniteEx)11 BinaryConfiguration (org.apache.ignite.configuration.BinaryConfiguration)10 NearCacheConfiguration (org.apache.ignite.configuration.NearCacheConfiguration)10 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)8 AffinityFunction (org.apache.ignite.cache.affinity.AffinityFunction)8 ArrayList (java.util.ArrayList)7 Random (java.util.Random)7 IgniteCache (org.apache.ignite.IgniteCache)7 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)7 QueryEntity (org.apache.ignite.cache.QueryEntity)4 Transaction (org.apache.ignite.transactions.Transaction)4 GridCacheDatabaseSharedManager (org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager)3