|
60 | 60 | import java.util.Collections; |
61 | 61 | import java.util.HashMap; |
62 | 62 | import java.util.HashSet; |
63 | | -import java.util.LinkedHashMap; |
64 | 63 | import java.util.List; |
65 | 64 | import java.util.Map; |
66 | 65 | import java.util.Objects; |
@@ -520,19 +519,30 @@ private SchemaPartition parseSchemaPartitionTableResp( |
520 | 519 | String database = entry1.getKey(); |
521 | 520 | final Map<TSeriesPartitionSlot, TRegionReplicaSet> result1 = |
522 | 521 | regionReplicaMap.computeIfAbsent(database, k -> new HashMap<>()); |
| 522 | + Map<TSeriesPartitionSlot, TConsensusGroupId> seriesPartitionTable = entry1.getValue(); |
| 523 | + |
| 524 | + if (seriesPartitionTable.size() == 1) { |
| 525 | + // Fast collection in case of query for single device |
| 526 | + Map.Entry<TSeriesPartitionSlot, TConsensusGroupId> seriesPartitionEntry = |
| 527 | + seriesPartitionTable.entrySet().iterator().next(); |
| 528 | + List<TRegionReplicaSet> regionReplicaSets = |
| 529 | + partitionCache.getRegionReplicaSet( |
| 530 | + Collections.singletonList(seriesPartitionEntry.getValue())); |
| 531 | + result1.put(seriesPartitionEntry.getKey(), regionReplicaSets.get(0)); |
| 532 | + continue; |
| 533 | + } |
523 | 534 |
|
524 | | - Map<TSeriesPartitionSlot, TConsensusGroupId> orderedMap = |
525 | | - new LinkedHashMap<>(entry1.getValue()); |
526 | | - List<TConsensusGroupId> orderedGroupIds = |
527 | | - orderedMap.values().stream().distinct().collect(Collectors.toList()); |
| 535 | + List<TConsensusGroupId> distinctRegionGroupIds = |
| 536 | + new ArrayList<>(new HashSet<>(seriesPartitionTable.values())); |
528 | 537 | List<TRegionReplicaSet> regionReplicaSets = |
529 | | - partitionCache.getRegionReplicaSet(orderedGroupIds); |
| 538 | + partitionCache.getRegionReplicaSet(distinctRegionGroupIds); |
530 | 539 | Map<TConsensusGroupId, TRegionReplicaSet> groupIdToReplicaSet = new HashMap<>(); |
531 | | - for (int index = 0; index < orderedGroupIds.size(); index++) { |
532 | | - groupIdToReplicaSet.put(orderedGroupIds.get(index), regionReplicaSets.get(index)); |
| 540 | + for (int index = 0; index < distinctRegionGroupIds.size(); index++) { |
| 541 | + groupIdToReplicaSet.put(distinctRegionGroupIds.get(index), regionReplicaSets.get(index)); |
533 | 542 | } |
534 | 543 |
|
535 | | - for (Map.Entry<TSeriesPartitionSlot, TConsensusGroupId> entry2 : orderedMap.entrySet()) { |
| 544 | + for (Map.Entry<TSeriesPartitionSlot, TConsensusGroupId> entry2 : |
| 545 | + seriesPartitionTable.entrySet()) { |
536 | 546 | result1.put(entry2.getKey(), groupIdToReplicaSet.get(entry2.getValue())); |
537 | 547 | } |
538 | 548 | } |
|
0 commit comments