nizhikov commented on code in PR #12117: URL: https://github.com/apache/ignite/pull/12117#discussion_r2123170602
########## modules/core/src/main/java/org/apache/ignite/dump/DumpReader.java: ########## @@ -369,4 +364,65 @@ private static GridKernalContext standaloneKernalContext(SnapshotFileTree sft, I throw new IgniteException(e); } } + + /** + * @param dump Dump. + * @param cacheIds Set of cache id we want to read from dump. If {@code null} then all caches read. + * @return Mapping from grpId -> "node list" and cache configs list. + */ + private GroupsConfigs groupsConfigs(Dump dump, @Nullable Set<Integer> cacheIds) { + Map<Integer, List<String>> grpsToNodes = new HashMap<>(); + + Set<Integer> grpIds = cfg.groupNames() != null + ? Arrays.stream(cfg.groupNames()).map(CU::cacheId).collect(Collectors.toSet()) + : null; + + for (SnapshotMetadata meta : dump.metadata()) { + for (Integer grp : meta.partitions().keySet()) { + if (grpIds == null || grpIds.contains(grp)) + grpsToNodes.computeIfAbsent(grp, key -> new ArrayList<>()).add(meta.folderName()); + } + } + + Iterator<Map.Entry<Integer, List<String>>> grpToNodesIter = grpsToNodes.entrySet().iterator(); + List<StoredCacheData> ccfgs = new ArrayList<>(); + + while (grpToNodesIter.hasNext()) { + Map.Entry<Integer, List<String>> grpToNodes = grpToNodesIter.next(); + + // Read all group configs from single node. + List<StoredCacheData> grpCaches = dump.configs(F.first(grpToNodes.getValue()), grpToNodes.getKey()); + + // Keep only caches from filter. + if (cacheIds != null) + grpCaches.removeIf(scd -> !cacheIds.contains(scd.cacheId())); + + if (grpCaches.isEmpty()) { + // Remove whole group to skip files read. + grpToNodesIter.remove(); + + continue; + } + + ccfgs.addAll(grpCaches); + } + + // Optimize - skip whole cache if only one in group! + return new GroupsConfigs(grpsToNodes, ccfgs); + } + + /** */ + private static class GroupsConfigs { + /** Key is group id, value is list of {@link NodeFileTree#folderName()} of nodes containing group. */ + public final Map<Integer, List<String>> grpToNodes; + + /** Cache configurations. */ + public final @Nullable Collection<StoredCacheData> cacheCfgs; Review Comment: class is private. variable is final, we can safely keep this public to simplify code. ########## modules/core/src/main/java/org/apache/ignite/dump/DumpReader.java: ########## @@ -369,4 +364,65 @@ private static GridKernalContext standaloneKernalContext(SnapshotFileTree sft, I throw new IgniteException(e); } } + + /** + * @param dump Dump. + * @param cacheIds Set of cache id we want to read from dump. If {@code null} then all caches read. + * @return Mapping from grpId -> "node list" and cache configs list. + */ + private GroupsConfigs groupsConfigs(Dump dump, @Nullable Set<Integer> cacheIds) { + Map<Integer, List<String>> grpsToNodes = new HashMap<>(); + + Set<Integer> grpIds = cfg.groupNames() != null + ? Arrays.stream(cfg.groupNames()).map(CU::cacheId).collect(Collectors.toSet()) + : null; + + for (SnapshotMetadata meta : dump.metadata()) { + for (Integer grp : meta.partitions().keySet()) { + if (grpIds == null || grpIds.contains(grp)) + grpsToNodes.computeIfAbsent(grp, key -> new ArrayList<>()).add(meta.folderName()); + } + } + + Iterator<Map.Entry<Integer, List<String>>> grpToNodesIter = grpsToNodes.entrySet().iterator(); + List<StoredCacheData> ccfgs = new ArrayList<>(); + + while (grpToNodesIter.hasNext()) { + Map.Entry<Integer, List<String>> grpToNodes = grpToNodesIter.next(); + + // Read all group configs from single node. + List<StoredCacheData> grpCaches = dump.configs(F.first(grpToNodes.getValue()), grpToNodes.getKey()); + + // Keep only caches from filter. + if (cacheIds != null) + grpCaches.removeIf(scd -> !cacheIds.contains(scd.cacheId())); + + if (grpCaches.isEmpty()) { + // Remove whole group to skip files read. + grpToNodesIter.remove(); + + continue; + } + + ccfgs.addAll(grpCaches); + } + + // Optimize - skip whole cache if only one in group! + return new GroupsConfigs(grpsToNodes, ccfgs); + } + + /** */ + private static class GroupsConfigs { + /** Key is group id, value is list of {@link NodeFileTree#folderName()} of nodes containing group. */ + public final Map<Integer, List<String>> grpToNodes; Review Comment: class is private. variable is final, we can safely keep this public to simplify code. -- 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. To unsubscribe, e-mail: notifications-unsubscr...@ignite.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org