You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by do...@apache.org on 2019/04/01 13:37:56 UTC

[incubator-iotdb] branch master updated: add check sg exists of path for cluster (#126)

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

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


The following commit(s) were added to refs/heads/master by this push:
     new 8e4b05b  add check sg exists of path for cluster (#126)
8e4b05b is described below

commit 8e4b05ba4503d509c5aa83b1a52cf980ad032667
Author: Tianan Li <li...@163.com>
AuthorDate: Mon Apr 1 21:37:52 2019 +0800

    add check sg exists of path for cluster (#126)
---
 .../java/org/apache/iotdb/db/metadata/MGraph.java  | 11 ++++++++
 .../org/apache/iotdb/db/metadata/MManager.java     | 14 +++++++++
 .../java/org/apache/iotdb/db/metadata/MTree.java   | 33 ++++++++++++++++++++++
 .../iotdb/db/metadata/MManagerBasicTest.java       | 28 ++++++++++++++++++
 .../org/apache/iotdb/db/metadata/MTreeTest.java    | 29 +++++++++++++++++++
 5 files changed, 115 insertions(+)

diff --git a/iotdb/src/main/java/org/apache/iotdb/db/metadata/MGraph.java b/iotdb/src/main/java/org/apache/iotdb/db/metadata/MGraph.java
index 14c94fb..8b2bfdc 100644
--- a/iotdb/src/main/java/org/apache/iotdb/db/metadata/MGraph.java
+++ b/iotdb/src/main/java/org/apache/iotdb/db/metadata/MGraph.java
@@ -148,12 +148,23 @@ public class MGraph implements Serializable {
    * Check whether the input path is storage level for current Metadata Tree or not.
    *
    * @param path Format: root.node.(node)*
+   * @apiNote :for cluster
    */
   public boolean checkStorageLevel(String path) {
     return mtree.checkStorageGroup(path);
   }
 
   /**
+   * Check whether the storage group of the input path exists or not
+   *
+   * @param path Format: root.node.(node)*
+   * @apiNote :for cluster
+   */
+  public boolean checkStorageExistOfPath(String path) {
+    return mtree.checkStorageExistOfPath(path);
+  }
+
+  /**
    * Get all paths for given seriesPath regular expression if given seriesPath belongs to MTree, or
    * get all linked seriesPath for given seriesPath if given seriesPath belongs to PTree Notice:
    * Regular expression in this method is formed by the amalgamation of seriesPath and the character
diff --git a/iotdb/src/main/java/org/apache/iotdb/db/metadata/MManager.java b/iotdb/src/main/java/org/apache/iotdb/db/metadata/MManager.java
index c3f07c6..7384695 100644
--- a/iotdb/src/main/java/org/apache/iotdb/db/metadata/MManager.java
+++ b/iotdb/src/main/java/org/apache/iotdb/db/metadata/MManager.java
@@ -343,6 +343,7 @@ public class MManager {
 
   /**
    * function for checking if the given path is storage level of mTree or not.
+   * @apiNote :for cluster
    */
   public boolean checkStorageLevelOfMTree(String path) {
     lock.readLock().lock();
@@ -354,6 +355,19 @@ public class MManager {
   }
 
   /**
+   * function for checking if the storage group of given path exists in mTree or not.
+   * @apiNote :for cluster
+   */
+  public boolean checkStorageExistOfPath(String path) {
+    lock.readLock().lock();
+    try {
+      return mgraph.checkStorageExistOfPath(path);
+    } finally {
+      lock.readLock().unlock();
+    }
+  }
+
+  /**
    * function for adding a pTree.
    */
   public void addAPTree(String ptreeRootName) throws IOException, MetadataArgsErrorException {
diff --git a/iotdb/src/main/java/org/apache/iotdb/db/metadata/MTree.java b/iotdb/src/main/java/org/apache/iotdb/db/metadata/MTree.java
index 2668619..5f65507 100644
--- a/iotdb/src/main/java/org/apache/iotdb/db/metadata/MTree.java
+++ b/iotdb/src/main/java/org/apache/iotdb/db/metadata/MTree.java
@@ -216,6 +216,7 @@ public class MTree implements Serializable {
    * check whether the input path is storage group or not
    * @param path input path
    * @return if it is storage group, return true. Else return false
+   * @apiNote :for cluster
    */
   public boolean checkStorageGroup(String path) {
     String[] nodeNames = path.split(DOUB_SEPARATOR);
@@ -241,6 +242,38 @@ public class MTree implements Serializable {
   }
 
   /**
+   * Check whether the storage group of the path exists or not
+   * @param path input path
+   * @return If it's storage group exists, return true. Else return false
+   * @apiNote :for cluster
+   */
+  public boolean checkStorageExistOfPath(String path) {
+    String[] nodeNames = path.split(DOUB_SEPARATOR);
+    MNode cur = root;
+    if (nodeNames.length <= 1 || !nodeNames[0].equals(root.getName())) {
+      return false;
+    }
+    int i = 1;
+    while (i < nodeNames.length - 1) {
+      MNode temp = cur.getChild(nodeNames[i]);
+      if (temp == null) {
+        return false;
+      }
+      if(temp.isStorageLevel()){
+        return true;
+      }
+      cur = cur.getChild(nodeNames[i]);
+      i++;
+    }
+    MNode temp = cur.getChild(nodeNames[i]);
+    if(temp != null && temp.isStorageLevel()) {
+      return true;
+    } else {
+      return false;
+    }
+  }
+
+  /**
    * Check whether set file seriesPath for this node or not. If not, throw an exception
    */
   private void checkStorageGroup(MNode node) throws PathErrorException {
diff --git a/iotdb/src/test/java/org/apache/iotdb/db/metadata/MManagerBasicTest.java b/iotdb/src/test/java/org/apache/iotdb/db/metadata/MManagerBasicTest.java
index 1316bd3..bbc41d2 100644
--- a/iotdb/src/test/java/org/apache/iotdb/db/metadata/MManagerBasicTest.java
+++ b/iotdb/src/test/java/org/apache/iotdb/db/metadata/MManagerBasicTest.java
@@ -287,4 +287,32 @@ public class MManagerBasicTest {
       fail(e.getMessage());
     }
   }
+
+  @Test
+  public void testCheckStorageExistOfPath() {
+    MManager manager = MManager.getInstance();
+
+    try {
+      assertEquals(false, manager.checkStorageExistOfPath("root"));
+      assertEquals(false, manager.checkStorageExistOfPath("root.vehicle"));
+      assertEquals(false, manager.checkStorageExistOfPath("root.vehicle.device"));
+      assertEquals(false, manager.checkStorageExistOfPath("root.vehicle.device.sensor"));
+
+      manager.setStorageLevelToMTree("root.vehicle");
+      assertEquals(true, manager.checkStorageExistOfPath("root.vehicle"));
+      assertEquals(true, manager.checkStorageExistOfPath("root.vehicle.device"));
+      assertEquals(true, manager.checkStorageExistOfPath("root.vehicle.device.sensor"));
+      assertEquals(false, manager.checkStorageExistOfPath("root.vehicle1"));
+      assertEquals(false, manager.checkStorageExistOfPath("root.vehicle1.device"));
+
+      manager.setStorageLevelToMTree("root.vehicle1.device");
+      assertEquals(false, manager.checkStorageExistOfPath("root.vehicle1.device1"));
+      assertEquals(false, manager.checkStorageExistOfPath("root.vehicle1.device2"));
+      assertEquals(false, manager.checkStorageExistOfPath("root.vehicle1.device3"));
+      assertEquals(true, manager.checkStorageExistOfPath("root.vehicle1.device"));
+    } catch (PathErrorException | IOException e) {
+      e.printStackTrace();
+      fail(e.getMessage());
+    }
+  }
 }
diff --git a/iotdb/src/test/java/org/apache/iotdb/db/metadata/MTreeTest.java b/iotdb/src/test/java/org/apache/iotdb/db/metadata/MTreeTest.java
index e4bed25..6f8ac94 100644
--- a/iotdb/src/test/java/org/apache/iotdb/db/metadata/MTreeTest.java
+++ b/iotdb/src/test/java/org/apache/iotdb/db/metadata/MTreeTest.java
@@ -213,4 +213,33 @@ public class MTreeTest {
       fail(e.getMessage());
     }
   }
+
+  @Test
+  public void testCheckStorageExistOfPath() {
+    // set storage group first
+    MTree root = new MTree("root");
+    try {
+      assertEquals(false, root.checkStorageExistOfPath("root"));
+      assertEquals(false, root.checkStorageExistOfPath("root.vehicle"));
+      assertEquals(false, root.checkStorageExistOfPath("root.vehicle.device"));
+      assertEquals(false, root.checkStorageExistOfPath("root.vehicle.device.sensor"));
+
+      root.setStorageGroup("root.vehicle");
+      assertEquals(true, root.checkStorageExistOfPath("root.vehicle"));
+      assertEquals(true, root.checkStorageExistOfPath("root.vehicle.device"));
+      assertEquals(true, root.checkStorageExistOfPath("root.vehicle.device.sensor"));
+      assertEquals(false, root.checkStorageExistOfPath("root.vehicle1"));
+      assertEquals(false, root.checkStorageExistOfPath("root.vehicle1.device"));
+
+      root.setStorageGroup("root.vehicle1.device");
+      assertEquals(false, root.checkStorageExistOfPath("root.vehicle1.device1"));
+      assertEquals(false, root.checkStorageExistOfPath("root.vehicle1.device2"));
+      assertEquals(false, root.checkStorageExistOfPath("root.vehicle1.device3"));
+      assertEquals(true, root.checkStorageExistOfPath("root.vehicle1.device"));
+    } catch (PathErrorException e) {
+      e.printStackTrace();
+      fail(e.getMessage());
+    }
+  }
+
 }