You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by hx...@apache.org on 2021/01/29 13:57:30 UTC

[iotdb] branch master updated: [IOTDB-1137] MNode.getLeafCount error when existing sub-device (#2602)

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

hxd pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git


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

commit 04b098232ab3410484bfadc19f844be30de0b5ee
Author: Zesong Sun <sz...@mails.tsinghua.edu.cn>
AuthorDate: Fri Jan 29 21:57:03 2021 +0800

    [IOTDB-1137] MNode.getLeafCount error when existing sub-device (#2602)
---
 .../org/apache/iotdb/db/metadata/MManager.java     |  2 +-
 .../org/apache/iotdb/db/metadata/mnode/MNode.java  | 27 ++++++++++--------
 .../org/apache/iotdb/db/metadata/MTreeTest.java    | 33 +++++++++++++++++++++-
 3 files changed, 48 insertions(+), 14 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 4482a58..cc3c285 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
@@ -232,7 +232,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 d9c11d1..c670200 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
@@ -18,11 +18,6 @@
  */
 package org.apache.iotdb.db.metadata.mnode;
 
-import org.apache.iotdb.db.conf.IoTDBConstant;
-import org.apache.iotdb.db.metadata.PartialPath;
-import org.apache.iotdb.db.metadata.logfile.MLogWriter;
-import org.apache.iotdb.db.rescon.CachedStringPool;
-
 import java.io.IOException;
 import java.io.Serializable;
 import java.util.ArrayList;
@@ -32,6 +27,10 @@ import java.util.Map;
 import java.util.Map.Entry;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
+import org.apache.iotdb.db.conf.IoTDBConstant;
+import org.apache.iotdb.db.metadata.PartialPath;
+import org.apache.iotdb.db.metadata.logfile.MLogWriter;
+import org.apache.iotdb.db.rescon.CachedStringPool;
 
 /**
  * This class is the implementation of Metadata Node. One MNode instance represents one node in the
@@ -85,7 +84,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 +138,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 e2a9d5d..e84b573 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
@@ -29,6 +29,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;
@@ -190,7 +191,8 @@ public class MTreeTest {
       assertEquals("root.a.d1.s0", result2.get(1).getFullPath());
       assertFalse(result2.get(1).isMeasurementAliasExists());
 
-      result2 = root.getAllTimeseriesPathWithAlias(new PartialPath("root.a.*.temperature"), 0, 0).left;
+      result2 = root
+          .getAllTimeseriesPathWithAlias(new PartialPath("root.a.*.temperature"), 0, 0).left;
       assertEquals(2, result2.size());
       assertEquals("root.a.d0.temperature", result2.get(0).getFullPathWithAlias());
       assertEquals("root.a.d1.temperature", result2.get(1).getFullPathWithAlias());
@@ -527,4 +529,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());
+    }
+  }
 }