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