zookeeper-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] asfgit closed pull request #722: [ZOOKEEPER-3203] Tracking the number of non voting followers in ZK
Date Mon, 07 Jan 2019 13:56:24 GMT
asfgit closed pull request #722: [ZOOKEEPER-3203] Tracking the number of non voting followers
in ZK
URL: https://github.com/apache/zookeeper/pull/722
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/zookeeper-server/src/main/java/org/apache/zookeeper/server/admin/Commands.java
b/zookeeper-server/src/main/java/org/apache/zookeeper/server/admin/Commands.java
index 29e18456a8..f1e5500563 100644
--- a/zookeeper-server/src/main/java/org/apache/zookeeper/server/admin/Commands.java
+++ b/zookeeper-server/src/main/java/org/apache/zookeeper/server/admin/Commands.java
@@ -369,6 +369,7 @@ public CommandResponse run(ZooKeeperServer zkServer, Map<String, String>
kwargs)
 
                 response.put("learners", leader.getLearners().size());
                 response.put("synced_followers", leader.getForwardingFollowers().size());
+                response.put("synced_non_voting_followers", leader.getNonVotingFollowers().size());
                 response.put("synced_observers", leader.getObservingLearners().size());
                 response.put("pending_syncs", leader.getNumPendingSyncs());
                 response.put("leader_uptime", leader.getUptime());
diff --git a/zookeeper-server/src/main/java/org/apache/zookeeper/server/command/MonitorCommand.java
b/zookeeper-server/src/main/java/org/apache/zookeeper/server/command/MonitorCommand.java
index b89d557473..75d1dea655 100644
--- a/zookeeper-server/src/main/java/org/apache/zookeeper/server/command/MonitorCommand.java
+++ b/zookeeper-server/src/main/java/org/apache/zookeeper/server/command/MonitorCommand.java
@@ -73,6 +73,7 @@ public void commandRun() {
 
             print("learners", leader.getLearners().size());
             print("synced_followers", leader.getForwardingFollowers().size());
+            print("synced_non_voting_followers", leader.getNonVotingFollowers().size());
             print("pending_syncs", leader.getNumPendingSyncs());
 
             print("last_proposal_size", leader.getProposalStats().getLastBufferSize());
diff --git a/zookeeper-server/src/main/java/org/apache/zookeeper/server/quorum/Leader.java
b/zookeeper-server/src/main/java/org/apache/zookeeper/server/quorum/Leader.java
index 397ea6d4e8..c284debfc4 100644
--- a/zookeeper-server/src/main/java/org/apache/zookeeper/server/quorum/Leader.java
+++ b/zookeeper-server/src/main/java/org/apache/zookeeper/server/quorum/Leader.java
@@ -152,7 +152,19 @@ public LearnerSnapshotThrottler createLearnerSnapshotThrottler(
         }
     }
 
