This is an automated email from the ASF dual-hosted git repository. nizhikov pushed a commit to branch cache_dumps in repository https://gitbox.apache.org/repos/asf/ignite.git
The following commit(s) were added to refs/heads/cache_dumps by this push: new aa1e0a57abb Minor: fix dump check. Read only local node data during check. aa1e0a57abb is described below commit aa1e0a57abbad92d76efcfdb2c45d644d27f3e0f Author: nizhikov <nizhi...@apache.org> AuthorDate: Sun Oct 8 13:29:01 2023 +0300 Minor: fix dump check. Read only local node data during check. --- .../snapshot/SnapshotPartitionsVerifyHandler.java | 29 ++++++++++++-------- .../snapshot/dump/CreateDumpFutureTask.java | 2 +- .../cache/persistence/snapshot/dump/Dump.java | 31 ++++++++++++++++++---- 3 files changed, 45 insertions(+), 17 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/SnapshotPartitionsVerifyHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/SnapshotPartitionsVerifyHandler.java index c36917ee023..3d14d937fc9 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/SnapshotPartitionsVerifyHandler.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/SnapshotPartitionsVerifyHandler.java @@ -358,19 +358,26 @@ public class SnapshotPartitionsVerifyHandler implements SnapshotHandler<Map<Part SnapshotHandlerContext opCtx, Set<File> partFiles ) { - try (Dump dump = new Dump(opCtx.snapshotDirectory(), true, true, log)) { - Collection<PartitionHashRecordV2> partitionHashRecordV2s = U.doInParallel( - cctx.snapshotMgr().snapshotExecutorService(), - partFiles, - part -> calculateDumpedPartitionHash(dump, cacheGroupName(part.getParentFile()), partId(part.getName())) - ); + try { + String consistentId = cctx.kernalContext().pdsFolderResolver().resolveFolders().consistentId().toString(); - return partitionHashRecordV2s.stream().collect(Collectors.toMap(PartitionHashRecordV2::partitionKey, r -> r)); - } - catch (Throwable t) { - log.error("Error executing handler: ", t); + try (Dump dump = new Dump(opCtx.snapshotDirectory(), consistentId, true, true, log)) { + Collection<PartitionHashRecordV2> partitionHashRecordV2s = U.doInParallel( + cctx.snapshotMgr().snapshotExecutorService(), + partFiles, + part -> calculateDumpedPartitionHash(dump, cacheGroupName(part.getParentFile()), partId(part.getName())) + ); + + return partitionHashRecordV2s.stream().collect(Collectors.toMap(PartitionHashRecordV2::partitionKey, r -> r)); + } + catch (Throwable t) { + log.error("Error executing handler: ", t); - throw new IgniteException(t); + throw new IgniteException(t); + } + } + catch (IgniteCheckedException e) { + throw new IgniteException(e); } } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/dump/CreateDumpFutureTask.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/dump/CreateDumpFutureTask.java index c01f81f877a..de1009059b0 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/dump/CreateDumpFutureTask.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/dump/CreateDumpFutureTask.java @@ -306,7 +306,7 @@ public class CreateDumpFutureTask extends AbstractCreateSnapshotFutureTask imple } /** {@inheritDoc} */ - @Override protected CompletableFuture<Void> closeAsync() { + @Override protected synchronized CompletableFuture<Void> closeAsync() { if (closeFut == null) { dumpCtxs.values().forEach(PartitionDumpContext::close); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/dump/Dump.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/dump/Dump.java index 38baf38356b..2496cd210c0 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/dump/Dump.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/dump/Dump.java @@ -59,6 +59,7 @@ import org.apache.ignite.internal.util.typedef.internal.CU; import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.marshaller.MarshallerUtils; import org.apache.ignite.marshaller.jdk.JdkMarshaller; +import org.jetbrains.annotations.Nullable; import static org.apache.ignite.configuration.DataStorageConfiguration.DFLT_BINARY_METADATA_PATH; import static org.apache.ignite.configuration.DataStorageConfiguration.DFLT_MARSHALLER_PATH; @@ -82,6 +83,9 @@ public class Dump implements AutoCloseable { /** Dump directory. */ private final File dumpDir; + /** Specific consistent id. */ + private final @Nullable String consistentId; + /** * Kernal context for each node in dump. */ @@ -103,14 +107,28 @@ public class Dump implements AutoCloseable { /** * @param dumpDir Dump directory. - * @param keepBinary If {@code true} then don't deserialize {@link KeyCacheObject} and {@link CacheObject}. + * @param keepBinary If {@code true} then keep read entries in binary form. + * @param raw If {@code true} then keep read entries in form of {@link KeyCacheObject} and {@link CacheObject}. + * @param log Logger. */ public Dump(File dumpDir, boolean keepBinary, boolean raw, IgniteLogger log) { + this(dumpDir, null, keepBinary, raw, log); + } + + /** + * @param dumpDir Dump directory. + * @param consistentId If specified, read dump data only for specific node. + * @param keepBinary If {@code true} then keep read entries in binary form. + * @param raw If {@code true} then keep read entries in form of {@link KeyCacheObject} and {@link CacheObject}. + * @param log Logger. + */ + public Dump(File dumpDir, @Nullable String consistentId, boolean keepBinary, boolean raw, IgniteLogger log) { A.ensure(dumpDir != null, "dump directory is null"); A.ensure(dumpDir.exists(), "dump directory not exists"); this.dumpDir = dumpDir; - this.metadata = metadata(dumpDir); + this.consistentId = consistentId == null ? null : U.maskForFileName(consistentId); + this.metadata = metadata(dumpDir, this.consistentId); this.keepBinary = keepBinary; this.cctx = standaloneKernalContext(dumpDir, log); this.raw = raw; @@ -148,7 +166,8 @@ public class Dump implements AutoCloseable { /** @return List of node directories. */ public List<String> nodesDirectories() { File[] dirs = new File(dumpDir, DFLT_STORE_DIR).listFiles(f -> f.isDirectory() - && !(f.getAbsolutePath().endsWith(DFLT_BINARY_METADATA_PATH) || f.getAbsolutePath().endsWith(DFLT_MARSHALLER_PATH))); + && !(f.getAbsolutePath().endsWith(DFLT_BINARY_METADATA_PATH) || f.getAbsolutePath().endsWith(DFLT_MARSHALLER_PATH)) + && (consistentId == null || U.maskForFileName(f.getName()).contains(consistentId))); if (dirs == null) return Collections.emptyList(); @@ -162,12 +181,14 @@ public class Dump implements AutoCloseable { } /** @return List of snapshot metadata saved in {@link #dumpDir}. */ - private static List<SnapshotMetadata> metadata(File dumpDir) { + private static List<SnapshotMetadata> metadata(File dumpDir, @Nullable String consistentId) { JdkMarshaller marsh = MarshallerUtils.jdkMarshaller("fake-node"); ClassLoader clsLdr = U.resolveClassLoader(new IgniteConfiguration()); - File[] files = dumpDir.listFiles(f -> f.getName().endsWith(SNAPSHOT_METAFILE_EXT)); + File[] files = dumpDir.listFiles(f -> + f.getName().endsWith(SNAPSHOT_METAFILE_EXT) && (consistentId == null || f.getName().startsWith(consistentId)) + ); if (files == null) return Collections.emptyList();