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 d637989 add check SG for MManager, MGraph and MTree (#114)
d637989 is described below
commit d63798951eab4425b30cb622052bf1eea1f86132
Author: DongFang Mao <[email protected]>
AuthorDate: Wed Mar 27 19:15:04 2019 +0800
add check SG for MManager, MGraph and MTree (#114)
---
.../java/org/apache/iotdb/db/metadata/MGraph.java | 9 +++++++
.../org/apache/iotdb/db/metadata/MManager.java | 12 ++++++++++
.../java/org/apache/iotdb/db/metadata/MTree.java | 28 ++++++++++++++++++++++
.../iotdb/db/metadata/MManagerBasicTest.java | 26 ++++++++++++++++++++
.../org/apache/iotdb/db/metadata/MTreeTest.java | 24 +++++++++++++++++++
5 files changed, 99 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 1de292f..14c94fb 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
@@ -145,6 +145,15 @@ 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)*
+ */
+ public boolean checkStorageLevel(String path) {
+ return mtree.checkStorageGroup(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 1788010..c3f07c6 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
@@ -342,6 +342,18 @@ public class MManager {
}
/**
+ * function for checking if the given path is storage level of mTree or not.
+ */
+ public boolean checkStorageLevelOfMTree(String path) {
+ lock.readLock().lock();
+ try {
+ return mgraph.checkStorageLevel(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 76c284e..2668619 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
@@ -213,6 +213,34 @@ 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
+ */
+ public boolean checkStorageGroup(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 || temp.isStorageLevel()) {
+ return false;
+ }
+ cur = cur.getChild(nodeNames[i]);
+ i++;
+ }
+ MNode temp = cur.getChild(nodeNames[i]);
+ if (temp == null || !temp.isStorageLevel()) {
+ return false;
+ } else {
+ return true;
+ }
+ }
+
+ /**
* 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 dbd619e..1316bd3 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
@@ -261,4 +261,30 @@ public class MManagerBasicTest {
fail(e.getMessage());
}
}
+
+ @Test
+ public void testSetStorageLevelAndExist() {
+
+ MManager manager = MManager.getInstance();
+
+ try {
+ assertEquals(false, manager.checkStorageLevelOfMTree("root"));
+ assertEquals(false, manager.checkStorageLevelOfMTree("root1.laptop.d2"));
+
+ manager.setStorageLevelToMTree("root.laptop.d1");
+ assertEquals(true, manager.checkStorageLevelOfMTree("root.laptop.d1"));
+ assertEquals(false, manager.checkStorageLevelOfMTree("root.laptop.d2"));
+ assertEquals(false, manager.checkStorageLevelOfMTree("root.laptop"));
+ assertEquals(false,
manager.checkStorageLevelOfMTree("root.laptop.d1.s1"));
+
+ manager.setStorageLevelToMTree("root.laptop.d2");
+ assertEquals(true, manager.checkStorageLevelOfMTree("root.laptop.d1"));
+ assertEquals(true, manager.checkStorageLevelOfMTree("root.laptop.d2"));
+ assertEquals(false, manager.checkStorageLevelOfMTree("root.laptop.d3"));
+ assertEquals(false, manager.checkStorageLevelOfMTree("root.laptop"));
+ } 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 fdd6f47..e4bed25 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
@@ -189,4 +189,28 @@ public class MTreeTest {
assertEquals(root.isPathExist("root.laptop.d2"), true);
assertEquals(root.isPathExist("root.laptop.d2.s0"), true);
}
+
+ @Test
+ public void testCheckStorageGroup() {
+ // set storage group first
+ MTree root = new MTree("root");
+ try {
+ assertEquals(false, root.checkStorageGroup("root"));
+ assertEquals(false, root.checkStorageGroup("root1.laptop.d2"));
+
+ root.setStorageGroup("root.laptop.d1");
+ assertEquals(true, root.checkStorageGroup("root.laptop.d1"));
+ assertEquals(false, root.checkStorageGroup("root.laptop.d2"));
+ assertEquals(false, root.checkStorageGroup("root.laptop"));
+ assertEquals(false, root.checkStorageGroup("root.laptop.d1.s1"));
+
+ root.setStorageGroup("root.laptop.d2");
+ assertEquals(true, root.checkStorageGroup("root.laptop.d1"));
+ assertEquals(true, root.checkStorageGroup("root.laptop.d2"));
+ assertEquals(false, root.checkStorageGroup("root.laptop.d3"));
+ } catch (PathErrorException e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ }
}