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);
}
Aggregations