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

    https://github.com/apache/zookeeper/pull/92#discussion_r90764675
  
    --- Diff: src/java/main/org/apache/zookeeper/server/quorum/QuorumPeer.java 
---
    @@ -1390,24 +1406,29 @@ public QuorumVerifier configFromString(String s) 
throws IOException, ConfigExcep
         }
         
         /**
    -     * Return QuorumVerifier object for the last committed configuration
    +     * Return QuorumVerifier object for the last committed configuration.
          */
    -
    -    public synchronized QuorumVerifier getQuorumVerifier(){
    -        return quorumVerifier;
    -
    +    public QuorumVerifier getQuorumVerifier(){
    +        synchronized (qvLock) {
    +            return quorumVerifier;
    +        }
         }
     
    -    public synchronized QuorumVerifier getLastSeenQuorumVerifier(){
    -        return lastSeenQuorumVerifier;        
    +    /**
    +     * Return QuorumVerifier object for the last proposed configuration.
    +     */
    +    public QuorumVerifier getLastSeenQuorumVerifier(){
    +        synchronized (qvLock) {
    +            return lastSeenQuorumVerifier;
    +        }
         }
         
    -    public synchronized void connectNewPeers(){
    -       if (qcm!=null && getQuorumVerifier()!=null && 
getLastSeenQuorumVerifier()!=null) {
    -           Map<Long, QuorumServer> committedView = 
getQuorumVerifier().getAllMembers();
    -           for (Entry<Long, QuorumServer> e: 
getLastSeenQuorumVerifier().getAllMembers().entrySet()){
    +    private void connectNewPeers(){
    --- End diff --
    
    Hi @hanm, I've followed the long discussion on the Jira, thanks for digging 
deeper into the problem. LGTM, only a small suggestion: it's error-prone to 
assume that in the future this method won't be called by other non-synchronized 
methods, we'd better to add the synchronize(qvLock) here too.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to