use of org.apache.ignite.internal.processors.cache.verify.IdleVerifyResultV2 in project ignite by apache.
the class IgniteClusterSnapshotCheckTest method testClusterSnapshotCheckPartitionCounters.
/**
* @throws Exception If fails.
*/
@Test
public void testClusterSnapshotCheckPartitionCounters() throws Exception {
IgniteEx ignite = startGridsWithCache(3, dfltCacheCfg.setAffinity(new RendezvousAffinityFunction(false, 1)), CACHE_KEYS_RANGE);
ignite.snapshot().createSnapshot(SNAPSHOT_NAME).get();
Path part0 = U.searchFileRecursively(snp(ignite).snapshotLocalDir(SNAPSHOT_NAME).toPath(), getPartitionFileName(PART_ID));
assertNotNull(part0);
assertTrue(part0.toString(), part0.toFile().exists());
try (FilePageStore pageStore = (FilePageStore) ((FilePageStoreManager) ignite.context().cache().context().pageStore()).getPageStoreFactory(CU.cacheId(dfltCacheCfg.getName()), false).createPageStore(getTypeByPartId(PART_ID), () -> part0, val -> {
})) {
ByteBuffer buff = ByteBuffer.allocateDirect(ignite.configuration().getDataStorageConfiguration().getPageSize()).order(ByteOrder.nativeOrder());
buff.clear();
pageStore.read(0, buff, false);
PagePartitionMetaIO io = PageIO.getPageIO(buff);
long pageAddr = GridUnsafe.bufferAddress(buff);
io.setUpdateCounter(pageAddr, CACHE_KEYS_RANGE * 2);
pageStore.beginRecover();
buff.flip();
pageStore.write(PageIO.getPageId(buff), buff, 0, true);
pageStore.finishRecover();
}
IdleVerifyResultV2 res = snp(ignite).checkSnapshot(SNAPSHOT_NAME).get();
StringBuilder b = new StringBuilder();
res.print(b::append, true);
assertTrue(F.isEmpty(res.exceptions()));
assertContains(log, b.toString(), "The check procedure has failed, conflict partitions has been found: [counterConflicts=1, hashConflicts=0]");
}
use of org.apache.ignite.internal.processors.cache.verify.IdleVerifyResultV2 in project ignite by apache.
the class IgniteClusterSnapshotCheckTest method testClusterSnapshotCheckFailsOnPartitionDataDiffers.
/**
* @throws Exception If fails.
*/
@Test
public void testClusterSnapshotCheckFailsOnPartitionDataDiffers() throws Exception {
CacheConfiguration<Integer, Value> ccfg = txCacheConfig(new CacheConfiguration<Integer, Value>(DEFAULT_CACHE_NAME)).setAffinity(new RendezvousAffinityFunction(false, 1));
IgniteEx ignite = startGridsWithoutCache(2);
ignite.getOrCreateCache(ccfg).put(1, new Value(new byte[2000]));
forceCheckpoint(ignite);
GridCacheSharedContext<?, ?> cctx = ignite.context().cache().context();
GridCacheDatabaseSharedManager db = (GridCacheDatabaseSharedManager) cctx.database();
BinaryContext binCtx = ((CacheObjectBinaryProcessorImpl) ignite.context().cacheObjects()).binaryContext();
GridCacheAdapter<?, ?> cache = ignite.context().cache().internalCache(dfltCacheCfg.getName());
long partCtr = cache.context().topology().localPartition(PART_ID, NONE, false).dataStore().updateCounter();
AtomicBoolean done = new AtomicBoolean();
db.addCheckpointListener(new CheckpointListener() {
@Override
public void onMarkCheckpointBegin(Context ctx) throws IgniteCheckedException {
// Change the cache value only at on of the cluster node to get hash conflict when the check command ends.
if (!done.compareAndSet(false, true))
return;
GridIterator<CacheDataRow> it = cache.context().offheap().partitionIterator(PART_ID);
assertTrue(it.hasNext());
CacheDataRow row0 = it.nextX();
AffinityTopologyVersion topVer = cctx.exchange().readyAffinityVersion();
GridCacheEntryEx cached = cache.entryEx(row0.key(), topVer);
byte[] bytes = new byte[2000];
new Random().nextBytes(bytes);
try {
BinaryObjectImpl newVal = new BinaryObjectImpl(binCtx, binCtx.marshaller().marshal(new Value(bytes)), 0);
boolean success = cached.initialValue(newVal, new GridCacheVersion(row0.version().topologyVersion(), row0.version().nodeOrder(), row0.version().order() + 1), null, null, TxState.NA, TxState.NA, TTL_ETERNAL, row0.expireTime(), true, topVer, DR_NONE, false, false, null);
assertTrue(success);
long newPartCtr = cache.context().topology().localPartition(PART_ID, NONE, false).dataStore().updateCounter();
assertEquals(newPartCtr, partCtr);
} catch (Exception e) {
throw new IgniteCheckedException(e);
}
}
@Override
public void onCheckpointBegin(Context ctx) throws IgniteCheckedException {
}
@Override
public void beforeCheckpointBegin(Context ctx) throws IgniteCheckedException {
}
});
db.waitForCheckpoint("test-checkpoint");
ignite.snapshot().createSnapshot(SNAPSHOT_NAME).get();
Path part0 = U.searchFileRecursively(snp(ignite).snapshotLocalDir(SNAPSHOT_NAME).toPath(), getPartitionFileName(PART_ID));
assertNotNull(part0);
assertTrue(part0.toString(), part0.toFile().exists());
IdleVerifyResultV2 res = snp(ignite).checkSnapshot(SNAPSHOT_NAME).get();
StringBuilder b = new StringBuilder();
res.print(b::append, true);
assertTrue(F.isEmpty(res.exceptions()));
assertContains(log, b.toString(), "The check procedure has failed, conflict partitions has been found: [counterConflicts=0, hashConflicts=1]");
}
use of org.apache.ignite.internal.processors.cache.verify.IdleVerifyResultV2 in project ignite by apache.
the class IgniteSnapshotRestoreFromRemoteTest method testRestoreFromAnEmptyNode.
/**
* @throws Exception If failed.
*/
@Test
public void testRestoreFromAnEmptyNode() throws Exception {
startDedicatedGrids(SECOND_CLUSTER_PREFIX, 2);
copyAndShuffle(snpParts, G.allGrids());
// Start a new node without snapshot working directory.
IgniteEx emptyNode = startDedicatedGrid(SECOND_CLUSTER_PREFIX, 2);
emptyNode.cluster().state(ClusterState.ACTIVE);
emptyNode.cache(DEFAULT_CACHE_NAME).destroy();
awaitPartitionMapExchange();
// Ensure that the snapshot check command succeeds.
IdleVerifyResultV2 res = emptyNode.context().cache().context().snapshotMgr().checkSnapshot(SNAPSHOT_NAME).get(TIMEOUT);
StringBuilder buf = new StringBuilder();
res.print(buf::append, true);
assertTrue(F.isEmpty(res.exceptions()));
assertPartitionsSame(res);
assertContains(log, buf.toString(), "The check procedure has finished, no conflicts have been found");
// Restore all cache groups.
emptyNode.snapshot().restoreSnapshot(SNAPSHOT_NAME, null).get(TIMEOUT);
awaitPartitionMapExchange(true, true, null, true);
for (Ignite grid : G.allGrids()) {
assertCacheKeys(grid.cache(DEFAULT_CACHE_NAME), CACHE_KEYS_RANGE);
assertCacheKeys(grid.cache(CACHE1), CACHE_KEYS_RANGE);
assertCacheKeys(grid.cache(CACHE2), CACHE_KEYS_RANGE);
}
}
use of org.apache.ignite.internal.processors.cache.verify.IdleVerifyResultV2 in project ignite by apache.
the class TxWithSmallTimeoutAndContentionOneKeyTest method test.
/**
* https://issues.apache.org/jira/browse/IGNITE-9042
*
* @throws Exception If failed.
*/
@Test
public void test() throws Exception {
Assume.assumeFalse("https://issues.apache.org/jira/browse/IGNITE-10455", MvccFeatureChecker.forcedMvcc());
startGrids(4);
IgniteEx igClient = startClientGrid(getConfiguration("client").setConsistentId("Client"));
igClient.cluster().active(true);
AtomicBoolean stop = new AtomicBoolean(false);
IgniteCache<Integer, Long> cache = igClient.cache(DEFAULT_CACHE_NAME);
int threads = 1;
int keyId = 0;
CountDownLatch finishLatch = new CountDownLatch(threads);
AtomicLong cnt = new AtomicLong();
IgniteInternalFuture<Long> f = runMultiThreadedAsync(() -> {
IgniteTransactions txMgr = igClient.transactions();
while (!stop.get()) {
long newVal = cnt.getAndIncrement();
TransactionConcurrency concurrency = transactionConcurrency();
TransactionIsolation transactionIsolation = transactionIsolation();
try (Transaction tx = txMgr.txStart(concurrency, transactionIsolation, randomTimeOut(), 1)) {
cache.put(keyId, newVal);
tx.commit();
} catch (Throwable e) {
// Ignore.
}
}
finishLatch.countDown();
}, threads, "tx-runner");
runAsync(() -> {
try {
Thread.sleep(TIME_TO_EXECUTE);
} catch (InterruptedException ignore) {
// Ignore.
}
stop.set(true);
});
finishLatch.await();
f.get();
IdleVerifyResultV2 idleVerifyResult = idleVerify(igClient, DEFAULT_CACHE_NAME);
log.info("Current counter value:" + cnt.get());
Long val = cache.get(keyId);
log.info("Last commited value:" + val);
if (idleVerifyResult.hasConflicts()) {
SB sb = new SB();
sb.a("\n");
buildConflicts("Hash conflicts:\n", sb, idleVerifyResult.hashConflicts());
buildConflicts("Counters conflicts:\n", sb, idleVerifyResult.counterConflicts());
System.out.println(sb);
fail();
}
}
use of org.apache.ignite.internal.processors.cache.verify.IdleVerifyResultV2 in project ignite by apache.
the class GridCacheFastNodeLeftForTransactionTest method check.
/**
* Checking the contents of the cache after rollback transactions,
* with restarting the stopped node with using "idle_verify".
*
* @param cacheValues Expected cache contents.
* @param cacheName Cache name.
* @param logLsnr LogListener.
* @param stoppedNodeId ID of the stopped node.
* @throws Exception If failed.
*/
private void check(Map<Integer, Integer> cacheValues, String cacheName, LogListener logLsnr, int stoppedNodeId) throws Exception {
assert nonNull(cacheValues);
assert nonNull(cacheName);
assert nonNull(logLsnr);
checkCacheData(cacheValues, cacheName);
assertTrue(logLsnr.check());
IgniteEx stoppedNode = startGrid(stoppedNodeId);
awaitPartitionMapExchange();
// Wait for vacuum.
doSleep(2000);
checkCacheData(cacheValues, cacheName);
IdleVerifyResultV2 idleVerifyResV2 = idleVerify(stoppedNode, null);
SB sb = new SB();
idleVerifyResV2.print(sb::a, true);
assertContains(listeningLog, sb.toString(), "no conflicts have been found");
}
Aggregations