zookeeper-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lvfangmin <...@git.apache.org>
Subject [GitHub] zookeeper pull request #628: ZOOKEEPER-3140: Allow Followers to host Observe...
Date Fri, 21 Sep 2018 18:16:31 GMT
Github user lvfangmin commented on a diff in the pull request:

    https://github.com/apache/zookeeper/pull/628#discussion_r219583415
  
    --- Diff: src/java/main/org/apache/zookeeper/server/quorum/QuorumPeer.java ---
    @@ -1920,7 +1937,75 @@ private void updateRemotePeerMXBeans(Map<Long, QuorumServer>
newMembers) {
             }
         }
     
    -   private boolean updateLearnerType(QuorumVerifier newQV) {        
    +    private ArrayList<QuorumServer> observerMasters = new ArrayList<>();
    +    private void updateObserverMasterList() {
    +        if (observerMasterPort <= 0) {
    +            return; // observer masters not enabled
    +        }
    +        observerMasters.clear();
    +        StringBuilder sb = new StringBuilder();
    +        for (QuorumServer server : quorumVerifier.getVotingMembers().values()) {
    +            InetSocketAddress addr = new InetSocketAddress(server.addr.getAddress(),
observerMasterPort);
    +            observerMasters.add(new QuorumServer(server.id, addr));
    +            sb.append(addr).append(",");
    +        }
    +        LOG.info("Updated learner master list to be {}", sb.toString());
    +        Collections.shuffle(observerMasters);
    +    }
    +
    +    private boolean useObserverMasters() {
    +        return getLearnerType() == LearnerType.OBSERVER && observerMasters.size()
> 0;
    +    }
    +
    +    private int nextObserverMaster = 0;
    +    private QuorumServer nextObserverMaster() {
    +        if (nextObserverMaster >= observerMasters.size()) {
    +            nextObserverMaster = 0;
    +        }
    +        return observerMasters.get(nextObserverMaster++);
    +    }
    +
    +    QuorumServer findLearnerMaster(QuorumServer leader) {
    +        return useObserverMasters() ? nextObserverMaster() : leader;
    +    }
    +
    +
    --- End diff --
    
    Remove extra empty line here.


---

Mime
View raw message