This is an automated email from the ASF dual-hosted git repository. CRZbulabula pushed a commit to branch load-balance-patch in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit b009fbd99bce07b0dfe8ba2bfebfefe5c5c791d0 Author: Yongzao <[email protected]> AuthorDate: Fri Apr 17 19:26:28 2026 +0800 Fast schema partition fetch for single device query (#17493) --- .../plan/analyze/ClusterPartitionFetcher.java | 28 +++++++++++++++------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/ClusterPartitionFetcher.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/ClusterPartitionFetcher.java index a160731fb24..eb65666035a 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/ClusterPartitionFetcher.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/ClusterPartitionFetcher.java @@ -59,7 +59,6 @@ import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; -import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Set; @@ -421,19 +420,30 @@ public class ClusterPartitionFetcher implements IPartitionFetcher { String database = entry1.getKey(); final Map<TSeriesPartitionSlot, TRegionReplicaSet> result1 = regionReplicaMap.computeIfAbsent(database, k -> new HashMap<>()); + Map<TSeriesPartitionSlot, TConsensusGroupId> seriesPartitionTable = entry1.getValue(); + + if (seriesPartitionTable.size() == 1) { + // Fast collection in case of query for single device + Map.Entry<TSeriesPartitionSlot, TConsensusGroupId> seriesPartitionEntry = + seriesPartitionTable.entrySet().iterator().next(); + List<TRegionReplicaSet> regionReplicaSets = + partitionCache.getRegionReplicaSet( + Collections.singletonList(seriesPartitionEntry.getValue())); + result1.put(seriesPartitionEntry.getKey(), regionReplicaSets.get(0)); + continue; + } - Map<TSeriesPartitionSlot, TConsensusGroupId> orderedMap = - new LinkedHashMap<>(entry1.getValue()); - List<TConsensusGroupId> orderedGroupIds = - orderedMap.values().stream().distinct().collect(Collectors.toList()); + List<TConsensusGroupId> distinctRegionGroupIds = + new ArrayList<>(new HashSet<>(seriesPartitionTable.values())); List<TRegionReplicaSet> regionReplicaSets = - partitionCache.getRegionReplicaSet(orderedGroupIds); + partitionCache.getRegionReplicaSet(distinctRegionGroupIds); Map<TConsensusGroupId, TRegionReplicaSet> groupIdToReplicaSet = new HashMap<>(); - for (int index = 0; index < orderedGroupIds.size(); index++) { - groupIdToReplicaSet.put(orderedGroupIds.get(index), regionReplicaSets.get(index)); + for (int index = 0; index < distinctRegionGroupIds.size(); index++) { + groupIdToReplicaSet.put(distinctRegionGroupIds.get(index), regionReplicaSets.get(index)); } - for (Map.Entry<TSeriesPartitionSlot, TConsensusGroupId> entry2 : orderedMap.entrySet()) { + for (Map.Entry<TSeriesPartitionSlot, TConsensusGroupId> entry2 : + seriesPartitionTable.entrySet()) { result1.put(entry2.getKey(), groupIdToReplicaSet.get(entry2.getValue())); } }
