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 06:28:49 UTC

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

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


##########
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:
   The schema cache is implemented based on Caffeine which is thread safe. The readLock is added to ensure that the schema cache clean operation, taking writeLock,  executed by delete timesereis or deactivate template will be effective.



-- 
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