-    private void addForwardingFollower(LearnerHandler lh) {
+    public List<LearnerHandler> getNonVotingFollowers() {
+        List<LearnerHandler> nonVotingFollowers = new ArrayList<LearnerHandler>();
+        synchronized (forwardingFollowers) {
+            for (LearnerHandler lh : forwardingFollowers) {
+                if (!isParticipant(lh.getSid())) {
+                    nonVotingFollowers.add(lh);
+                }
+            }
+        }
+        return nonVotingFollowers;
+    }
+
+    void addForwardingFollower(LearnerHandler lh) {
         synchronized (forwardingFollowers) {
             forwardingFollowers.add(lh);
         }
diff --git a/zookeeper-server/src/main/java/org/apache/zookeeper/server/quorum/LeaderBean.java
b/zookeeper-server/src/main/java/org/apache/zookeeper/server/quorum/LeaderBean.java
index 0c3be4a252..1c178f6bd9 100644
--- a/zookeeper-server/src/main/java/org/apache/zookeeper/server/quorum/LeaderBean.java
+++ b/zookeeper-server/src/main/java/org/apache/zookeeper/server/quorum/LeaderBean.java
@@ -51,6 +51,15 @@ public String followerInfo() {
         return sb.toString();
     }
 
+    @Override
+    public String nonVotingFollowerInfo() {
+        StringBuilder sb = new StringBuilder();
+        for (LearnerHandler handler : leader.getNonVotingFollowers()) {
+            sb.append(handler.toString()).append("\n");
+        }
+        return sb.toString();
+    }
+
     @Override
     public long getElectionTimeTaken() {
         return leader.self.getElectionTimeTaken();
diff --git a/zookeeper-server/src/main/java/org/apache/zookeeper/server/quorum/LeaderMXBean.java
b/zookeeper-server/src/main/java/org/apache/zookeeper/server/quorum/LeaderMXBean.java
index 7a1a439fa0..4aed18608d 100644
--- a/zookeeper-server/src/main/java/org/apache/zookeeper/server/quorum/LeaderMXBean.java
+++ b/zookeeper-server/src/main/java/org/apache/zookeeper/server/quorum/LeaderMXBean.java
@@ -34,6 +34,11 @@
      */
     public String followerInfo();
 
+    /**
+     * @return information about current non-voting followers
+     */
+    public String nonVotingFollowerInfo();
+
     /**
      * @return time taken for leader election in milliseconds.
      */
diff --git a/zookeeper-server/src/test/java/org/apache/zookeeper/server/quorum/LeaderBeanTest.java
b/zookeeper-server/src/test/java/org/apache/zookeeper/server/quorum/LeaderBeanTest.java
index 69dac1ff18..38539b3f88 100644
--- a/zookeeper-server/src/test/java/org/apache/zookeeper/server/quorum/LeaderBeanTest.java
+++ b/zookeeper-server/src/test/java/org/apache/zookeeper/server/quorum/LeaderBeanTest.java
@@ -45,6 +45,7 @@
 import java.util.Map;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.assertNotEquals;
 import static org.mockito.Matchers.any;
 import static org.mockito.Matchers.anyString;
@@ -58,6 +59,7 @@
     private FileTxnSnapLog fileTxnSnapLog;
     private LeaderZooKeeperServer zks;
     private QuorumPeer qp;
+    private QuorumVerifier quorumVerifierMock;
 
     @Before
     public void setUp() throws IOException, X509Exception {
@@ -73,7 +75,7 @@ public void setUp() throws IOException, X509Exception {
                         new InetSocketAddress(clientIP, PortAssignment.unique()),
                         new InetSocketAddress(clientIP, clientPort), LearnerType.PARTICIPANT));
 
-        QuorumVerifier quorumVerifierMock = mock(QuorumVerifier.class);
+        quorumVerifierMock = mock(QuorumVerifier.class);
         when(quorumVerifierMock.getAllMembers()).thenReturn(peersView);
 
         qp.setQuorumVerifier(quorumVerifierMock, false);
@@ -173,12 +175,21 @@ public Object answer(InvocationOnMock invocation) throws Throwable {
 
     @Test
     public void testFollowerInfo() throws IOException {
+        Map<Long, QuorumServer> votingMembers = new HashMap<Long, QuorumServer>();
+        votingMembers.put(1L, null);
+        votingMembers.put(2L, null);
+        votingMembers.put(3L, null);
+        when(quorumVerifierMock.getVotingMembers()).thenReturn(votingMembers);
+
         LearnerHandler follower = mock(LearnerHandler.class);
         when(follower.getLearnerType()).thenReturn(LearnerType.PARTICIPANT);
         when(follower.toString()).thenReturn("1");
+        when(follower.getSid()).thenReturn(1L);
         leader.addLearnerHandler(follower);
+        leader.addForwardingFollower(follower);
 
         assertEquals("1\n", leaderBean.followerInfo());
+        assertEquals("", leaderBean.nonVotingFollowerInfo());
 
         LearnerHandler observer = mock(LearnerHandler.class);
         when(observer.getLearnerType()).thenReturn(LearnerType.OBSERVER);
@@ -186,5 +197,18 @@ public void testFollowerInfo() throws IOException {
         leader.addLearnerHandler(observer);
 
         assertEquals("1\n", leaderBean.followerInfo());
+        assertEquals("", leaderBean.nonVotingFollowerInfo());
+
+        LearnerHandler nonVotingFollower = mock(LearnerHandler.class);
+        when(nonVotingFollower.getLearnerType()).thenReturn(LearnerType.PARTICIPANT);
+        when(nonVotingFollower.toString()).thenReturn("5");
+        when(nonVotingFollower.getSid()).thenReturn(5L);
+        leader.addLearnerHandler(nonVotingFollower);
+        leader.addForwardingFollower(nonVotingFollower);
+
+        String followerInfo = leaderBean.followerInfo();
+        assertTrue(followerInfo.contains("1"));
+        assertTrue(followerInfo.contains("5"));
+        assertEquals("5\n", leaderBean.nonVotingFollowerInfo());
     }
 }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on 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