Search in sources :

Example 81 with GridCacheDatabaseSharedManager

use of org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager in project ignite by apache.

the class IgniteWalRecoveryTest method testAbsentDeadlock_Iterator_RollOver_Archivation.

/**
 * @throws Exception if failed.
 */
@Test
public void testAbsentDeadlock_Iterator_RollOver_Archivation() throws Exception {
    walSegments = 2;
    walSegmentSize = 512 * 1024;
    IgniteEx ignite0 = (IgniteEx) startGrid("node0");
    ignite0.active(true);
    IgniteCache<Object, Object> cache0 = ignite0.cache(CACHE_NAME);
    for (int i = 0; i < 100; i++) cache0.put(i, new IndexedObject(i));
    GridCacheSharedContext<Object, Object> sharedCtx = ignite0.context().cache().context();
    GridCacheDatabaseSharedManager db = (GridCacheDatabaseSharedManager) sharedCtx.database();
    db.waitForCheckpoint("test");
    db.enableCheckpoints(false).get();
    // Log something to know where to start.
    WALPointer ptr = sharedCtx.wal().log(new MemoryRecoveryRecord(U.currentTimeMillis()));
    info("Replay marker: " + ptr);
    for (int i = 100; i < 200; i++) cache0.put(i, new IndexedObject(i));
    CountDownLatch insertFinished = new CountDownLatch(1);
    GridTestUtils.runAsync(() -> {
        try (WALIterator it = sharedCtx.wal().replay(ptr)) {
            if (it.hasNext()) {
                it.next();
                insertFinished.await();
            }
        }
        return null;
    });
    IgniteInternalFuture<Object> future = GridTestUtils.runAsync(() -> {
        for (int i = 0; i < 10000; i++) cache0.put(i, new IndexedObject(i));
        return null;
    });
    future.get();
    insertFinished.countDown();
    ignite0.close();
}
Also used : GridCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager) WALIterator(org.apache.ignite.internal.pagemem.wal.WALIterator) IgniteEx(org.apache.ignite.internal.IgniteEx) CountDownLatch(java.util.concurrent.CountDownLatch) WALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer) MemoryRecoveryRecord(org.apache.ignite.internal.pagemem.wal.record.MemoryRecoveryRecord) Test(org.junit.Test) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)

Example 82 with GridCacheDatabaseSharedManager

use of org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager 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.
 */
@Test
public void testTxRecordsConsistency() throws Exception {
    IgniteEx ignite = startGrids(3);
    ignite.cluster().state(ClusterState.ACTIVE);
    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 = random.nextBoolean() ? randomString(random) + key : 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 (int i = 0; i < dataRecord.entryCount(); i++) {
                    DataEntry entry = dataRecord.get(i);
                    GridCacheVersion txId = entry.nearXidVersion();
                    assert activeTransactions.contains(txId) : "No transaction for entry " + entry;
                }
            }
        }
    }
}
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) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) Random(java.util.Random) 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.processors.cache.persistence.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) Test(org.junit.Test) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)

Example 83 with GridCacheDatabaseSharedManager

use of org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager in project ignite by apache.

the class CleanupIndexTreeCheckpointFailoverTest method testCorruptedTree.

/**
 * @throws Exception if failed.
 */
