use of org.apache.ignite.internal.processors.cache.verify.IdleVerifyResultV2 in project ignite by apache.
the class IgniteClusterSnapshotCheckWithIndexesTest method testClusterSnapshotCheckWithIndexes.
/**
* @throws Exception If fails.
*/
@Test
public void testClusterSnapshotCheckWithIndexes() throws Exception {
IgniteEx ignite = startGridsWithCache(3, CACHE_KEYS_RANGE, key -> new Account(key, key), txFilteredCache("indexed"));
ignite.snapshot().createSnapshot(SNAPSHOT_NAME).get(TIMEOUT);
IdleVerifyResultV2 res = ignite.context().cache().context().snapshotMgr().checkSnapshot(SNAPSHOT_NAME).get();
StringBuilder b = new StringBuilder();
res.print(b::append, true);
assertTrue("Exceptions: " + b, F.isEmpty(res.exceptions()));
assertContains(log, b.toString(), "The check procedure has finished, no conflicts have been found.");
}
use of org.apache.ignite.internal.processors.cache.verify.IdleVerifyResultV2 in project ignite by apache.
the class IgniteClusterSnapshotCheckWithIndexesTest method testClusterSnapshotCheckEmptyCache.
/**
* @throws Exception If fails.
*/
@Test
public void testClusterSnapshotCheckEmptyCache() throws Exception {
IgniteEx ignite = startGridsWithCache(3, 0, key -> new Account(key, key), txFilteredCache("indexed"));
ignite.snapshot().createSnapshot(SNAPSHOT_NAME).get(TIMEOUT);
IdleVerifyResultV2 res = ignite.context().cache().context().snapshotMgr().checkSnapshot(SNAPSHOT_NAME).get();
StringBuilder b = new StringBuilder();
res.print(b::append, true);
assertTrue("Exceptions: " + b, F.isEmpty(res.exceptions()));
assertTrue(F.isEmpty(res.exceptions()));
}
use of org.apache.ignite.internal.processors.cache.verify.IdleVerifyResultV2 in project ignite by apache.
the class TxRollbackOnTimeoutOnePhaseCommitTest method doTestRollbackOnTimeoutPartitionDesync.
/**
*/
private void doTestRollbackOnTimeoutPartitionDesync(TransactionConcurrency concurrency) throws Exception {
IgniteEx client = grid("client");
assertNotNull(client.cache(DEFAULT_CACHE_NAME));
int key = 0;
Ignite primary = primaryNode(key, DEFAULT_CACHE_NAME);
Ignite backup = backupNode(key, DEFAULT_CACHE_NAME);
TestRecordingCommunicationSpi backupSpi = TestRecordingCommunicationSpi.spi(backup);
backupSpi.blockMessages(GridDhtTxPrepareResponse.class, primary.name());
IgniteInternalFuture fut = runAsync(() -> {
try {
backupSpi.waitForBlocked(1, 5000);
} catch (InterruptedException e) {
fail();
}
doSleep(500);
backupSpi.stopBlock();
});
try (Transaction tx = client.transactions().txStart(concurrency, REPEATABLE_READ, 500, 1)) {
client.cache(DEFAULT_CACHE_NAME).put(key, key);
tx.commit();
} catch (Exception e) {
assertTrue(e.getClass().getName(), X.hasCause(e, TransactionTimeoutException.class));
}
fut.get();
IdleVerifyResultV2 res = idleVerify(client, DEFAULT_CACHE_NAME);
assertPartitionsSame(res);
checkFutures();
}
use of org.apache.ignite.internal.processors.cache.verify.IdleVerifyResultV2 in project ignite by apache.
the class IgniteSnapshotManager method checkSnapshot.
/**
* The check snapshot procedure performs compute operation over the whole cluster to verify the snapshot
* entirety and partitions consistency. The result future will be completed with an exception if this
* exception is not related to the check procedure, and will be completed normally with the {@code IdleVerifyResult}.
*
* @param name Snapshot name.
* @param grps Collection of cache group names to check.
* @param includeCustomHandlers {@code True} to invoke all user-defined {@link SnapshotHandlerType#RESTORE}
* handlers, otherwise only system consistency check will be performed.
* @return Future with the result of execution snapshot partitions verify task, which besides calculating partition
* hashes of {@link IdleVerifyResultV2} also contains the snapshot metadata distribution across the cluster.
*/
public IgniteInternalFuture<SnapshotPartitionsVerifyTaskResult> checkSnapshot(String name, @Nullable Collection<String> grps, boolean includeCustomHandlers) {
A.notNullOrEmpty(name, "Snapshot name cannot be null or empty.");
A.ensure(U.alphanumericUnderscore(name), "Snapshot name must satisfy the following name pattern: a-zA-Z0-9_");
A.ensure(grps == null || grps.stream().filter(Objects::isNull).collect(Collectors.toSet()).isEmpty(), "Collection of cache groups names cannot contain null elements.");
GridFutureAdapter<SnapshotPartitionsVerifyTaskResult> res = new GridFutureAdapter<>();
GridKernalContext kctx0 = cctx.kernalContext();
Collection<ClusterNode> bltNodes = F.view(cctx.discovery().serverNodes(AffinityTopologyVersion.NONE), (node) -> CU.baselineNode(node, kctx0.state().clusterState()));
kctx0.task().setThreadContext(TC_SKIP_AUTH, true);
kctx0.task().setThreadContext(TC_SUBGRID, bltNodes);
kctx0.task().execute(SnapshotMetadataCollectorTask.class, name).listen(f0 -> {
if (f0.error() == null) {
Map<ClusterNode, List<SnapshotMetadata>> metas = f0.result();
Map<Integer, String> grpIds = grps == null ? Collections.emptyMap() : grps.stream().collect(Collectors.toMap(CU::cacheId, v -> v));
for (List<SnapshotMetadata> nodeMetas : metas.values()) {
for (SnapshotMetadata meta : nodeMetas) grpIds.keySet().removeAll(meta.partitions().keySet());
}
if (!grpIds.isEmpty()) {
res.onDone(new SnapshotPartitionsVerifyTaskResult(metas, new IdleVerifyResultV2(Collections.singletonMap(cctx.localNode(), new IllegalArgumentException("Cache group(s) was not " + "found in the snapshot [groups=" + grpIds.values() + ", snapshot=" + name + ']')))));
return;
}
kctx0.task().setThreadContext(TC_SKIP_AUTH, true);
kctx0.task().setThreadContext(TC_SUBGRID, new ArrayList<>(metas.keySet()));
Class<? extends AbstractSnapshotVerificationTask> cls = includeCustomHandlers ? SnapshotHandlerRestoreTask.class : SnapshotPartitionsVerifyTask.class;
kctx0.task().execute(cls, new SnapshotPartitionsVerifyTaskArg(grps, metas)).listen(f1 -> {
if (f1.error() == null)
res.onDone(f1.result());
else if (f1.error() instanceof IgniteSnapshotVerifyException)
res.onDone(new SnapshotPartitionsVerifyTaskResult(metas, new IdleVerifyResultV2(((IgniteSnapshotVerifyException) f1.error()).exceptions())));
else
res.onDone(f1.error());
});
} else {
if (f0.error() instanceof IgniteSnapshotVerifyException)
res.onDone(new SnapshotPartitionsVerifyTaskResult(null, new IdleVerifyResultV2(((IgniteSnapshotVerifyException) f0.error()).exceptions())));
else
res.onDone(f0.error());
}
});
return res;
}
use of org.apache.ignite.internal.processors.cache.verify.IdleVerifyResultV2 in project ignite by apache.
the class IgniteClusterSnapshotCheckTest method testClusterSnapshotCheckHashesSameAsIdleVerifyHashes.
/**
* @throws Exception If fails.
*/
@Test
public void testClusterSnapshotCheckHashesSameAsIdleVerifyHashes() throws Exception {
Random rnd = new Random();
CacheConfiguration<Integer, Value> ccfg = txCacheConfig(new CacheConfiguration<>(DEFAULT_CACHE_NAME));
IgniteEx ignite = startGridsWithCache(1, CACHE_KEYS_RANGE, k -> new Value(new byte[rnd.nextInt(32768)]), ccfg);
ignite.snapshot().createSnapshot(SNAPSHOT_NAME).get();
IdleVerifyResultV2 idleVerifyRes = ignite.compute().execute(new TestVisorBackupPartitionsTask(), new VisorIdleVerifyTaskArg(new HashSet<>(singletonList(ccfg.getName())), new HashSet<>(), false, CacheFilterEnum.USER, true));
IdleVerifyResultV2 snpVerifyRes = ignite.compute().execute(new TestSnapshotPartitionsVerifyTask(), new SnapshotPartitionsVerifyTaskArg(new HashSet<>(), Collections.singletonMap(ignite.cluster().localNode(), Collections.singletonList(snp(ignite).readSnapshotMetadata(SNAPSHOT_NAME, (String) ignite.configuration().getConsistentId()))))).idleVerifyResult();
Map<PartitionKeyV2, List<PartitionHashRecordV2>> idleVerifyHashes = jobResults.get(TestVisorBackupPartitionsTask.class);
Map<PartitionKeyV2, List<PartitionHashRecordV2>> snpCheckHashes = jobResults.get(TestVisorBackupPartitionsTask.class);
assertFalse(F.isEmpty(idleVerifyHashes));
assertFalse(F.isEmpty(snpCheckHashes));
assertEquals(idleVerifyHashes, snpCheckHashes);
assertEquals(idleVerifyRes, snpVerifyRes);
}
Aggregations