anton-vinogradov commented on a change in pull request #8767:
URL: https://github.com/apache/ignite/pull/8767#discussion_r593019812



##########
File path: 
modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/IgniteClusterSnapshotCheckTest.java
##########
@@ -317,4 +363,175 @@ public void testClusterSnapshotCheckCRCFail() throws 
Exception {
         Exception ex = res.exceptions().values().iterator().next();
         assertTrue(X.hasCause(ex, 
IgniteDataIntegrityViolationException.class));
     }
+
+    /** @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().offheap().lastUpdatedPartitionCounter(PART_ID);
+        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,
+                        null);
+
+                    assertTrue(success);
+
+                    long newPartCtr = 
cache.context().offheap().lastUpdatedPartitionCounter(PART_ID);
+
+                    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 finished, found 1 conflict partitions: 
[counterConflicts=0, hashConflicts=1]");
+    }
+
+    /** @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<>(Collections.singletonList(ccfg.getName())),
+            new HashSet<>(),
+            false,
+            CacheFilterEnum.USER,
+            true));
+
+        IdleVerifyResultV2 snpVerifyRes = ignite.compute().execute(new 
TestSnapshotPartitionsVerifyTask(),
+            Collections.singletonMap(ignite.cluster().localNode(),
+                
Collections.singletonList(snp(ignite).readSnapshotMetadata(SNAPSHOT_NAME, 
(String)ignite.configuration().getConsistentId()))));
+
+        Map<PartitionKeyV2, List<PartitionHashRecordV2>> idleVerifyHashes = 
jobResults.get(TestVisorBackupPartitionsTask.class);
+        Map<PartitionKeyV2, List<PartitionHashRecordV2>> snpCheckHashes = 
jobResults.get(TestVisorBackupPartitionsTask.class);
+
+        assertNotNull(idleVerifyHashes);
+        assertNotNull(snpCheckHashes);

Review comment:
       Let's assert they're not empty as well.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to