This is an automated email from the ASF dual-hosted git repository. jackietien pushed a commit to branch PartitionCacheBug in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit e7cfe0704a5b59cb7a92679b73fb83f9062e0a13 Author: JackieTien97 <[email protected]> AuthorDate: Mon Nov 27 16:25:10 2023 +0800 Fix concurrent bug in PartitonCache --- .../plan/analyze/cache/partition/PartitionCache.java | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) 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 c8b2a11196f..f6e8fbd7848 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 @@ -187,10 +187,9 @@ public class PartitionCache { * * @param result the result of get database cache * @param devicePaths the devices that need to hit - * * @return */ - private Set<String> fetchStorageGroupAndUpdateCache( + private void fetchStorageGroupAndUpdateCache( StorageGroupCacheResult<?> result, List<String> devicePaths) throws ClientManagerException, TException { storageGroupCacheLock.writeLock().lock(); @@ -206,7 +205,7 @@ public class PartitionCache { Set<String> storageGroupNames = storageGroupSchemaResp.getDatabaseSchemaMap().keySet(); // update all database into cache updateStorageCache(storageGroupNames); - return storageGroupNames; + getStorageGroupMap(result, devicePaths, true); } } } finally { @@ -225,9 +224,9 @@ public class PartitionCache { private void createStorageGroupAndUpdateCache( StorageGroupCacheResult<?> result, List<String> devicePaths, String userName) throws ClientManagerException, MetadataException, TException { + storageGroupCacheLock.writeLock().lock(); try (ConfigNodeClient client = configNodeClientManager.borrowClient(ConfigNodeInfo.CONFIG_REGION_ID)) { - storageGroupCacheLock.writeLock().lock(); // try to check whether database need to be created result.reset(); // try to hit database with all missed devices @@ -278,6 +277,7 @@ public class PartitionCache { } // try to update database cache when all databases has already been created updateStorageCache(storageGroupNamesNeedCreated); + getStorageGroupMap(result, devicePaths, false); } } finally { storageGroupCacheLock.writeLock().unlock(); @@ -358,15 +358,11 @@ public class PartitionCache { try { // try to fetch database from config node when miss fetchStorageGroupAndUpdateCache(result, devicePaths); - // second try to hit database in fast-fail way - getStorageGroupMap(result, devicePaths, true); if (!result.isSuccess() && isAutoCreate) { // try to auto create database of failed device createStorageGroupAndUpdateCache(result, devicePaths, userName); - // third try to hit database in fast-fail way - getStorageGroupMap(result, devicePaths, true); if (!result.isSuccess()) { - throw new StatementAnalyzeException("Failed to get database Map in three attempts."); + throw new StatementAnalyzeException("Failed to get database Map"); } } } catch (TException | MetadataException | ClientManagerException e) {
