This is an automated email from the ASF dual-hosted git repository.

qiaojialin pushed a commit to branch rel/0.11
in repository https://gitbox.apache.org/repos/asf/iotdb.git


The following commit(s) were added to refs/heads/rel/0.11 by this push:
     new ea7a215  [IOTDB-1137] MNode.getLeafCount error when existing 
sub-device (#2606)
ea7a215 is described below

commit ea7a215274f9ad6228a9b7df4ca8f571798b4690
Author: Zesong Sun <[email protected]>
AuthorDate: Mon Feb 1 08:54:30 2021 +0800

    [IOTDB-1137] MNode.getLeafCount error when existing sub-device (#2606)
---
 .../org/apache/iotdb/db/metadata/MManager.java     |  2 +-
 .../org/apache/iotdb/db/metadata/mnode/MNode.java  | 20 +++++++++------
 .../org/apache/iotdb/db/metadata/MTreeTest.java    | 30 ++++++++++++++++++++++
 3 files changed, 43 insertions(+), 9 deletions(-)

diff --git a/server/src/main/java/org/apache/iotdb/db/metadata/MManager.java 
b/server/src/main/java/org/apache/iotdb/db/metadata/MManager.java
index 84bc60b..d526753 100644
--- a/server/src/main/java/org/apache/iotdb/db/metadata/MManager.java
+++ b/server/src/main/java/org/apache/iotdb/db/metadata/MManager.java
@@ -219,7 +219,7 @@ public class MManager {
       List<PartialPath> storageGroups = mtree.getAllStorageGroupPaths();
       for (PartialPath sg : storageGroups) {
         MNode node = mtree.getNodeByPath(sg);
-        totalSeriesNumber.addAndGet(node.getLeafCount());
+        totalSeriesNumber.addAndGet(node.getMeasurementMNodeCount());
       }
 
       logWriter = new MLogWriter(config.getSchemaDir(), 
MetadataConstant.METADATA_LOG);
diff --git a/server/src/main/java/org/apache/iotdb/db/metadata/mnode/MNode.java 
b/server/src/main/java/org/apache/iotdb/db/metadata/mnode/MNode.java
index f2939b6..980322a 100644
--- a/server/src/main/java/org/apache/iotdb/db/metadata/mnode/MNode.java
+++ b/server/src/main/java/org/apache/iotdb/db/metadata/mnode/MNode.java
@@ -21,8 +21,8 @@ package org.apache.iotdb.db.metadata.mnode;
 import java.io.BufferedWriter;
 import java.io.IOException;
 import java.io.Serializable;
-import java.util.Collections;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
@@ -85,7 +85,8 @@ public class MNode implements Serializable {
 
   /**
    * add a child to current mnode
-   * @param name child's name
+   *
+   * @param name  child's name
    * @param child child's node
    */
   public void addChild(String name, MNode child) {
@@ -138,17 +139,20 @@ public class MNode implements Serializable {
   }
 
   /**
-   * get the count of all leaves whose ancestor is current node
+   * get the count of all MeasurementMNode whose ancestor is current node
    */
-  public int getLeafCount() {
+  public int getMeasurementMNodeCount() {
     if (children == null) {
-      return 0;
+      return 1;
+    }
+    int measurementMNodeCount = 0;
+    if (this instanceof MeasurementMNode) {
+      measurementMNodeCount += 1; // current node itself may be 
MeasurementMNode
     }
-    int leafCount = 0;
     for (MNode child : children.values()) {
-      leafCount += child.getLeafCount();
+      measurementMNodeCount += child.getMeasurementMNodeCount();
     }
-    return leafCount;
+    return measurementMNodeCount;
   }
 
   /**
diff --git a/server/src/test/java/org/apache/iotdb/db/metadata/MTreeTest.java 
b/server/src/test/java/org/apache/iotdb/db/metadata/MTreeTest.java
index ae5c2bd..f3da317 100644
--- a/server/src/test/java/org/apache/iotdb/db/metadata/MTreeTest.java
+++ b/server/src/test/java/org/apache/iotdb/db/metadata/MTreeTest.java
@@ -31,6 +31,7 @@ import java.util.List;
 import org.apache.iotdb.db.exception.metadata.AliasAlreadyExistException;
 import org.apache.iotdb.db.exception.metadata.IllegalPathException;
 import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.metadata.mnode.MNode;
 import org.apache.iotdb.db.utils.EnvironmentUtils;
 import org.apache.iotdb.tsfile.common.conf.TSFileDescriptor;
 import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
@@ -523,4 +524,33 @@ public class MTreeTest {
       fail(e1.getMessage());
     }
   }
+
+  @Test
+  public void testGetMeasurementMNodeCount() throws MetadataException {
+    MTree root = new MTree();
+    PartialPath sgPath = new PartialPath("root.sg1");
+    root.setStorageGroup(sgPath);
+    try {
+      root.createTimeseries(new PartialPath("root.sg1.a.b"), TSDataType.INT32, 
TSEncoding.RLE,
+          TSFileDescriptor.getInstance().getConfig().getCompressor(), 
Collections.emptyMap(), null);
+      MNode sgNode = root.getNodeByPath(sgPath);
+      assertEquals(1, sgNode.getMeasurementMNodeCount()); // b
+
+      root.createTimeseries(new PartialPath("root.sg1.a.b.c"), 
TSDataType.INT32, TSEncoding.RLE,
+          TSFileDescriptor.getInstance().getConfig().getCompressor(), 
Collections.emptyMap(), null);
+      assertEquals(2, sgNode.getMeasurementMNodeCount()); // b and c
+      MNode cNode = sgNode.getChild("a").getChild("b").getChild("c");
+      assertEquals(1, cNode.getMeasurementMNodeCount()); // c
+
+      root.createTimeseries(new PartialPath("root.sg1.a.b.c.d"), 
TSDataType.INT32, TSEncoding.RLE,
+          TSFileDescriptor.getInstance().getConfig().getCompressor(), 
Collections.emptyMap(), null);
+      assertEquals(3, sgNode.getMeasurementMNodeCount()); // b, c and d
+      assertEquals(2, cNode.getMeasurementMNodeCount()); // c and d
+      MNode dNode = cNode.getChild("d");
+      assertEquals(1, dNode.getMeasurementMNodeCount()); // d
+
+    } catch (MetadataException e1) {
+      fail(e1.getMessage());
+    }
+  }
 }

Reply via email to