You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by qi...@apache.org on 2021/01/07 09:56:17 UTC

[iotdb] branch master updated: fix delete timeseries bug (#2441)

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

qiaojialin 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 f24f469  fix delete timeseries bug (#2441)
f24f469 is described below

commit f24f469886caaead2606b2147524aaad1d3cad27
Author: Jackie Tien <Ja...@foxmail.com>
AuthorDate: Thu Jan 7 17:55:52 2021 +0800

    fix delete timeseries bug (#2441)
---
 .../java/org/apache/iotdb/db/metadata/MTree.java   |  4 ++--
 .../org/apache/iotdb/db/metadata/MTreeTest.java    | 23 ++++++++++++++++++++++
 2 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/server/src/main/java/org/apache/iotdb/db/metadata/MTree.java b/server/src/main/java/org/apache/iotdb/db/metadata/MTree.java
index a0e62f2..054bff9 100644
--- a/server/src/main/java/org/apache/iotdb/db/metadata/MTree.java
+++ b/server/src/main/java/org/apache/iotdb/db/metadata/MTree.java
@@ -411,9 +411,9 @@ public class MTree implements Serializable {
       curNode.getParent().deleteAliasChild(((MeasurementMNode) curNode).getAlias());
     }
     curNode = curNode.getParent();
-    // delete all empty ancestors except storage group
+    // delete all empty ancestors except storage group and MeasurementMNode
     while (!IoTDBConstant.PATH_ROOT.equals(curNode.getName())
-        && curNode.getChildren().size() == 0) {
+        && !(curNode instanceof MeasurementMNode) && curNode.getChildren().size() == 0) {
       // if current storage group has no time series, return the storage group name
       if (curNode instanceof StorageGroupMNode) {
         return new Pair<>(curNode.getPartialPath(), deletedNode);
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 d5b1795..e2a9d5d 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
@@ -504,4 +504,27 @@ public class MTreeTest {
     assertEquals(root.searchAllRelatedStorageGroups(new PartialPath("root.vehicle.d1.s1")),
         Collections.singletonList(new PartialPath(sgPath1)));
   }
+
+  @Test
+  public void testDeleteChildOfMeasurementMNode() throws MetadataException {
+    MTree root = new MTree();
+    String sgPath = "root.sg1";
+    root.setStorageGroup(new PartialPath(sgPath));
+    try {
+      root.createTimeseries(new PartialPath("root.sg1.a.b"), TSDataType.INT32, TSEncoding.RLE,
+          TSFileDescriptor.getInstance().getConfig().getCompressor(), Collections.emptyMap(), null);
+      root.createTimeseries(new PartialPath("root.sg1.a.b.c"), TSDataType.INT32, TSEncoding.RLE,
+          TSFileDescriptor.getInstance().getConfig().getCompressor(), Collections.emptyMap(), null);
+      assertTrue(root.isPathExist(new PartialPath("root.sg1.a.b")));
+      assertTrue(root.isPathExist(new PartialPath("root.sg1.a.b.c")));
+
+      root.deleteTimeseriesAndReturnEmptyStorageGroup(new PartialPath("root.sg1.a.b.c"));
+
+      assertFalse(root.isPathExist(new PartialPath("root.sg1.a.b.c")));
+      assertTrue(root.isPathExist(new PartialPath("root.sg1.a.b")));
+
+    } catch (MetadataException e1) {
+      fail(e1.getMessage());
+    }
+  }
 }