use of org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager.PART_FILE_PREFIX in project ignite by apache.
the class IgniteClusterSnapshotRestoreSelfTest method testNodeFailDuringFilesCopy.
/**
* @throws Exception If failed.
*/
@Test
public void testNodeFailDuringFilesCopy() throws Exception {
dfltCacheCfg.setCacheMode(CacheMode.REPLICATED).setAffinity(new RendezvousAffinityFunction());
startGridsWithSnapshot(3, CACHE_KEYS_RANGE);
TestRecordingCommunicationSpi spi = TestRecordingCommunicationSpi.spi(grid(2));
CountDownLatch stopLatch = new CountDownLatch(1);
spi.blockMessages((node, msg) -> msg instanceof SingleNodeMessage && ((SingleNodeMessage<?>) msg).type() == RESTORE_CACHE_GROUP_SNAPSHOT_PRELOAD.ordinal());
String failingFilePath = Paths.get(CACHE_DIR_PREFIX + DEFAULT_CACHE_NAME, PART_FILE_PREFIX + (dfltCacheCfg.getAffinity().partitions() / 2) + FILE_SUFFIX).toString();
grid(2).context().cache().context().snapshotMgr().ioFactory(new CustomFileIOFactory(new RandomAccessFileIOFactory(), file -> {
if (file.getPath().endsWith(failingFilePath)) {
stopLatch.countDown();
throw new RuntimeException("Test exception");
}
}));
File node2dbDir = ((FilePageStoreManager) grid(2).context().cache().context().pageStore()).cacheWorkDir(dfltCacheCfg).getParentFile();
IgniteInternalFuture<Object> stopFut = runAsync(() -> {
U.await(stopLatch, TIMEOUT, TimeUnit.MILLISECONDS);
stopGrid(2, true);
return null;
});
IgniteFuture<Void> fut = grid(0).snapshot().restoreSnapshot(SNAPSHOT_NAME, Collections.singleton(DEFAULT_CACHE_NAME));
stopFut.get(TIMEOUT);
GridTestUtils.assertThrowsAnyCause(log, () -> fut.get(TIMEOUT), ClusterTopologyCheckedException.class, null);
File[] files = node2dbDir.listFiles(file -> file.getName().startsWith(TMP_CACHE_DIR_PREFIX));
assertEquals("A temp directory with potentially corrupted files must exist.", 1, files.length);
ensureCacheAbsent(dfltCacheCfg);
dfltCacheCfg = null;
startGrid(2);
files = node2dbDir.listFiles(file -> file.getName().startsWith(TMP_CACHE_DIR_PREFIX));
assertEquals("A temp directory should be removed at node startup", 0, files.length);
waitForEvents(EVT_CLUSTER_SNAPSHOT_RESTORE_STARTED, EVT_CLUSTER_SNAPSHOT_RESTORE_FAILED);
}
Aggregations