Search in sources :

Example 16 with CheckpointListener

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

the class CheckpointFreeListTest method testFreeListUnderLoadMultipleCheckpoints.

/**
 * Test checks that free-list works and pages cache flushes correctly under the high concurrent load.
 */
@Test
public void testFreeListUnderLoadMultipleCheckpoints() throws Throwable {
    IgniteEx ignite = startGrid(0);
    ignite.cluster().active(true);
    int minValSize = 64;
    int maxValSize = 128;
    int valsCnt = maxValSize - minValSize;
    int keysCnt = 1_000;
    byte[][] vals = new byte[valsCnt][];
    for (int i = 0; i < valsCnt; i++) vals[i] = new byte[minValSize + i];
    IgniteCache<Object, Object> cache = ignite.createCache(new CacheConfiguration<>(DEFAULT_CACHE_NAME).setAffinity(// Maximize contention per partition.
    new RendezvousAffinityFunction().setPartitions(2)).setAtomicityMode(CacheAtomicityMode.ATOMIC));
    AtomicBoolean done = new AtomicBoolean();
    AtomicReference<Throwable> error = new AtomicReference<>();
    GridCacheDatabaseSharedManager db = (GridCacheDatabaseSharedManager) ignite.context().cache().context().database();
    AtomicLong pageListCacheLimitHolder = db.pageListCacheLimitHolder(ignite.context().cache().cache(DEFAULT_CACHE_NAME).context().dataRegion());
    long initPageListCacheLimit = pageListCacheLimitHolder.get();
    // Add listener after cache is started, so this listener will be triggered after listener for cache.
    db.addCheckpointListener(new CheckpointListener() {

        @Override
        public void onMarkCheckpointBegin(Context ctx) throws IgniteCheckedException {
            // Need to wait for condition here, since checkpointer can store free-list metadata asynchronously.
            if (!waitForCondition(() -> initPageListCacheLimit == pageListCacheLimitHolder.get(), 1_000L)) {
                IgniteCheckedException e = new IgniteCheckedException("Page list cache limit doesn't restored " + "correctly [init=" + initPageListCacheLimit + ", cur=" + pageListCacheLimitHolder.get() + ']');
                error.set(e);
                throw e;
            }
        }

        @Override
        public void onCheckpointBegin(Context ctx) {
        // No-op.
        }

        @Override
        public void beforeCheckpointBegin(Context ctx) {
        // No-op.
        }
    });
    IgniteInternalFuture<Long> fut = GridTestUtils.runMultiThreadedAsync(() -> {
        Random rnd = new Random();
        try {
            while (!done.get()) {
                int key = rnd.nextInt(keysCnt);
                byte[] val = vals[rnd.nextInt(valsCnt)];
                // Put with changed value size - worst case for free list, since row will be removed first and
                // then inserted again.
                cache.put(key, val);
            }
        } catch (Throwable t) {
            error.set(t);
        }
    }, 20, "cache-put");
    for (int i = 0; i < SF.applyLB(10, 2); i++) {
        if (error.get() != null)
            break;
        forceCheckpoint(ignite);
        doSleep(1_000L);
    }
    done.set(true);
    fut.get();
    stopAllGrids();
    if (error.get() != null)
        throw error.get();
}
Also used : GridCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager) CheckpointListener(org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointListener) AtomicReference(java.util.concurrent.atomic.AtomicReference) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicLong(java.util.concurrent.atomic.AtomicLong) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) Random(java.util.Random) IgniteEx(org.apache.ignite.internal.IgniteEx) AtomicLong(java.util.concurrent.atomic.AtomicLong) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 17 with CheckpointListener

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

the class ResumeCreateIndexTest method awaitBeforeCheckpointBeginAsync.

/**
 * Waiting for a {@link CheckpointListener#beforeCheckpointBegin} asynchronously
 * for a checkpoint for a specific reason.
 *
 * @param n Node.
 * @param reason Checkpoint reason.
 * @return Future for waiting for the {@link CheckpointListener#beforeCheckpointBegin}.
 */
