From e4b38b25e66b6a1594f512d853431b8f560981bc Mon Sep 17 00:00:00 2001 From: Anastasia Iakimova <94782753+Nastya828@users.noreply.github.com> Date: Sun, 22 Sep 2024 19:43:36 +0300 Subject: [PATCH] IGNITE-23222 Fixed incremental snapshot restore fail if consistent ID is not a string (#11545) --- .../SnapshotMetadataVerificationTask.java | 13 +++++-- .../snapshot/IncrementalSnapshotTest.java | 37 +++++++++++++++++++ 2 files changed, 47 insertions(+), 3 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/SnapshotMetadataVerificationTask.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/SnapshotMetadataVerificationTask.java index fc6d4e431c323..370e922c7a44a 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/SnapshotMetadataVerificationTask.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/SnapshotMetadataVerificationTask.java @@ -39,6 +39,7 @@ import org.apache.ignite.compute.ComputeJobResultPolicy; import org.apache.ignite.compute.ComputeTaskAdapter; import org.apache.ignite.internal.IgniteEx; +import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; import org.apache.ignite.internal.processors.cache.persistence.wal.FileDescriptor; import org.apache.ignite.internal.processors.cache.persistence.wal.FileWriteAheadLogManager; import org.apache.ignite.internal.processors.cache.persistence.wal.reader.IgniteWalIteratorFactory; @@ -49,7 +50,9 @@ import org.apache.ignite.resources.LoggerResource; import org.jetbrains.annotations.NotNull; +import static java.lang.String.valueOf; import static org.apache.ignite.internal.processors.cache.persistence.snapshot.IgniteSnapshotManager.incrementalSnapshotWalsDir; +import static org.apache.ignite.internal.processors.cache.persistence.snapshot.IgniteSnapshotManager.snapshotMetaFileName; /** Snapshot task to verify snapshot metadata on the baseline nodes for given snapshot name. */ @GridInternal @@ -112,7 +115,7 @@ public MetadataVerificationJob(SnapshotMetadataVerificationTaskArg arg) { if (arg.incrementIndex() > 0) { List metas = snpMeta.stream() - .filter(m -> m.consistentId().equals(ignite.localNode().consistentId())) + .filter(m -> m.consistentId().equals(valueOf(ignite.localNode().consistentId()))) .collect(Collectors.toList()); if (metas.size() != 1) { @@ -174,7 +177,9 @@ private void checkMeta(SnapshotMetadata meta) { /** Checks that all incremental snapshots are present, contain correct metafile and WAL segments. */ public void checkIncrementalSnapshots(SnapshotMetadata fullMeta, SnapshotMetadataVerificationTaskArg arg) { try { - IgniteSnapshotManager snpMgr = ignite.context().cache().context().snapshotMgr(); + GridCacheSharedContext ctx = ignite.context().cache().context(); + + IgniteSnapshotManager snpMgr = ctx.snapshotMgr(); // Incremental snapshot must contain ClusterSnapshotRecord. long startSeg = fullMeta.snapshotRecordPointer().index(); @@ -187,7 +192,9 @@ public void checkIncrementalSnapshots(SnapshotMetadata fullMeta, SnapshotMetadat "[snpName=" + arg.snapshotName() + ", snpPath=" + arg.snapshotPath() + ", incrementIndex=" + inc + ']'); } - String metaFileName = IgniteSnapshotManager.snapshotMetaFileName(ignite.localNode().consistentId().toString()); + String folderName = ctx.kernalContext().pdsFolderResolver().resolveFolders().folderName(); + + String metaFileName = snapshotMetaFileName(folderName); File metafile = incSnpDir.toPath().resolve(metaFileName).toFile(); diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/IncrementalSnapshotTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/IncrementalSnapshotTest.java index 57a8a2bac79b2..415fc90589020 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/IncrementalSnapshotTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/IncrementalSnapshotTest.java @@ -25,6 +25,7 @@ import org.apache.ignite.IgniteCache; import org.apache.ignite.IgniteException; import org.apache.ignite.cache.QueryEntity; +import org.apache.ignite.cluster.ClusterState; import org.apache.ignite.configuration.CacheConfiguration; import org.apache.ignite.configuration.DataStorageConfiguration; import org.apache.ignite.configuration.IgniteConfiguration; @@ -440,6 +441,42 @@ public void testStagesFail() throws Exception { assertCacheKeys(srv.cache(DEFAULT_CACHE_NAME), CACHE_KEYS_RANGE); } + /** */ + @Test + public void testDefaultConsistentId() throws Exception { + assumeFalse("https://issues.apache.org/jira/browse/IGNITE-17819", encryption); + + IgniteEx ignite = startGrid(getConfiguration().setConsistentId(null)); + + ignite.cluster().state(ClusterState.ACTIVE); + + IgniteCache cache = ignite.getOrCreateCache(new CacheConfiguration<>(DEFAULT_CACHE_NAME)); + + cache.put(1, 1); + + ignite.snapshot().createSnapshot(SNAPSHOT_NAME).get(); + + cache.put(2, 2); + + ignite.snapshot().createIncrementalSnapshot(SNAPSHOT_NAME).get(); + + ignite.destroyCache(DEFAULT_CACHE_NAME); + + awaitPartitionMapExchange(); + + ignite.snapshot().restoreSnapshot(SNAPSHOT_NAME, F.asList(DEFAULT_CACHE_NAME)).get(getTestTimeout()); + + assertEquals(1, cache.size()); + + ignite.destroyCache(DEFAULT_CACHE_NAME); + + awaitPartitionMapExchange(); + + ignite.snapshot().restoreSnapshot(SNAPSHOT_NAME, F.asList(DEFAULT_CACHE_NAME), 1).get(getTestTimeout()); + + assertEquals(2, cache.size()); + } + /** */ private void checkFailWhenCacheDestroyed(String cache2rvm, String errMsg) throws Exception { IgniteEx srv = startGridsWithCache(