Search in sources :

Example 6 with SingleNodeMessage

use of org.apache.ignite.internal.util.distributed.SingleNodeMessage in project ignite by apache.

the class MasterKeyChangeTest method testRejectMasterKeyChangeDuringRotation.

/**
 * @throws Exception If failed.
 */
@Test
public void testRejectMasterKeyChangeDuringRotation() throws Exception {
    T2<IgniteEx, IgniteEx> grids = startTestGrids(true);
    createEncryptedCache(grids.get1(), grids.get2(), cacheName(), null);
    assertTrue(checkMasterKeyName(DEFAULT_MASTER_KEY_NAME));
    TestRecordingCommunicationSpi commSpi = TestRecordingCommunicationSpi.spi(grids.get2());
    commSpi.blockMessages((node, msg) -> msg instanceof SingleNodeMessage);
    IgniteFuture<Void> fut = grids.get1().encryption().changeMasterKey(MASTER_KEY_NAME_2);
    commSpi.waitForBlocked();
    // Stops block subsequent changes.
    commSpi.stopBlock(false, null, true, false);
    assertThrowsWithCause(() -> grids.get2().encryption().changeMasterKey(MASTER_KEY_NAME_3).get(), IgniteException.class);
    // Unblocks first change.
    commSpi.stopBlock();
    fut.get();
    assertTrue(checkMasterKeyName(MASTER_KEY_NAME_2));
    checkEncryptedCaches(grids.get1(), grids.get2());
}
Also used : TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) IgniteEx(org.apache.ignite.internal.IgniteEx) SingleNodeMessage(org.apache.ignite.internal.util.distributed.SingleNodeMessage) Test(org.junit.Test)

Example 7 with SingleNodeMessage

use of org.apache.ignite.internal.util.distributed.SingleNodeMessage in project ignite by apache.

the class IgniteClusterSnapshotSelfTest method testClusterSnapshotCleanedOnLeft.

/**
 * @throws Exception If fails.
 */
@Test
public void testClusterSnapshotCleanedOnLeft() throws Exception {
    CountDownLatch block = new CountDownLatch(1);
    CountDownLatch partProcessed = new CountDownLatch(1);
    IgniteEx ignite = startGridsWithCache(2, dfltCacheCfg, CACHE_KEYS_RANGE);
    File locSnpDir = snp(ignite).snapshotLocalDir(SNAPSHOT_NAME);
    String dirNameIgnite0 = folderName(ignite);
    String dirNameIgnite1 = folderName(grid(1));
    snp(grid(1)).localSnapshotSenderFactory(blockingLocalSnapshotSender(grid(1), partProcessed, block));
    TestRecordingCommunicationSpi commSpi1 = TestRecordingCommunicationSpi.spi(grid(1));
    commSpi1.blockMessages((node, msg) -> msg instanceof SingleNodeMessage);
    IgniteFuture<?> fut = ignite.snapshot().createSnapshot(SNAPSHOT_NAME);
    U.await(partProcessed, TIMEOUT, TimeUnit.MILLISECONDS);
    stopGrid(1);
    block.countDown();
    assertThrowsAnyCause(log, fut::get, ClusterTopologyException.class, "Snapshot operation interrupted, because baseline node left the cluster");
    waitForEvents(EVT_CLUSTER_SNAPSHOT_STARTED, EVT_CLUSTER_SNAPSHOT_FAILED);
    assertTrue("Snapshot directory must be empty for node 0 due to snapshot future fail: " + dirNameIgnite0, !searchDirectoryRecursively(locSnpDir.toPath(), dirNameIgnite0).isPresent());
    startGrid(1);
    awaitPartitionMapExchange();
    // Snapshot directory must be cleaned.
    assertTrue("Snapshot directory must be empty for node 1 due to snapshot future fail: " + dirNameIgnite1, !searchDirectoryRecursively(locSnpDir.toPath(), dirNameIgnite1).isPresent());
    List<String> allSnapshots = snp(ignite).localSnapshotNames();
    assertTrue("Snapshot directory must be empty due to snapshot fail: " + allSnapshots, allSnapshots.isEmpty());
}
Also used : TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) IgniteEx(org.apache.ignite.internal.IgniteEx) CountDownLatch(java.util.concurrent.CountDownLatch) File(java.io.File) SingleNodeMessage(org.apache.ignite.internal.util.distributed.SingleNodeMessage) Test(org.junit.Test)

Example 8 with SingleNodeMessage

use of org.apache.ignite.internal.util.distributed.SingleNodeMessage 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)

Example 9 with SingleNodeMessage

use of org.apache.ignite.internal.util.distributed.SingleNodeMessage in project ignite by apache.

the class IgniteSnapshotMXBeanTest method testCancelRestoreSnapshot.

/**
 * @throws Exception If fails.
 */
