Github user eribeiro commented on a diff in the pull request:

    https://github.com/apache/zookeeper/pull/632#discussion_r224208545
  
    --- Diff: 
zookeeper-server/src/main/java/org/apache/zookeeper/server/DataTree.java ---
    @@ -154,6 +160,26 @@
     
         private final ReferenceCountedACLCache aclCache = new 
ReferenceCountedACLCache();
     
    +    // The maximum number of tree digests that we will keep in our history
    +    public static final int DIGEST_LOG_LIMIT = 1024;
    +
    +    // Dump digest every 128 txns, in hex it's 80, which will make it 
easier 
    +    // to align and compare between servers.
    +    public static final int DIGEST_LOG_INTERVAL = 128;
    +
    +    // If this is not null, we are actively looking for a target zxid that 
we
    +    // want to validate the digest for
    +    private ZxidDigest digestFromLoadedSnapshot;
    +
    +    // The digest associated with the highest zxid in the data tree.
    +    private volatile ZxidDigest lastProcessedZxidDigest;
    +
    +    // Will be notified when digest mismatch event triggered.
    +    private List<DigestWatcher> digestWatchers = new ArrayList<>();
    --- End diff --
    
    tip: when you are dealing with Observer pattern in Java where the list of 
observers can potentially change concurrently with the traversal of the list 
for notification this can lead to `ConcurrentModificationException`. It's 
better to use `CopyOnWriteArrayList` or `CopyOnWriteArraySet`, given some 
important constraints specified in the javadocs, because they guarantee that a 
traversal over the collection will never throw 
`ConcurrentModificationException`. 
    
    Besides that, it would be nice to use a `Set` instead of a `List` because 
then there's no risk of bloating the collection by adding duplicate observers. 
So, my suggestion would be to put:
    
    `private Set<DigestWatcher> digestWatchers = new CopyOnWriteArraySet<>();`


---

Reply via email to