zookeeper-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [zookeeper] BELUGABEHR commented on issue #888: ZOOKEEPER-3347: Improve PathTrie Consistency
Date Fri, 12 Jul 2019 14:28:46 GMT
BELUGABEHR commented on issue #888: ZOOKEEPER-3347: Improve PathTrie Consistency
URL: https://github.com/apache/zookeeper/pull/888#issuecomment-510907700
 
 
   @anmolnar 
   
   
   You say it is a NO-OP, but that is very difficult for anyone to deduce just by looking
at the code.  Since the tree is synchronized within a node, as you mentioned, the state of
the tree could be changed between each of these calls by another thread.  I think it's safer
and, easier to understand, if the state of the tree can be locked, either at the root tree
level, or on sub-trees, not per-node.  For such a simple data structure, I think it's easier
to just lock the entire tree.  Then there are no questions about race conditions.
   
   Another nice thing about my approach is that to `addPath`, a thread must acquire only a
single lock.  In the current approach, the same lock must be acquired three times which can
be expensive.
   `
       // acquire lock
       if (parent.getChild(part) == null) {
           // acquire lock
           parent.addChild(part, new TrieNode(parent));
       }
       // acquire lock
       parent = parent.getChild(part);
   `
   
   Finally, I imagine that this is a WORM (write once, read many) data structure.  I'm not
sure how often new quota nodes are being created or deleted, but this structure will be read
by every READ operation.  I've implemented separate read/write locks so that many readers
can access the tree at the same time.  Currently, with the `synchronized` keyword, all threads,
even if they are all read-only, will block each other.

----------------------------------------------------------------
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


With regards,
Apache Git Services

Mime
View raw message