You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@iotdb.apache.org by GitBox <gi...@apache.org> on 2020/06/11 15:37:50 UTC

[GitHub] [incubator-iotdb] Alima777 commented on a change in pull request #1345: [IOTDB-759] Refactor MNode by removing InternalMNode

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



##########
File path: server/src/main/java/org/apache/iotdb/db/metadata/mnode/MNode.java
##########
@@ -44,49 +57,100 @@
    */
   protected String fullPath;
 
+  Map<String, MNode> children;
+  Map<String, MNode> aliasChildren;
+
+  protected ReadWriteLock lock = new ReentrantReadWriteLock();
 
   /**
    * Constructor of MNode.
    */
   public MNode(MNode parent, String name) {
     this.parent = parent;
     this.name = name;
+    this.children = new LinkedHashMap<>();
   }
 
   /**
    * check whether the MNode has a child with the name
    */
-  public abstract boolean hasChild(String name);
+  public boolean hasChild(String name) {
+    return this.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) {
+    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.containsKey(name)) {
+      Lock writeLock;
+      // if its child node is leaf node, we need to acquire the write lock of the current device node
+      if (children.get(name) instanceof MeasurementMNode) {
+        writeLock = lock.writeLock();
+      } else {
+        // otherwise, we only need to acquire the write lock of its child node.
+        writeLock = (children.get(name)).lock.writeLock();
+      }

Review comment:
       I'm not sure about this. Whether should we change the lock logic of this method? As the measurementNode maybe internalNode now.




----------------------------------------------------------------
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:
users@infra.apache.org