qiaojialin commented on a change in pull request #793: [IOTDB-274] Refactor 
MManager
URL: https://github.com/apache/incubator-iotdb/pull/793#discussion_r379294406
 
 

 ##########
 File path: server/src/main/java/org/apache/iotdb/db/metadata/MTree.java
 ##########
 @@ -50,131 +52,127 @@
 public class MTree implements Serializable {
 
   private static final long serialVersionUID = -4200394435237291964L;
-  private static final String PATH_SEPARATOR = "\\.";
-  private static final String NO_CHILD_ERROR = "Node [%s] doesn't have child 
named: [%s]";
-  private static final String NOT_LEAF_NODE = "is NOT the leaf node";
   private MNode root;
+  /**
+   * dummy node is used for the default param of traverse methods
+   */
+  private MNode dummyNode;
 
   MTree(String rootName) {
     this.root = new MNode(rootName, null, false);
+    this.dummyNode = new MNode("dummy", null, false);
   }
 
   /**
-   * function for adding timeseries.It should check whether seriesPath exists.
-   */
-  void addTimeseriesPath(String timeseriesPath, TSDataType dataType, 
TSEncoding encoding,
-      CompressionType compressor, Map<String, String> props) throws 
PathException {
-    String[] nodeNames = MetaUtils.getNodeNames(timeseriesPath, 
PATH_SEPARATOR);
+   * Add timeseries path
+   *
+   * @param path timeseries path
+   * @param dataType data type
+   * @param encoding encoding
+   * @param compressor compressor
+   * @param props props
+   */
+  void addPath(String path, TSDataType dataType, TSEncoding encoding,
+      CompressionType compressor, Map<String, String> props) throws 
MetadataException {
+    String[] nodeNames = MetaUtils.getNodeNames(path);
     if (nodeNames.length <= 1 || !nodeNames[0].equals(root.getName())) {
-      throw new MTreePathException("Timeseries", timeseriesPath);
+      throw new IllegalPathException(path);
     }
-    MNode cur = findLeafParent(nodeNames);
-    String levelPath = cur.getDataFileName();
+    MNode cur = getParent(nodeNames);
+    String storageGroupName = cur.getStorageGroupName();
 
     MNode leaf = new MNode(nodeNames[nodeNames.length - 1], cur, dataType, 
encoding, compressor);
     if (props != null && !props.isEmpty()) {
       leaf.getSchema().setProps(props);
     }
-    leaf.setDataFileName(levelPath);
+    leaf.setStorageGroupName(storageGroupName);
     if (cur.isLeaf()) {
-      throw new MTreePathException(timeseriesPath, "can't be created",
-          String.format("node [%s] is left node", cur.getName()));
+      throw new PathAlreadyExistException(cur.getFullPath());
     }
     cur.addChild(nodeNames[nodeNames.length - 1], leaf);
   }
 
   /**
-   * function for adding deviceId
+   * Add device to MTree. This is available IF and ONLY IF creating schema 
automatically is enabled
+   *
+   * @param deviceId device id
    */
-  MNode addDeviceId(String deviceId) throws PathException {
-    String[] nodeNames = MetaUtils.getNodeNames(deviceId, PATH_SEPARATOR);
+  MNode addDevice(String deviceId) throws MetadataException {
+    String[] nodeNames = MetaUtils.getNodeNames(deviceId);
     if (nodeNames.length <= 1 || !nodeNames[0].equals(root.getName())) {
-      throw new MTreePathException("Timeseries", deviceId);
+      throw new IllegalPathException(deviceId);
     }
-    MNode cur = getRoot();
+    MNode cur = root;
     for (int i = 1; i < nodeNames.length; i++) {
-      if (!cur.hasChild(nodeNames[i])) {
+      if (!cur.hasChildWithKey(nodeNames[i])) {
         cur.addChild(nodeNames[i], new MNode(nodeNames[i], cur, false));
       }
       cur = cur.getChild(nodeNames[i]);
     }
     return cur;
   }
 
-  private MNode findLeafParent(String[] nodeNames) throws PathException {
+  /**
+   * Get nodes parent
+   *
+   * @param nodeNames node names
+   */
+  private MNode getParent(String[] nodeNames) throws MetadataException {
 
 Review comment:
   I don't understant this method... This is not only a get function, it also 
changes the tree structure.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to