This is an automated email from the ASF dual-hosted git repository. jackietien pushed a commit to branch rc/1.3.5 in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit 968d65cba0404f6dcff490508221eb45d6a84bc9 Author: Caideyipi <[email protected]> AuthorDate: Fri Jul 25 14:16:35 2025 +0800 [To dev/1.3] Optimize partition cache getRegionReplicaSet interface performance by batching --- .../plan/analyze/ClusterPartitionFetcher.java | 54 +++- .../analyze/cache/partition/PartitionCache.java | 347 ++++++++++++--------- .../plan/analyze/cache/PartitionCacheTest.java | 5 +- 3 files changed, 242 insertions(+), 164 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 e76973c516b..ff19dd79cf5 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 @@ -56,9 +56,10 @@ import org.slf4j.LoggerFactory; import java.io.IOException; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.HashSet; -import java.util.LinkedList; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Set; @@ -415,15 +416,21 @@ public class ClusterPartitionFetcher implements IPartitionFetcher { private SchemaPartition parseSchemaPartitionTableResp( TSchemaPartitionTableResp schemaPartitionTableResp) { Map<String, Map<TSeriesPartitionSlot, TRegionReplicaSet>> regionReplicaMap = new HashMap<>(); - for (Map.Entry<String, Map<TSeriesPartitionSlot, TConsensusGroupId>> entry1 : + for (final Map.Entry<String, Map<TSeriesPartitionSlot, TConsensusGroupId>> entry1 : schemaPartitionTableResp.getSchemaPartitionTable().entrySet()) { - Map<TSeriesPartitionSlot, TRegionReplicaSet> result1 = - regionReplicaMap.computeIfAbsent(entry1.getKey(), k -> new HashMap<>()); - for (Map.Entry<TSeriesPartitionSlot, TConsensusGroupId> entry2 : - entry1.getValue().entrySet()) { - TSeriesPartitionSlot seriesPartitionSlot = entry2.getKey(); - TConsensusGroupId consensusGroupId = entry2.getValue(); - result1.put(seriesPartitionSlot, partitionCache.getRegionReplicaSet(consensusGroupId)); + String database = entry1.getKey(); + final Map<TSeriesPartitionSlot, TRegionReplicaSet> result1 = + regionReplicaMap.computeIfAbsent(database, k -> new HashMap<>()); + + Map<TSeriesPartitionSlot, TConsensusGroupId> orderedMap = + new LinkedHashMap<>(entry1.getValue()); + List<TConsensusGroupId> orderedGroupIds = new ArrayList<>(orderedMap.values()); + List<TRegionReplicaSet> regionReplicaSets = + partitionCache.getRegionReplicaSet(orderedGroupIds); + + int index = 0; + for (Map.Entry<TSeriesPartitionSlot, TConsensusGroupId> entry2 : orderedMap.entrySet()) { + result1.put(entry2.getKey(), regionReplicaSets.get(index++)); } } @@ -443,6 +450,29 @@ public class ClusterPartitionFetcher implements IPartitionFetcher { } private DataPartition parseDataPartitionResp(TDataPartitionTableResp dataPartitionTableResp) { + final Set<TConsensusGroupId> uniqueConsensusGroupIds = new HashSet<>(); + for (final Map< + String, Map<TSeriesPartitionSlot, Map<TTimePartitionSlot, List<TConsensusGroupId>>>> + partitionTable : Collections.singleton(dataPartitionTableResp.getDataPartitionTable())) { + for (final Map<TSeriesPartitionSlot, Map<TTimePartitionSlot, List<TConsensusGroupId>>> + seriesPartitionMap : partitionTable.values()) { + for (final Map<TTimePartitionSlot, List<TConsensusGroupId>> timePartitionMap : + seriesPartitionMap.values()) { + for (final List<TConsensusGroupId> consensusGroupIds : timePartitionMap.values()) { + uniqueConsensusGroupIds.addAll(consensusGroupIds); + } + } + } + } + + final List<TRegionReplicaSet> allRegionReplicaSets = + partitionCache.getRegionReplicaSet(new ArrayList<>(uniqueConsensusGroupIds)); + final List<TConsensusGroupId> consensusGroupIds = new ArrayList<>(uniqueConsensusGroupIds); + final Map<TConsensusGroupId, TRegionReplicaSet> regionReplicaSetMap = new HashMap<>(); + for (int i = 0; i < allRegionReplicaSets.size(); i++) { + regionReplicaSetMap.put(consensusGroupIds.get(i), allRegionReplicaSets.get(i)); + } + Map<String, Map<TSeriesPartitionSlot, Map<TTimePartitionSlot, List<TRegionReplicaSet>>>> regionReplicaSet = new HashMap<>(); for (Map.Entry< @@ -456,9 +486,9 @@ public class ClusterPartitionFetcher implements IPartitionFetcher { result1.computeIfAbsent(entry2.getKey(), k -> new HashMap<>()); for (Map.Entry<TTimePartitionSlot, List<TConsensusGroupId>> entry3 : entry2.getValue().entrySet()) { - List<TRegionReplicaSet> regionReplicaSets = new LinkedList<>(); - for (TConsensusGroupId consensusGroupId : entry3.getValue()) { - regionReplicaSets.add(partitionCache.getRegionReplicaSet(consensusGroupId)); + final List<TRegionReplicaSet> regionReplicaSets = new ArrayList<>(); + for (TConsensusGroupId groupId : entry3.getValue()) { + regionReplicaSets.add(regionReplicaSetMap.get(groupId)); } result2.put(entry3.getKey(), regionReplicaSets); } diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/cache/partition/PartitionCache.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/cache/partition/PartitionCache.java index e649822bac4..8c701bcd126 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/cache/partition/PartitionCache.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/cache/partition/PartitionCache.java @@ -68,9 +68,9 @@ import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; -import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Set; import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.locks.ReentrantReadWriteLock; @@ -317,10 +317,12 @@ public class PartitionCache { for (String devicePath : devicePaths) { String storageGroupName = getStorageGroupName(devicePath); if (null == storageGroupName) { - logger.debug( - "[{} Cache] miss when search device {}", - CacheMetrics.STORAGE_GROUP_CACHE_NAME, - devicePath); + if (logger.isDebugEnabled()) { + logger.debug( + "[{} Cache] miss when search device {}", + CacheMetrics.STORAGE_GROUP_CACHE_NAME, + devicePath); + } status = false; if (failFast) { break; @@ -335,10 +337,12 @@ public class PartitionCache { if (!status) { result.setFailed(); } - logger.debug( - "[{} Cache] hit when search device {}", - CacheMetrics.STORAGE_GROUP_CACHE_NAME, - devicePaths); + if (logger.isDebugEnabled()) { + logger.debug( + "[{} Cache] hit when search device {}", + CacheMetrics.STORAGE_GROUP_CACHE_NAME, + devicePaths); + } cacheMetrics.record(status, CacheMetrics.STORAGE_GROUP_CACHE_NAME); } finally { storageGroupCacheLock.readLock().unlock(); @@ -439,26 +443,30 @@ public class PartitionCache { /** * get regionReplicaSet from local and confignode * - * @param consensusGroupId the id of consensus group - * @return regionReplicaSet + * @param consensusGroupIds the ids of consensus group + * @return List<regionReplicaSet> * @throws RuntimeException if failed to get regionReplicaSet from confignode * @throws StatementAnalyzeException if there are exception when try to get latestRegionRouteMap */ - public TRegionReplicaSet getRegionReplicaSet(TConsensusGroupId consensusGroupId) { - TRegionReplicaSet result; + public List<TRegionReplicaSet> getRegionReplicaSet(List<TConsensusGroupId> consensusGroupIds) { + if (consensusGroupIds.isEmpty()) { + return Collections.emptyList(); + } + List<TRegionReplicaSet> result; // try to get regionReplicaSet from cache regionReplicaSetLock.readLock().lock(); try { - result = groupIdToReplicaSetMap.get(consensusGroupId); + result = getRegionReplicaSetInternal(consensusGroupIds); } finally { regionReplicaSetLock.readLock().unlock(); } - if (result == null) { + if (result.isEmpty()) { // if not hit then try to get regionReplicaSet from confignode regionReplicaSetLock.writeLock().lock(); try { - // verify that there are not hit in cache - if (!groupIdToReplicaSetMap.containsKey(consensusGroupId)) { + // double check after getting the write lock + result = getRegionReplicaSetInternal(consensusGroupIds); + if (result.isEmpty()) { try (ConfigNodeClient client = configNodeClientManager.borrowClient(ConfigNodeInfo.CONFIG_REGION_ID)) { TRegionRouteMapResp resp = client.getLatestRegionRouteMap(); @@ -470,18 +478,18 @@ public class PartitionCache { resp.getStatus(), resp.getRegionRouteMap()); } + result = getRegionReplicaSetInternal(consensusGroupIds); // if confignode don't have then will throw RuntimeException - if (!groupIdToReplicaSetMap.containsKey(consensusGroupId)) { + if (result.isEmpty()) { // failed to get RegionReplicaSet from confignode throw new RuntimeException( - "Failed to get replicaSet of consensus group[id= " + consensusGroupId + "]"); + "Failed to get replicaSet of consensus groups[ids= " + consensusGroupIds + "]"); } } catch (ClientManagerException | TException e) { throw new StatementAnalyzeException( "An error occurred when executing getRegionReplicaSet():" + e.getMessage()); } } - result = groupIdToReplicaSetMap.get(consensusGroupId); } finally { regionReplicaSetLock.writeLock().unlock(); } @@ -490,6 +498,20 @@ public class PartitionCache { return result; } + private List<TRegionReplicaSet> getRegionReplicaSetInternal( + List<TConsensusGroupId> consensusGroupIds) { + List<TRegionReplicaSet> result = new ArrayList<>(consensusGroupIds.size()); + for (TConsensusGroupId groupId : consensusGroupIds) { + TRegionReplicaSet replicaSet = groupIdToReplicaSetMap.get(groupId); + if (replicaSet != null) { + result.add(replicaSet); + } else { + return Collections.emptyList(); + } + } + return result; + } + /** * update regionReplicaSetMap according to timestamp * @@ -551,34 +573,45 @@ public class PartitionCache { schemaPartitionCache.getIfPresent(storageGroupName); if (null == schemaPartitionTable) { // if database not find, then return cache miss. - logger.debug( - "[{} Cache] miss when search database {}", - CacheMetrics.SCHEMA_PARTITION_CACHE_NAME, - storageGroupName); + if (logger.isDebugEnabled()) { + logger.debug( + "[{} Cache] miss when search database {}", + CacheMetrics.SCHEMA_PARTITION_CACHE_NAME, + storageGroupName); + } cacheMetrics.record(false, CacheMetrics.SCHEMA_PARTITION_CACHE_NAME); return null; } Map<TSeriesPartitionSlot, TConsensusGroupId> map = schemaPartitionTable.getSchemaPartitionMap(); // check cache for each device + List<TSeriesPartitionSlot> seriesPartitionSlots = new ArrayList<>(entry.getValue().size()); + List<TConsensusGroupId> consensusGroupIds = new ArrayList<>(entry.getValue().size()); for (String device : entry.getValue()) { TSeriesPartitionSlot seriesPartitionSlot = partitionExecutor.getSeriesPartitionSlot(device); if (!map.containsKey(seriesPartitionSlot)) { // if one device not find, then return cache miss. - logger.debug( - "[{} Cache] miss when search device {}", - CacheMetrics.SCHEMA_PARTITION_CACHE_NAME, - device); + if (logger.isDebugEnabled()) { + logger.debug( + "[{} Cache] miss when search device {}", + CacheMetrics.SCHEMA_PARTITION_CACHE_NAME, + device); + } cacheMetrics.record(false, CacheMetrics.SCHEMA_PARTITION_CACHE_NAME); return null; } - TConsensusGroupId consensusGroupId = map.get(seriesPartitionSlot); - TRegionReplicaSet regionReplicaSet = getRegionReplicaSet(consensusGroupId); - regionReplicaSetMap.put(seriesPartitionSlot, regionReplicaSet); + seriesPartitionSlots.add(seriesPartitionSlot); + consensusGroupIds.add(map.get(seriesPartitionSlot)); + } + List<TRegionReplicaSet> replicaSets = getRegionReplicaSet(consensusGroupIds); + for (int i = 0; i < replicaSets.size(); i++) { + regionReplicaSetMap.put(seriesPartitionSlots.get(i), replicaSets.get(i)); } } - logger.debug("[{} Cache] hit", CacheMetrics.SCHEMA_PARTITION_CACHE_NAME); + if (logger.isDebugEnabled()) { + logger.debug("[{} Cache] hit", CacheMetrics.SCHEMA_PARTITION_CACHE_NAME); + } // cache hit cacheMetrics.record(true, CacheMetrics.SCHEMA_PARTITION_CACHE_NAME); return new SchemaPartition( @@ -656,22 +689,115 @@ public class PartitionCache { cacheMetrics.record(false, CacheMetrics.DATA_PARTITION_CACHE_NAME); return null; } - Map<String, Map<TSeriesPartitionSlot, Map<TTimePartitionSlot, List<TRegionReplicaSet>>>> - dataPartitionMap = new HashMap<>(); + + final Set<TConsensusGroupId> allConsensusGroupIds = new HashSet<>(); + final Map<TConsensusGroupId, HashSet<TimeSlotRegionInfo>> consensusGroupToTimeSlotMap = + new HashMap<>(); + // check cache for each database for (Map.Entry<String, List<DataPartitionQueryParam>> entry : storageGroupToQueryParamsMap.entrySet()) { - if (null == entry.getValue() - || entry.getValue().isEmpty() - || !getStorageGroupDataPartition(dataPartitionMap, entry.getKey(), entry.getValue())) { + String databaseName = entry.getKey(); + List<DataPartitionQueryParam> params = entry.getValue(); + + if (null == params || params.isEmpty()) { cacheMetrics.record(false, CacheMetrics.DATA_PARTITION_CACHE_NAME); return null; } + + DataPartitionTable dataPartitionTable = dataPartitionCache.getIfPresent(databaseName); + if (null == dataPartitionTable) { + if (logger.isDebugEnabled()) { + logger.debug( + "[{} Cache] miss when search database {}", + CacheMetrics.DATA_PARTITION_CACHE_NAME, + databaseName); + } + cacheMetrics.record(false, CacheMetrics.DATA_PARTITION_CACHE_NAME); + return null; + } + + Map<TSeriesPartitionSlot, SeriesPartitionTable> cachedDatabasePartitionMap = + dataPartitionTable.getDataPartitionMap(); + + for (DataPartitionQueryParam param : params) { + TSeriesPartitionSlot seriesPartitionSlot; + if (null != param.getDevicePath()) { + seriesPartitionSlot = partitionExecutor.getSeriesPartitionSlot(param.getDevicePath()); + } else { + return null; + } + + SeriesPartitionTable cachedSeriesPartitionTable = + cachedDatabasePartitionMap.get(seriesPartitionSlot); + if (null == cachedSeriesPartitionTable) { + if (logger.isDebugEnabled()) { + logger.debug( + "[{} Cache] miss when search device {}", + CacheMetrics.DATA_PARTITION_CACHE_NAME, + param.getDevicePath()); + } + cacheMetrics.record(false, CacheMetrics.DATA_PARTITION_CACHE_NAME); + return null; + } + + Map<TTimePartitionSlot, List<TConsensusGroupId>> cachedTimePartitionSlot = + cachedSeriesPartitionTable.getSeriesPartitionMap(); + + if (param.getTimePartitionSlotList().isEmpty()) { + return null; + } + + for (TTimePartitionSlot timePartitionSlot : param.getTimePartitionSlotList()) { + List<TConsensusGroupId> cacheConsensusGroupIds = + cachedTimePartitionSlot.get(timePartitionSlot); + if (null == cacheConsensusGroupIds + || cacheConsensusGroupIds.isEmpty() + || null == timePartitionSlot) { + if (logger.isDebugEnabled()) { + logger.debug( + "[{} Cache] miss when search time partition {}", + CacheMetrics.DATA_PARTITION_CACHE_NAME, + timePartitionSlot); + } + cacheMetrics.record(false, CacheMetrics.DATA_PARTITION_CACHE_NAME); + return null; + } + + for (TConsensusGroupId groupId : cacheConsensusGroupIds) { + allConsensusGroupIds.add(groupId); + consensusGroupToTimeSlotMap + .computeIfAbsent(groupId, k -> new HashSet<>()) + .add( + new TimeSlotRegionInfo(databaseName, seriesPartitionSlot, timePartitionSlot)); + } + } + } } + + final List<TConsensusGroupId> consensusGroupIds = new ArrayList<>(allConsensusGroupIds); + final List<TRegionReplicaSet> allRegionReplicaSets = getRegionReplicaSet(consensusGroupIds); + + Map<String, Map<TSeriesPartitionSlot, Map<TTimePartitionSlot, List<TRegionReplicaSet>>>> + dataPartitionMap = new HashMap<>(); + + for (int i = 0; i < allRegionReplicaSets.size(); i++) { + TConsensusGroupId groupId = consensusGroupIds.get(i); + TRegionReplicaSet replicaSet = allRegionReplicaSets.get(i); + + for (TimeSlotRegionInfo info : consensusGroupToTimeSlotMap.get(groupId)) { + dataPartitionMap + .computeIfAbsent(info.databaseName, k -> new HashMap<>()) + .computeIfAbsent(info.seriesPartitionSlot, k -> new HashMap<>()) + .computeIfAbsent(info.timePartitionSlot, k -> new ArrayList<>()) + .add(replicaSet); + } + } + if (logger.isDebugEnabled()) { logger.debug("[{} Cache] hit", CacheMetrics.DATA_PARTITION_CACHE_NAME); } - // cache hit + cacheMetrics.record(true, CacheMetrics.DATA_PARTITION_CACHE_NAME); return new DataPartition(dataPartitionMap, seriesSlotExecutorName, seriesPartitionSlotNum); } finally { @@ -679,124 +805,39 @@ public class PartitionCache { } } - /** - * get dataPartition from database - * - * @param dataPartitionMap result - * @param storageGroupName database that need to get - * @param dataPartitionQueryParams specific query params of data partition - * @return whether hit - */ - private boolean getStorageGroupDataPartition( - Map<String, Map<TSeriesPartitionSlot, Map<TTimePartitionSlot, List<TRegionReplicaSet>>>> - dataPartitionMap, - String storageGroupName, - List<DataPartitionQueryParam> dataPartitionQueryParams) { - DataPartitionTable dataPartitionTable = dataPartitionCache.getIfPresent(storageGroupName); - if (null == dataPartitionTable) { - if (logger.isDebugEnabled()) { - logger.debug( - "[{} Cache] miss when search database {}", - CacheMetrics.DATA_PARTITION_CACHE_NAME, - storageGroupName); - } - return false; + private static class TimeSlotRegionInfo { + final String databaseName; + final TSeriesPartitionSlot seriesPartitionSlot; + final TTimePartitionSlot timePartitionSlot; + + TimeSlotRegionInfo( + String databaseName, + TSeriesPartitionSlot seriesPartitionSlot, + TTimePartitionSlot timePartitionSlot) { + this.databaseName = databaseName; + this.seriesPartitionSlot = seriesPartitionSlot; + this.timePartitionSlot = timePartitionSlot; } - Map<TSeriesPartitionSlot, SeriesPartitionTable> cachedStorageGroupPartitionMap = - dataPartitionTable.getDataPartitionMap(); - Map<TSeriesPartitionSlot, Map<TTimePartitionSlot, List<TRegionReplicaSet>>> - seriesSlotToTimePartitionMap = - dataPartitionMap.computeIfAbsent(storageGroupName, k -> new HashMap<>()); - // check cache for each device - for (DataPartitionQueryParam dataPartitionQueryParam : dataPartitionQueryParams) { - if (!getDeviceDataPartition( - seriesSlotToTimePartitionMap, dataPartitionQueryParam, cachedStorageGroupPartitionMap)) { - return false; - } - } - return true; - } - /** - * get dataPartition from device - * - * @param seriesSlotToTimePartitionMap result - * @param dataPartitionQueryParam specific query param of data partition - * @param cachedStorageGroupPartitionMap all cached data partition map of related database - * @return whether hit - */ - private boolean getDeviceDataPartition( - Map<TSeriesPartitionSlot, Map<TTimePartitionSlot, List<TRegionReplicaSet>>> - seriesSlotToTimePartitionMap, - DataPartitionQueryParam dataPartitionQueryParam, - Map<TSeriesPartitionSlot, SeriesPartitionTable> cachedStorageGroupPartitionMap) { - TSeriesPartitionSlot seriesPartitionSlot; - if (null != dataPartitionQueryParam.getDevicePath()) { - seriesPartitionSlot = - partitionExecutor.getSeriesPartitionSlot(dataPartitionQueryParam.getDevicePath()); - } else { - return false; - } - SeriesPartitionTable cachedSeriesPartitionTable = - cachedStorageGroupPartitionMap.get(seriesPartitionSlot); - if (null == cachedSeriesPartitionTable) { - if (logger.isDebugEnabled()) { - logger.debug( - "[{} Cache] miss when search device {}", - CacheMetrics.DATA_PARTITION_CACHE_NAME, - dataPartitionQueryParam.getDevicePath()); - } - return false; - } - Map<TTimePartitionSlot, List<TConsensusGroupId>> cachedTimePartitionSlot = - cachedSeriesPartitionTable.getSeriesPartitionMap(); - Map<TTimePartitionSlot, List<TRegionReplicaSet>> timePartitionSlotListMap = - seriesSlotToTimePartitionMap.computeIfAbsent(seriesPartitionSlot, k -> new HashMap<>()); - // Notice: when query all time partition, then miss - if (dataPartitionQueryParam.getTimePartitionSlotList().isEmpty()) { - return false; - } - // check cache for each time partition - for (TTimePartitionSlot timePartitionSlot : - dataPartitionQueryParam.getTimePartitionSlotList()) { - if (!getTimeSlotDataPartition( - timePartitionSlotListMap, timePartitionSlot, cachedTimePartitionSlot)) { + @Override + public boolean equals(Object o) { + if (o == null || getClass() != o.getClass()) { return false; } - } - return true; - } - /** - * get dataPartition from time slot - * - * @param timePartitionSlotListMap result - * @param timePartitionSlot the specific time partition slot of data partition - * @param cachedTimePartitionSlot all cached time slot map of related device - * @return whether hit - */ - private boolean getTimeSlotDataPartition( - Map<TTimePartitionSlot, List<TRegionReplicaSet>> timePartitionSlotListMap, - TTimePartitionSlot timePartitionSlot, - Map<TTimePartitionSlot, List<TConsensusGroupId>> cachedTimePartitionSlot) { - List<TConsensusGroupId> cacheConsensusGroupId = cachedTimePartitionSlot.get(timePartitionSlot); - if (null == cacheConsensusGroupId - || cacheConsensusGroupId.isEmpty() - || null == timePartitionSlot) { - if (logger.isDebugEnabled()) { - logger.debug( - "[{} Cache] miss when search time partition {}", - CacheMetrics.DATA_PARTITION_CACHE_NAME, - timePartitionSlot); - } - return false; + TimeSlotRegionInfo that = (TimeSlotRegionInfo) o; + return Objects.equals(databaseName, that.databaseName) + && Objects.equals(seriesPartitionSlot, that.seriesPartitionSlot) + && Objects.equals(timePartitionSlot, that.timePartitionSlot); } - List<TRegionReplicaSet> regionReplicaSets = new LinkedList<>(); - for (TConsensusGroupId consensusGroupId : cacheConsensusGroupId) { - regionReplicaSets.add(getRegionReplicaSet(consensusGroupId)); + + @Override + public int hashCode() { + int result = Objects.hashCode(databaseName); + result = 31 * result + Objects.hashCode(seriesPartitionSlot); + result = 31 * result + Objects.hashCode(timePartitionSlot); + return result; } - timePartitionSlotListMap.put(timePartitionSlot, regionReplicaSets); - return true; } /** @@ -879,12 +920,16 @@ public class PartitionCache { // endregion public void invalidAllCache() { - logger.debug("[Partition Cache] invalid"); + if (logger.isDebugEnabled()) { + logger.debug("[Partition Cache] invalid"); + } removeFromStorageGroupCache(); invalidAllDataPartitionCache(); invalidAllSchemaPartitionCache(); invalidReplicaSetCache(); - logger.debug("[Partition Cache] is invalid:{}", this); + if (logger.isDebugEnabled()) { + logger.debug("[Partition Cache] is invalid:{}", this); + } } @Override diff --git a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/analyze/cache/PartitionCacheTest.java b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/analyze/cache/PartitionCacheTest.java index ca9fcb062a7..43b3a867472 100644 --- a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/analyze/cache/PartitionCacheTest.java +++ b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/analyze/cache/PartitionCacheTest.java @@ -258,7 +258,10 @@ public class PartitionCacheTest { private void checkRegionReplicaSet(TConsensusGroupId consensusGroupId) { try { - assertNotNull(partitionCache.getRegionReplicaSet(consensusGroupId)); + List<TRegionReplicaSet> regionReplicaSets = + partitionCache.getRegionReplicaSet(Collections.singletonList(consensusGroupId)); + assertEquals(1, regionReplicaSets.size()); + assertNotNull(regionReplicaSets.get(0)); } catch (Exception e) { fail(e.getMessage()); }