@Test
public void testCorruptedTree() throws Exception {
    cleanPersistenceDir();
    IgniteEx ig = startGrid(0);
    ig.cluster().state(ClusterState.ACTIVE);
    CacheConfiguration<Key, Value> cfg = new CacheConfiguration<Key, Value>().setIndexedTypes(Key.class, Value.class).setName("test");
    IgniteCache<Key, Value> cache = ig.getOrCreateCache(cfg);
    cache.query(new SqlFieldsQuery("create index myindex on value (a asc)")).getAll();
    for (int i = 0; i < 5000; i++) cache.put(new Key(i), new Value(String.valueOf(i), "b" + i));
    ig.context().cache().context().database().wakeupForCheckpoint("test").get();
    cache.query(new SqlFieldsQuery("drop index myindex")).getAll();
    GridCacheDatabaseSharedManager dbMgr = (GridCacheDatabaseSharedManager) ig.context().cache().context().database();
    U.sleep(1000);
    dbMgr.enableCheckpoints(false);
    stopGrid(0, true);
    ig = startGrid(0);
    cache = ig.cache("test");
    for (int i = 0; i < 5000; i += 2) cache.remove(new Key(i));
    cache.query(new SqlFieldsQuery("create index myindex on value (a asc)")).getAll();
    for (int i = 0; i < 5000; i++) cache.put(new Key(i), new Value(String.valueOf(i), "b" + i));
}
Also used : GridCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager) IgniteEx(org.apache.ignite.internal.IgniteEx) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 84 with GridCacheDatabaseSharedManager

use of org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager in project ignite by apache.

the class IgniteDbSingleNodeWithIndexingWalRestoreTest method testRegularClassesRestored.

/**
 * Test for regular objects stored in cache with compactFooter=true setting
 * (no metainformation to deserialize values is stored with values themselves).
 */
@Test
public void testRegularClassesRestored() throws Exception {
    IgniteEx ig = startGrid(0);
    ig.active(true);
    GridCacheDatabaseSharedManager dbMgr = (GridCacheDatabaseSharedManager) ig.context().cache().context().database();
    dbMgr.enableCheckpoints(false).get();
    IgniteCache<Object, Object> cache = ig.cache("indexedCache");
    for (int i = 0; i < ENTRIES_COUNT; i++) cache.put(i, new RegularPerson("RegularPeter" + i));
    stopGrid(0, true);
    ig = startGrid(0);
    ig.active(true);
    cache = ig.cache("indexedCache");
    for (int i = 0; i < ENTRIES_COUNT; i++) assertEquals("RegularPeter" + i, ((RegularPerson) cache.get(i)).regName);
}
Also used : GridCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager) IgniteEx(org.apache.ignite.internal.IgniteEx) BinaryObject(org.apache.ignite.binary.BinaryObject) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 85 with GridCacheDatabaseSharedManager

use of org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager in project ignite by apache.

the class IgnitePersistentStoreSchemaLoadTest method checkpointLatch.

/**
 * @param node Node whose checkpoint to wait for.
 * @return Latch released when checkpoint happens.
 */
private CountDownLatch checkpointLatch(IgniteEx node) {
    final CountDownLatch cnt = new CountDownLatch(1);
    GridCacheDatabaseSharedManager db = (GridCacheDatabaseSharedManager) node.context().cache().context().database();
    db.addCheckpointListener(new CheckpointListener() {

        @Override
        public void onMarkCheckpointBegin(Context ctx) {
            cnt.countDown();
        }

        @Override
        public void beforeCheckpointBegin(Context ctx) throws IgniteCheckedException {
        }

        @Override
        public void onCheckpointBegin(Context ctx) {
        /* No-op. */
        }
    });
    return cnt;
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager) CheckpointListener(org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointListener) CountDownLatch(java.util.concurrent.CountDownLatch)

Aggregations

GridCacheDatabaseSharedManager (org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager)85 IgniteEx (org.apache.ignite.internal.IgniteEx)54 Test (org.junit.Test)48 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)33 Ignite (org.apache.ignite.Ignite)20 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)17 RendezvousAffinityFunction (org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction)17 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)16 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)15 ArrayList (java.util.ArrayList)13 File (java.io.File)12 DataStorageConfiguration (org.apache.ignite.configuration.DataStorageConfiguration)12 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)12 List (java.util.List)10 IgniteWriteAheadLogManager (org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager)10 WALPointer (org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer)10 CountDownLatch (java.util.concurrent.CountDownLatch)9 IgniteCache (org.apache.ignite.IgniteCache)9 GridCacheSharedContext (org.apache.ignite.internal.processors.cache.GridCacheSharedContext)9 CheckpointListener (org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointListener)9