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


##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/mtree/impl/pbtree/mnode/container/CachedMNodeContainer.java:
##########
@@ -425,6 +426,23 @@ private boolean changeStatus() {
     }
   }
 
+  private class BufferIterator extends MergeSortIterator<ICachedMNode> {
+
+    BufferIterator() {
+      super(
+          getNewChildBuffer().getMNodeChildBufferIterator(),
+          getUpdatedChildBuffer().getMNodeChildBufferIterator());
+    }
+
+    protected int decide() {
+      return 0;

Review Comment:
   Replace this with ```throw new IlegalStateException("There shall not exist 
two node with the same name separately in newChildBuffer and 
updateChildBuffer")```



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/mtree/impl/pbtree/CachedMTreeStore.java:
##########
@@ -785,5 +711,45 @@ public void close() {
         }
       }
     }
+
+    private class CachedMNodeMergeIterator extends 
MergeSortIterator<ICachedMNode> {
+
+      public CachedMNodeMergeIterator(
+          Iterator<ICachedMNode> leftIterator, Iterator<ICachedMNode> 
rightIterator) {

Review Comment:
   Rename the parameters to bufferIterator and diskIterator



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/mtree/impl/pbtree/CachedMTreeStore.java:
##########
@@ -714,53 +712,46 @@ public ICachedMNode next() {
       return result;
     }
 
-    private void readNext() throws MetadataException {
-      ICachedMNode node = null;
-      if (isIteratingDisk) {
-        ICachedMNodeContainer container = 
ICachedMNodeContainer.getCachedMNodeContainer(parent);
-        if (iterator.hasNext()) {
-          node = iterator.next();
-          while (container.hasChildInBuffer(node.getName())) {
-            if (iterator.hasNext()) {
-              node = iterator.next();
-            } else {
-              node = null;
-              break;
-            }
-          }
-        }
-        if (node != null) {
-          ICachedMNode nodeInMem = parent.getChild(node.getName());
-          if (nodeInMem != null) {
-            // this branch means the node load from disk is in cache, thus use 
the instance in
-            // cache
-            try {
-              memoryManager.updateCacheStatusAfterMemoryRead(nodeInMem);
-              node = nodeInMem;
-            } catch (MNodeNotCachedException e) {
-              node = loadChildFromDiskToParent(parent, node);
-            }
-          } else {
-            node = loadChildFromDiskToParent(parent, node);
-          }
-          nextNode = node;
-          return;
-        } else {
-          startIteratingBuffer();
+    private void catchDiskMNode() {
+      nextNode = diskHeader;
+      diskHeader = diskIterator.hasNext() ? diskIterator.next() : null;
+      ICachedMNode nodeInMem = parent.getChild(nextNode.getName());
+      if (nodeInMem != null) {
+        try {
+          memoryManager.updateCacheStatusAfterMemoryRead(nodeInMem);
+          nextNode = nodeInMem;
+        } catch (MNodeNotCachedException e) {
+          nextNode = loadChildFromDiskToParent(parent, nextNode);
         }
+      } else {
+        nextNode = loadChildFromDiskToParent(parent, nextNode);
       }
+    }
 
-      if (iterator.hasNext()) {
-        node = iterator.next();
-        // node in buffer won't be evicted during Iteration
-        memoryManager.updateCacheStatusAfterMemoryRead(node);
-      }
-      nextNode = node;
+    private void catchBufferMNode() throws MNodeNotCachedException {
+      nextNode = bufferHeader;
+      memoryManager.updateCacheStatusAfterMemoryRead(nextNode);
+      bufferHeader = bufferIterator.hasNext() ? bufferIterator.next() : null;
     }
 
-    private void startIteratingBuffer() {
-      iterator = bufferIterator;
-      isIteratingDisk = false;
+    private void readNext() throws MetadataException {
+
+      if (diskHeader != null && bufferHeader != null) { // 内存磁盘都有

Review Comment:
   In English.



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/mtree/impl/pbtree/CachedMTreeStore.java:
##########
@@ -771,9 +698,8 @@ public void skipTemplateChildren() {
     @Override
     public void close() {
       try {
-        if (nextNode != null) {
-          unPin(nextNode, false);
-          nextNode = null;
+        if (mergeIterator.hasNext()) {
+          unPin(mergeIterator.next(), false);

Review Comment:
   Since there's no buffered result in this mergeIterator, close it directly 
without reading the next element.



-- 
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-unsubscr...@iotdb.apache.org

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

Reply via email to