|
59 | 59 | import java.util.Collections; |
60 | 60 | import java.util.HashMap; |
61 | 61 | import java.util.HashSet; |
62 | | -import java.util.LinkedHashMap; |
63 | 62 | import java.util.List; |
64 | 63 | import java.util.Map; |
65 | 64 | import java.util.Set; |
@@ -421,16 +420,31 @@ private SchemaPartition parseSchemaPartitionTableResp( |
421 | 420 | String database = entry1.getKey(); |
422 | 421 | final Map<TSeriesPartitionSlot, TRegionReplicaSet> result1 = |
423 | 422 | regionReplicaMap.computeIfAbsent(database, k -> new HashMap<>()); |
| 423 | + Map<TSeriesPartitionSlot, TConsensusGroupId> seriesPartitionTable = entry1.getValue(); |
| 424 | + |
| 425 | + if (seriesPartitionTable.size() == 1) { |
| 426 | + // Fast collection in case of query for single device |
| 427 | + Map.Entry<TSeriesPartitionSlot, TConsensusGroupId> seriesPartitionEntry = |
| 428 | + seriesPartitionTable.entrySet().iterator().next(); |
| 429 | + List<TRegionReplicaSet> regionReplicaSets = |
| 430 | + partitionCache.getRegionReplicaSet( |
| 431 | + Collections.singletonList(seriesPartitionEntry.getValue())); |
| 432 | + result1.put(seriesPartitionEntry.getKey(), regionReplicaSets.get(0)); |
| 433 | + continue; |
| 434 | + } |
424 | 435 |
|
425 | | - Map<TSeriesPartitionSlot, TConsensusGroupId> orderedMap = |
426 | | - new LinkedHashMap<>(entry1.getValue()); |
427 | | - List<TConsensusGroupId> orderedGroupIds = new ArrayList<>(orderedMap.values()); |
| 436 | + List<TConsensusGroupId> distinctRegionGroupIds = |
| 437 | + new ArrayList<>(new HashSet<>(seriesPartitionTable.values())); |
428 | 438 | List<TRegionReplicaSet> regionReplicaSets = |
429 | | - partitionCache.getRegionReplicaSet(orderedGroupIds); |
| 439 | + partitionCache.getRegionReplicaSet(distinctRegionGroupIds); |
| 440 | + Map<TConsensusGroupId, TRegionReplicaSet> groupIdToReplicaSet = new HashMap<>(); |
| 441 | + for (int index = 0; index < distinctRegionGroupIds.size(); index++) { |
| 442 | + groupIdToReplicaSet.put(distinctRegionGroupIds.get(index), regionReplicaSets.get(index)); |
| 443 | + } |
430 | 444 |
|
431 | | - int index = 0; |
432 | | - for (Map.Entry<TSeriesPartitionSlot, TConsensusGroupId> entry2 : orderedMap.entrySet()) { |
433 | | - result1.put(entry2.getKey(), regionReplicaSets.get(index++)); |
| 445 | + for (Map.Entry<TSeriesPartitionSlot, TConsensusGroupId> entry2 : |
| 446 | + seriesPartitionTable.entrySet()) { |
| 447 | + result1.put(entry2.getKey(), groupIdToReplicaSet.get(entry2.getValue())); |
434 | 448 | } |
435 | 449 | } |
436 | 450 |
|
|
0 commit comments