You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@iotdb.apache.org by GitBox <gi...@apache.org> on 2022/11/15 03:31:24 UTC

[GitHub] [iotdb] JackieTien97 commented on a diff in pull request #7977: [IOTDB-4815] Apply SchemaCache for explicit timeseries query

JackieTien97 commented on code in PR #7977:
URL: https://github.com/apache/iotdb/pull/7977#discussion_r1022281746


##########
server/src/main/java/org/apache/iotdb/db/mpp/plan/analyze/ClusterSchemaFetcher.java:
##########
@@ -104,10 +106,67 @@ public ClusterSchemaTree fetchSchemaWithTags(PathPatternTree patternTree) {
   private ClusterSchemaTree fetchSchema(PathPatternTree patternTree, boolean withTags) {
     Map<Integer, Template> templateMap = new HashMap<>();
     patternTree.constructTree();
-    for (PartialPath pattern : patternTree.getAllPathPatterns()) {
+    List<PartialPath> fullPathList = new ArrayList<>();
+    List<PartialPath> pathPatternList = patternTree.getAllPathPatterns();
+    for (PartialPath pattern : pathPatternList) {
       templateMap.putAll(templateManager.checkAllRelatedTemplate(pattern));
+      if (!pattern.hasWildcard() && !withTags) {
+        fullPathList.add(pattern);
+      }
+    }
+
+    if (fullPathList.isEmpty()) {
+      return executeSchemaFetchQuery(new SchemaFetchStatement(patternTree, templateMap, withTags));
+    }
+
+    ClusterSchemaTree schemaTree;
+    if (fullPathList.size() == pathPatternList.size()) {
+      boolean isAllCached = true;
+      schemaTree = new ClusterSchemaTree();
+      String[] measurement = new String[1];
+      schemaCache.takeReadLock();
+      try {
+        ClusterSchemaTree cachedSchema;
+        for (PartialPath fullPath : fullPathList) {
+          measurement[0] = fullPath.getMeasurement();
+          cachedSchema = schemaCache.get(fullPath.getDevicePath(), measurement);
+          if (cachedSchema.isEmpty()) {
+            isAllCached = false;
+            break;
+          } else {
+            schemaTree.mergeSchemaTree(cachedSchema);
+          }
+        }
+      } finally {
+        schemaCache.releaseReadLock();
+      }
+      if (isAllCached) {
+        SchemaPartition schemaPartition = partitionFetcher.getSchemaPartition(patternTree);

Review Comment:
   We only need storage groups in `SchemaPartition`, I think it's too heavy to fetch it from partitionFetcher especially when cache miss, it may also need to fetch from remote config.
   And even if cache hit, there is no need for us to do too much calculation in `partitionFetcher.getSchemaPartition`



##########
server/src/main/java/org/apache/iotdb/db/mpp/plan/analyze/ClusterSchemaFetcher.java:
##########
@@ -104,10 +106,67 @@ public ClusterSchemaTree fetchSchemaWithTags(PathPatternTree patternTree) {
   private ClusterSchemaTree fetchSchema(PathPatternTree patternTree, boolean withTags) {
     Map<Integer, Template> templateMap = new HashMap<>();
     patternTree.constructTree();
-    for (PartialPath pattern : patternTree.getAllPathPatterns()) {
+    List<PartialPath> fullPathList = new ArrayList<>();
+    List<PartialPath> pathPatternList = patternTree.getAllPathPatterns();
+    for (PartialPath pattern : pathPatternList) {
       templateMap.putAll(templateManager.checkAllRelatedTemplate(pattern));
+      if (!pattern.hasWildcard() && !withTags) {
+        fullPathList.add(pattern);
+      }
+    }
+
+    if (fullPathList.isEmpty()) {
+      return executeSchemaFetchQuery(new SchemaFetchStatement(patternTree, templateMap, withTags));
+    }
+
+    ClusterSchemaTree schemaTree;
+    if (fullPathList.size() == pathPatternList.size()) {
+      boolean isAllCached = true;
+      schemaTree = new ClusterSchemaTree();
+      String[] measurement = new String[1];
+      schemaCache.takeReadLock();
+      try {
+        ClusterSchemaTree cachedSchema;
+        for (PartialPath fullPath : fullPathList) {
+          measurement[0] = fullPath.getMeasurement();
+          cachedSchema = schemaCache.get(fullPath.getDevicePath(), measurement);
+          if (cachedSchema.isEmpty()) {
+            isAllCached = false;
+            break;
+          } else {
+            schemaTree.mergeSchemaTree(cachedSchema);
+          }
+        }
+      } finally {
+        schemaCache.releaseReadLock();
+      }
+      if (isAllCached) {
+        SchemaPartition schemaPartition = partitionFetcher.getSchemaPartition(patternTree);
+        schemaTree.setStorageGroups(
+            new ArrayList<>(schemaPartition.getSchemaPartitionMap().keySet()));
+        return schemaTree;
+      }
     }
-    return executeSchemaFetchQuery(new SchemaFetchStatement(patternTree, templateMap, withTags));
+
+    schemaTree =
+        executeSchemaFetchQuery(new SchemaFetchStatement(patternTree, templateMap, withTags));
+
+    schemaCache.takeReadLock();

Review Comment:
   write lock?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org