Search in sources :

Example 1 with DmsDataWriterWorker

use of org.apache.ignite.internal.processors.metastorage.persistence.DmsDataWriterWorker in project ignite by apache.

the class IgniteSnapshotWithMetastorageTest method testMetastorageUpdateDuringSnapshot.

/**
 * @throws Exception If fails.
 */
@Test
public void testMetastorageUpdateDuringSnapshot() throws Exception {
    AtomicInteger keyCnt = new AtomicInteger();
    AtomicBoolean stop = new AtomicBoolean();
    CountDownLatch latch = new CountDownLatch(1);
    IgniteEx ignite = startGridsWithCache(2, dfltCacheCfg, CACHE_KEYS_RANGE);
    IgniteInternalFuture<?> updFut = GridTestUtils.runMultiThreadedAsync(() -> {
        while (!Thread.currentThread().isInterrupted() && !stop.get()) {
            try {
                ignite.context().distributedMetastorage().write(SNAPSHOT_PREFIX + keyCnt.getAndIncrement(), "value");
            } catch (IgniteCheckedException e) {
                throw new IgniteException(e);
            }
        }
    }, 3, "dms-updater");
    DmsDataWriterWorker worker = GridTestUtils.getFieldValue(ignite.context().distributedMetastorage(), DistributedMetaStorageImpl.class, "worker");
    LinkedBlockingQueue<RunnableFuture<?>> queue = GridTestUtils.getFieldValue(worker, DmsDataWriterWorker.class, "updateQueue");
    RunnableFuture<?> testTask = new FutureTask<>(() -> {
        U.await(latch);
        return null;
    });
    queue.offer(testTask);
    assertTrue(GridTestUtils.waitForCondition(() -> queue.size() > 10, getTestTimeout()));
    ignite.context().cache().context().exchange().registerExchangeAwareComponent(new PartitionsExchangeAware() {

        /**
         * {@inheritDoc}
         */
        @Override
        public void onInitAfterTopologyLock(GridDhtPartitionsExchangeFuture fut) {
            latch.countDown();
        }
    });
    ignite.snapshot().createSnapshot(SNAPSHOT_NAME).get();
    stop.set(true);
    updFut.get();
    stopAllGrids();
    Function<IgniteConfiguration, String> pathProv = cfg -> resolveSnapshotWorkDirectory(cfg).getAbsolutePath();
    Set<String> keySet0 = new TreeSet<>();
    Set<String> keySet1 = new TreeSet<>();
    IgniteEx snp0 = startGridsFromSnapshot(Collections.singleton(0), pathProv, SNAPSHOT_NAME, false);
    snp0.context().distributedMetastorage().iterate(SNAPSHOT_PREFIX, (key, val) -> keySet0.add(key));
    stopGrid(0);
    IgniteEx snp1 = startGridsFromSnapshot(Collections.singleton(1), pathProv, SNAPSHOT_NAME, false);
    snp1.context().distributedMetastorage().iterate(SNAPSHOT_PREFIX, (key, val) -> keySet1.add(key));
    assertEquals("Keys must be the same on all nodes", keySet0, keySet1);
}
Also used : IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) FutureTask(java.util.concurrent.FutureTask) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) U(org.apache.ignite.internal.util.typedef.internal.U) IgniteSnapshotManager.resolveSnapshotWorkDirectory(org.apache.ignite.internal.processors.cache.persistence.snapshot.IgniteSnapshotManager.resolveSnapshotWorkDirectory) IgniteEx(org.apache.ignite.internal.IgniteEx) Function(java.util.function.Function) TreeSet(java.util.TreeSet) GridCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GridDhtPartitionsExchangeFuture(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture) Map(java.util.Map) CheckpointListener(org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointListener) DistributedMetaStorageImpl(org.apache.ignite.internal.processors.metastorage.persistence.DistributedMetaStorageImpl) RunnableFuture(java.util.concurrent.RunnableFuture) DmsDataWriterWorker(org.apache.ignite.internal.processors.metastorage.persistence.DmsDataWriterWorker) IgniteFuture(org.apache.ignite.lang.IgniteFuture) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) Set(java.util.Set) Test(org.junit.Test) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) GridTestUtils(org.apache.ignite.testframework.GridTestUtils) PartitionsExchangeAware(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.PartitionsExchangeAware) CountDownLatch(java.util.concurrent.CountDownLatch) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) ConcurrentSkipListSet(java.util.concurrent.ConcurrentSkipListSet) Collections(java.util.Collections) GridDhtPartitionsExchangeFuture(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture) CountDownLatch(java.util.concurrent.CountDownLatch) PartitionsExchangeAware(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.PartitionsExchangeAware) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) DmsDataWriterWorker(org.apache.ignite.internal.processors.metastorage.persistence.DmsDataWriterWorker) FutureTask(java.util.concurrent.FutureTask) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteException(org.apache.ignite.IgniteException) TreeSet(java.util.TreeSet) IgniteEx(org.apache.ignite.internal.IgniteEx) RunnableFuture(java.util.concurrent.RunnableFuture) Test(org.junit.Test)

Aggregations

Collections (java.util.Collections)1 Map (java.util.Map)1 Set (java.util.Set)1 TreeSet (java.util.TreeSet)1 ConcurrentSkipListSet (java.util.concurrent.ConcurrentSkipListSet)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 FutureTask (java.util.concurrent.FutureTask)1 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)1 RunnableFuture (java.util.concurrent.RunnableFuture)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Function (java.util.function.Function)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 IgniteException (org.apache.ignite.IgniteException)1 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)1 IgniteEx (org.apache.ignite.internal.IgniteEx)1 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)1 GridDhtPartitionsExchangeFuture (org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture)1 PartitionsExchangeAware (org.apache.ignite.internal.processors.cache.distributed.dht.preloader.PartitionsExchangeAware)1 GridCacheDatabaseSharedManager (org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager)1