zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From an...@apache.org
Subject zookeeper git commit: ZOOKEEPER-3117: Correct the LeaderBean.followerInfo to only return the followers list
Date Fri, 17 Aug 2018 12:40:08 GMT
Repository: zookeeper
Updated Branches:
  refs/heads/master 2584625cd -> 290f1fc4b


ZOOKEEPER-3117: Correct the LeaderBean.followerInfo to only return the followers list

Author: Fangmin Lyu <allenlyu@fb.com>

Reviewers: andor@apache.org

Closes #595 from lvfangmin/ZOOKEEPER-3117


Project: http://git-wip-us.apache.org/repos/asf/zookeeper/repo
Commit: http://git-wip-us.apache.org/repos/asf/zookeeper/commit/290f1fc4
Tree: http://git-wip-us.apache.org/repos/asf/zookeeper/tree/290f1fc4
Diff: http://git-wip-us.apache.org/repos/asf/zookeeper/diff/290f1fc4

Branch: refs/heads/master
Commit: 290f1fc4b907c7d51ec81985e87ef46b8528b8f7
Parents: 2584625
Author: Fangmin Lyu <allenlyu@fb.com>
Authored: Fri Aug 17 14:40:02 2018 +0200
Committer: Andor Molnar <andor@apache.org>
Committed: Fri Aug 17 14:40:02 2018 +0200

----------------------------------------------------------------------
 .../apache/zookeeper/server/admin/Commands.java  |  2 +-
 .../zookeeper/server/command/MonitorCommand.java |  2 +-
 .../apache/zookeeper/server/quorum/Leader.java   |  2 +-
 .../zookeeper/server/quorum/LeaderBean.java      | 11 +++++++----
 .../zookeeper/server/quorum/LeaderBeanTest.java  | 19 +++++++++++++++++++
 5 files changed, 29 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zookeeper/blob/290f1fc4/src/java/main/org/apache/zookeeper/server/admin/Commands.java
