qiaojialin commented on a change in pull request #1345:
URL: https://github.com/apache/incubator-iotdb/pull/1345#discussion_r440689990



##########
File path: server/src/main/java/org/apache/iotdb/db/metadata/mnode/MNode.java
##########
@@ -56,37 +69,85 @@ public MNode(MNode parent, String name) {
   /**
    * check whether the MNode has a child with the name
    */
-  public abstract boolean hasChild(String name);
+  public boolean hasChild(String name) {
+    return (children != null && children.containsKey(name)) ||
+        (aliasChildren != null && aliasChildren.containsKey(name));
+  }
 
   /**
    * node key, name or alias
    */
-  public abstract void addChild(String name, MNode child);
+  public void addChild(String name, MNode child) {
+    if (children == null) {
+      children = new LinkedHashMap<>();
+    }
+    children.put(name, child);
+  }
 
   /**
-   * delete a child
+   * If delete a leafMNode, lock its parent, if delete an InternalNode, lock 
itself
    */
-  public abstract void deleteChild(String name) throws DeleteFailedException;
+  public void deleteChild(String name) throws DeleteFailedException {
+    if (children != null && children.containsKey(name)) {
+      // acquire the write lock of its child node.
+      Lock writeLock = (children.get(name)).lock.writeLock();
+      if (writeLock.tryLock()) {
+        children.remove(name);
+        writeLock.unlock();
+      } else {
+        throw new DeleteFailedException(getFullPath() + PATH_SEPARATOR + name);
+      }
+    }
+  }
 
   /**
    * delete the alias of a child
    */
-  public abstract void deleteAliasChild(String alias) throws 
DeleteFailedException;
+  public void deleteAliasChild(String alias) throws DeleteFailedException {
+    if (aliasChildren == null) {
+      return;
+    }
+    if (lock.writeLock().tryLock()) {
+      aliasChildren.remove(alias);
+      lock.writeLock().unlock();
+    } else {
+      throw new DeleteFailedException(getFullPath() + PATH_SEPARATOR + alias);
+    }
+  }
 
   /**
    * get the child with the name
    */
-  public abstract MNode getChild(String name);
+  public MNode getChild(String name) {
+    if (children != null && children.containsKey(name)) {
+      return children.get(name);
+    }

Review comment:
       MNode child = null;
   if (children != null) {
       child = children.get(name);
   }
   if (child != null) {
       return child;
   }




----------------------------------------------------------------
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:
[email protected]


Reply via email to