Search in sources :

Example 1 with EVT_CLUSTER_SNAPSHOT_RESTORE_STARTED

use of org.apache.ignite.events.EventType.EVT_CLUSTER_SNAPSHOT_RESTORE_STARTED 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);
}
Also used : IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) BinaryObject(org.apache.ignite.binary.BinaryObject) Arrays(java.util.Arrays) IgniteEx(org.apache.ignite.internal.IgniteEx) PART_FILE_PREFIX(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager.PART_FILE_PREFIX) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) GridTestUtils.runAsync(org.apache.ignite.testframework.GridTestUtils.runAsync) FileIO(org.apache.ignite.internal.processors.cache.persistence.file.FileIO) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DistributedProcessType(org.apache.ignite.internal.util.distributed.DistributedProcess.DistributedProcessType) Path(java.nio.file.Path) TMP_CACHE_DIR_PREFIX(org.apache.ignite.internal.processors.cache.persistence.snapshot.SnapshotRestoreProcess.TMP_CACHE_DIR_PREFIX) GridTestUtils.assertThrowsAnyCause(org.apache.ignite.testframework.GridTestUtils.assertThrowsAnyCause) EVT_CLUSTER_SNAPSHOT_RESTORE_FINISHED(org.apache.ignite.events.EventType.EVT_CLUSTER_SNAPSHOT_RESTORE_FINISHED) IgniteFuture(org.apache.ignite.lang.IgniteFuture) RandomAccessFileIOFactory(org.apache.ignite.internal.processors.cache.persistence.file.RandomAccessFileIOFactory) EVT_CLUSTER_SNAPSHOT_RESTORE_FAILED(org.apache.ignite.events.EventType.EVT_CLUSTER_SNAPSHOT_RESTORE_FAILED) SingleNodeMessage(org.apache.ignite.internal.util.distributed.SingleNodeMessage) EVT_CLUSTER_SNAPSHOT_RESTORE_STARTED(org.apache.ignite.events.EventType.EVT_CLUSTER_SNAPSHOT_RESTORE_STARTED) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) FilePageStoreManager(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager) UUID(java.util.UUID) IgniteCache(org.apache.ignite.IgniteCache) GridTestUtils(org.apache.ignite.testframework.GridTestUtils) CountDownLatch(java.util.concurrent.CountDownLatch) Nullable(org.jetbrains.annotations.Nullable) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) FilePageStoreManager.getPartitionFileName(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager.getPartitionFileName) CACHE_DIR_PREFIX(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager.CACHE_DIR_PREFIX) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) ClusterState(org.apache.ignite.cluster.ClusterState) U(org.apache.ignite.internal.util.typedef.internal.U) CacheExistsException(org.apache.ignite.cache.CacheExistsException) Function(java.util.function.Function) BinaryObjectBuilder(org.apache.ignite.binary.BinaryObjectBuilder) FileIOFactory(org.apache.ignite.internal.processors.cache.persistence.file.FileIOFactory) IntSupplier(java.util.function.IntSupplier) RESTORE_CACHE_GROUP_SNAPSHOT_PREPARE(org.apache.ignite.internal.util.distributed.DistributedProcess.DistributedProcessType.RESTORE_CACHE_GROUP_SNAPSHOT_PREPARE) RESTORE_CACHE_GROUP_SNAPSHOT_PRELOAD(org.apache.ignite.internal.util.distributed.DistributedProcess.DistributedProcessType.RESTORE_CACHE_GROUP_SNAPSHOT_PRELOAD) G(org.apache.ignite.internal.util.typedef.G) OpenOption(java.nio.file.OpenOption) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) IOException(java.io.IOException) Test(org.junit.Test) Ignite(org.apache.ignite.Ignite) GridDhtPartitionsSingleMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsSingleMessage) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) FILE_SUFFIX(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager.FILE_SUFFIX) BinaryType(org.apache.ignite.binary.BinaryType) RESTORE_CACHE_GROUP_SNAPSHOT_START(org.apache.ignite.internal.util.distributed.DistributedProcess.DistributedProcessType.RESTORE_CACHE_GROUP_SNAPSHOT_START) BinaryObjectException(org.apache.ignite.binary.BinaryObjectException) Paths(java.nio.file.Paths) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) Collections(java.util.Collections) IgniteSnapshot(org.apache.ignite.IgniteSnapshot) CacheMode(org.apache.ignite.cache.CacheMode) DynamicCacheChangeBatch(org.apache.ignite.internal.processors.cache.DynamicCacheChangeBatch) CountDownLatch(java.util.concurrent.CountDownLatch) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) BinaryObject(org.apache.ignite.binary.BinaryObject) File(java.io.File) SingleNodeMessage(org.apache.ignite.internal.util.distributed.SingleNodeMessage) RandomAccessFileIOFactory(org.apache.ignite.internal.processors.cache.persistence.file.RandomAccessFileIOFactory) Test(org.junit.Test)

Aggregations

File (java.io.File)1 IOException (java.io.IOException)1 OpenOption (java.nio.file.OpenOption)1 Path (java.nio.file.Path)1 Paths (java.nio.file.Paths)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 UUID (java.util.UUID)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 TimeUnit (java.util.concurrent.TimeUnit)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Consumer (java.util.function.Consumer)1 Function (java.util.function.Function)1 IntSupplier (java.util.function.IntSupplier)1 Ignite (org.apache.ignite.Ignite)1 IgniteCache (org.apache.ignite.IgniteCache)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 IgniteException (org.apache.ignite.IgniteException)1 IgniteSnapshot (org.apache.ignite.IgniteSnapshot)1 BinaryObject (org.apache.ignite.binary.BinaryObject)1