----------------------------------------------------------------------
diff --git a/src/java/main/org/apache/zookeeper/server/admin/Commands.java b/src/java/main/org/apache/zookeeper/server/admin/Commands.java
index 4712261..e0c66a6 100644
--- a/src/java/main/org/apache/zookeeper/server/admin/Commands.java
+++ b/src/java/main/org/apache/zookeeper/server/admin/Commands.java
@@ -337,7 +337,7 @@ public class Commands {
             if (zkServer instanceof LeaderZooKeeperServer) {
                 Leader leader = ((LeaderZooKeeperServer) zkServer).getLeader();
 
-                response.put("followers", leader.getLearners().size());
+                response.put("learners", leader.getLearners().size());
                 response.put("synced_followers", leader.getForwardingFollowers().size());
                 response.put("pending_syncs", leader.getNumPendingSyncs());
 

http://git-wip-us.apache.org/repos/asf/zookeeper/blob/290f1fc4/src/java/main/org/apache/zookeeper/server/command/MonitorCommand.java
----------------------------------------------------------------------
diff --git a/src/java/main/org/apache/zookeeper/server/command/MonitorCommand.java b/src/java/main/org/apache/zookeeper/server/command/MonitorCommand.java
index a17fe40..9613c7c 100644
--- a/src/java/main/org/apache/zookeeper/server/command/MonitorCommand.java
+++ b/src/java/main/org/apache/zookeeper/server/command/MonitorCommand.java
@@ -71,7 +71,7 @@ public class MonitorCommand extends AbstractFourLetterCommand {
         if (stats.getServerState().equals("leader")) {
             Leader leader = ((LeaderZooKeeperServer)zkServer).getLeader();
 
-            print("followers", leader.getLearners().size());
+            print("learners", leader.getLearners().size());
             print("synced_followers", leader.getForwardingFollowers().size());
             print("pending_syncs", leader.getNumPendingSyncs());
 

http://git-wip-us.apache.org/repos/asf/zookeeper/blob/290f1fc4/src/java/main/org/apache/zookeeper/server/quorum/Leader.java
----------------------------------------------------------------------
diff --git a/src/java/main/org/apache/zookeeper/server/quorum/Leader.java b/src/java/main/org/apache/zookeeper/server/quorum/Leader.java
index 1d96165..190d98d 100644
--- a/src/java/main/org/apache/zookeeper/server/quorum/Leader.java
+++ b/src/java/main/org/apache/zookeeper/server/quorum/Leader.java
@@ -100,7 +100,7 @@ public class Leader {
     // the follower acceptor thread
     volatile LearnerCnxAcceptor cnxAcceptor = null;
 
-    // list of all the followers
+    // list of all the learners, including followers and observers
     private final HashSet<LearnerHandler> learners =
         new HashSet<LearnerHandler>();
 

http://git-wip-us.apache.org/repos/asf/zookeeper/blob/290f1fc4/src/java/main/org/apache/zookeeper/server/quorum/LeaderBean.java
----------------------------------------------------------------------
diff --git a/src/java/main/org/apache/zookeeper/server/quorum/LeaderBean.java b/src/java/main/org/apache/zookeeper/server/quorum/LeaderBean.java
index 4d4c856..0c3be4a 100644
--- a/src/java/main/org/apache/zookeeper/server/quorum/LeaderBean.java
+++ b/src/java/main/org/apache/zookeeper/server/quorum/LeaderBean.java
@@ -20,18 +20,19 @@ package org.apache.zookeeper.server.quorum;
 
 import org.apache.zookeeper.server.ZooKeeperServerBean;
 import org.apache.zookeeper.server.ZooKeeperServer;
+import org.apache.zookeeper.server.quorum.QuorumPeer.LearnerType;
 
 /**
  * Leader MBean interface implementation.
  */
 public class LeaderBean extends ZooKeeperServerBean implements LeaderMXBean {
     private final Leader leader;
-    
+
     public LeaderBean(Leader leader, ZooKeeperServer zks) {
         super(zks);
         this.leader = leader;
     }
-    
+
     public String getName() {
         return "Leader";
     }
@@ -39,11 +40,13 @@ public class LeaderBean extends ZooKeeperServerBean implements LeaderMXBean
{
     public String getCurrentZxid() {
         return "0x" + Long.toHexString(zks.getZxid());
     }
-    
+
     public String followerInfo() {
         StringBuilder sb = new StringBuilder();
         for (LearnerHandler handler : leader.getLearners()) {
-            sb.append(handler.toString()).append("\n");
+            if (handler.getLearnerType() == LearnerType.PARTICIPANT) {
+                sb.append(handler.toString()).append("\n");
+            }
         }
         return sb.toString();
     }

http://git-wip-us.apache.org/repos/asf/zookeeper/blob/290f1fc4/src/java/test/org/apache/zookeeper/server/quorum/LeaderBeanTest.java
----------------------------------------------------------------------
diff --git a/src/java/test/org/apache/zookeeper/server/quorum/LeaderBeanTest.java b/src/java/test/org/apache/zookeeper/server/quorum/LeaderBeanTest.java
index c30541c..b017551 100644
--- a/src/java/test/org/apache/zookeeper/server/quorum/LeaderBeanTest.java
+++ b/src/java/test/org/apache/zookeeper/server/quorum/LeaderBeanTest.java
@@ -24,6 +24,7 @@ import org.apache.zookeeper.server.Request;
 import org.apache.zookeeper.server.ZKDatabase;
 import org.apache.zookeeper.server.persistence.FileTxnSnapLog;
 import org.apache.zookeeper.server.quorum.flexible.QuorumVerifier;
+import org.apache.zookeeper.server.quorum.QuorumPeer.LearnerType;
 import org.apache.zookeeper.server.util.SerializeUtils;
 import org.apache.zookeeper.test.ClientBase;
 import org.apache.zookeeper.txn.TxnHeader;
@@ -42,6 +43,7 @@ import static org.mockito.Matchers.any;
 import static org.mockito.Matchers.anyString;
 import static org.mockito.Mockito.doAnswer;
 import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
 
 public class LeaderBeanTest {
     private Leader leader;
@@ -148,4 +150,21 @@ public class LeaderBeanTest {
         }).when(txn).serialize(any(OutputArchive.class), anyString());
         return new Request(1, 2, 3, header, txn, 4);
     }
+
+    @Test
+    public void testFollowerInfo() throws IOException {
+        LearnerHandler follower = mock(LearnerHandler.class);
+        when(follower.getLearnerType()).thenReturn(LearnerType.PARTICIPANT);
+        when(follower.toString()).thenReturn("1");
+        leader.addLearnerHandler(follower);
+
+        assertEquals("1\n", leaderBean.followerInfo());
+
+        LearnerHandler observer = mock(LearnerHandler.class);
+        when(observer.getLearnerType()).thenReturn(LearnerType.OBSERVER);
+        when(observer.toString()).thenReturn("2");
+        leader.addLearnerHandler(observer);
+
+        assertEquals("1\n", leaderBean.followerInfo());
+    }
 }


Mime
View raw message