private IgniteInternalFuture<Void> awaitBeforeCheckpointBeginAsync(IgniteEx n, String reason) {
    GridFutureAdapter<Void> fut = new GridFutureAdapter<>();
    dbMgr(n).addCheckpointListener(new CheckpointListener() {

        /**
         * {@inheritDoc}
         */
        @Override
        public void onMarkCheckpointBegin(Context ctx) {
        // No-op.
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public void onCheckpointBegin(Context ctx) {
        // No-op.
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public void beforeCheckpointBegin(Context ctx) {
            if (reason.equals(ctx.progress().reason()))
                fut.onDone();
        }
    });
    return fut;
}
Also used : CheckpointListener(org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointListener) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter)

Example 18 with CheckpointListener

use of org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointListener 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)

Example 19 with CheckpointListener

use of org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointListener in project gridgain by gridgain.

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)

Example 20 with CheckpointListener

use of org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointListener in project gridgain by gridgain.

the class MetaStorage method init.

/**
 */
public void init(GridCacheDatabaseSharedManager db) throws IgniteCheckedException {
    dataRegion.metrics().clear();
    initInternal(db);
    if (!PRESERVE_LEGACY_METASTORAGE_PARTITION_ID) {
        if (partId == OLD_METASTORE_PARTITION)
            db.temporaryMetaStorage(copyDataToTmpStorage());
        else if (db.temporaryMetaStorage() != null) {
            restoreDataFromTmpStorage(db.temporaryMetaStorage());
            db.temporaryMetaStorage(null);
            db.addCheckpointListener(new CheckpointListener() {

                @Override
                public void onMarkCheckpointBegin(Context ctx) {
                }

                @Override
                public void onCheckpointBegin(Context ctx) throws IgniteCheckedException {
                    assert cctx.pageStore() != null;
                    int partTag = ((PageMemoryEx) dataRegion.pageMemory()).invalidate(METASTORAGE_CACHE_ID, OLD_METASTORE_PARTITION);
                    cctx.pageStore().truncate(METASTORAGE_CACHE_ID, OLD_METASTORE_PARTITION, partTag);
                    int idxTag = ((PageMemoryEx) dataRegion.pageMemory()).invalidate(METASTORAGE_CACHE_ID, PageIdAllocator.INDEX_PARTITION);
                    PageStore store = ((FilePageStoreManager) cctx.pageStore()).getStore(METASTORAGE_CACHE_ID, PageIdAllocator.INDEX_PARTITION);
                    store.truncate(idxTag);
                    db.removeCheckpointListener(this);
                }

                @Override
                public void beforeCheckpointBegin(Context ctx) {
                }
            }, dataRegion);
        }
    }
}
Also used : GridCacheSharedContext(org.apache.ignite.internal.processors.cache.GridCacheSharedContext) CheckpointListener(org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointListener) PageMemoryEx(org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryEx) PageStore(org.apache.ignite.internal.pagemem.store.PageStore) FilePageStoreManager(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager)

Aggregations

CheckpointListener (org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointListener)25 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)17 IgniteEx (org.apache.ignite.internal.IgniteEx)15 Test (org.junit.Test)14 GridCacheDatabaseSharedManager (org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager)12 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)10 CountDownLatch (java.util.concurrent.CountDownLatch)9 GridFutureAdapter (org.apache.ignite.internal.util.future.GridFutureAdapter)8 IgniteException (org.apache.ignite.IgniteException)7 CacheGroupContext (org.apache.ignite.internal.processors.cache.CacheGroupContext)6 GridCacheSharedContext (org.apache.ignite.internal.processors.cache.GridCacheSharedContext)6 RendezvousAffinityFunction (org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction)5 Map (java.util.Map)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)4 TestRecordingCommunicationSpi (org.apache.ignite.internal.TestRecordingCommunicationSpi)4 GridDhtPartitionDemandMessage (org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionDemandMessage)4 GridDhtPartitionsExchangeFuture (org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture)4