@Test
public void testCancelRestoreSnapshot() throws Exception {
    // TODO IGNITE-14999 Support dynamic restoration of encrypted snapshots.
    if (encryption)
        return;
    IgniteEx ignite = startGridsWithSnapshot(2, CACHE_KEYS_RANGE, false);
    SnapshotMXBean mxBean = getMxBean(ignite.name(), METRIC_GROUP, SnapshotMXBeanImpl.class, SnapshotMXBean.class);
    DynamicMBean mReg0 = metricRegistry(grid(0).name(), null, SNAPSHOT_RESTORE_METRICS);
    DynamicMBean mReg1 = metricRegistry(grid(1).name(), null, SNAPSHOT_RESTORE_METRICS);
    assertEquals("", getMetric("error", mReg0));
    assertEquals("", getMetric("error", mReg1));
    assertEquals(0, (long) getMetric("endTime", mReg0));
    assertEquals(0, (long) getMetric("endTime", mReg1));
    TestRecordingCommunicationSpi spi = TestRecordingCommunicationSpi.spi(grid(1));
    spi.blockMessages((node, msg) -> msg instanceof SingleNodeMessage && ((SingleNodeMessage<?>) msg).type() == RESTORE_CACHE_GROUP_SNAPSHOT_PREPARE.ordinal());
    IgniteFuture<Void> fut = ignite.snapshot().restoreSnapshot(SNAPSHOT_NAME, null);
    spi.waitForBlocked();
    IgniteInternalFuture<Boolean> interruptFut = GridTestUtils.runAsync(() -> {
        try {
            return GridTestUtils.waitForCondition(() -> !"".equals(getMetric("error", mReg0)) && !"".equals(getMetric("error", mReg1)), TIMEOUT);
        } finally {
            spi.stopBlock();
        }
    });
    mxBean.cancelSnapshotRestore(SNAPSHOT_NAME);
    assertTrue(interruptFut.get());
    String expErrMsg = "Operation has been canceled by the user.";
    assertThrowsAnyCause(log, () -> fut.get(TIMEOUT), IgniteCheckedException.class, expErrMsg);
    assertTrue((long) getMetric("endTime", mReg0) > 0);
    assertTrue((long) getMetric("endTime", mReg1) > 0);
    assertTrue(((String) getMetric("error", mReg0)).contains(expErrMsg));
    assertTrue(((String) getMetric("error", mReg1)).contains(expErrMsg));
    assertNull(ignite.cache(DEFAULT_CACHE_NAME));
}
Also used : DynamicMBean(javax.management.DynamicMBean) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) IgniteEx(org.apache.ignite.internal.IgniteEx) SingleNodeMessage(org.apache.ignite.internal.util.distributed.SingleNodeMessage) SnapshotMXBean(org.apache.ignite.mxbean.SnapshotMXBean) Test(org.junit.Test)

Example 10 with SingleNodeMessage

use of org.apache.ignite.internal.util.distributed.SingleNodeMessage in project ignite by apache.

the class CacheGroupKeyChangeTest method testCacheStartSameGroupDuringRotation.

/**
 * @throws Exception If failed.
 */
@Test
public void testCacheStartSameGroupDuringRotation() throws Exception {
    T2<IgniteEx, IgniteEx> grids = startTestGrids(true);
    String grpName = "shared";
    createEncryptedCache(grids.get1(), grids.get2(), cacheName(), grpName);
    TestRecordingCommunicationSpi commSpi = TestRecordingCommunicationSpi.spi(grids.get2());
    commSpi.blockMessages((node, msg) -> msg instanceof SingleNodeMessage);
    IgniteFuture<Void> fut = grids.get1().encryption().changeCacheGroupKey(Collections.singleton(grpName));
    commSpi.waitForBlocked();
    IgniteCache<Integer, Integer> cache = grids.get1().createCache(cacheConfiguration("cache1", grpName));
    commSpi.stopBlock();
    for (int i = 0; i < 100; i++) cache.put(i, i);
    fut.get();
    checkGroupKey(CU.cacheId(grpName), INITIAL_KEY_ID + 1, MAX_AWAIT_MILLIS);
}
Also used : TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) IgniteEx(org.apache.ignite.internal.IgniteEx) SingleNodeMessage(org.apache.ignite.internal.util.distributed.SingleNodeMessage) Test(org.junit.Test)

Aggregations

IgniteEx (org.apache.ignite.internal.IgniteEx)13 TestRecordingCommunicationSpi (org.apache.ignite.internal.TestRecordingCommunicationSpi)13 SingleNodeMessage (org.apache.ignite.internal.util.distributed.SingleNodeMessage)13 Test (org.junit.Test)11 File (java.io.File)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)2 DistributedProcessType (org.apache.ignite.internal.util.distributed.DistributedProcess.DistributedProcessType)2 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 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