zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From f..@apache.org
Subject zookeeper git commit: ZOOKEEPER-2479: Add 'electionTimeTaken' value in LeaderMXBean and FollowerMXBean
Date Tue, 20 Dec 2016 13:47:46 GMT
Repository: zookeeper
Updated Branches:
  refs/heads/branch-3.5 cb20fcbd5 -> fbf6fe1ad


ZOOKEEPER-2479: Add 'electionTimeTaken' value in LeaderMXBean and FollowerMXBean

Author: Rakesh Radhakrishnan <rakeshr@apache.org>

Reviewers: Edward Ribeiro <edward.ribeiro@gmail.com>, fpj <fpj@apache.org>

Closes #98 from rakeshadr/ZK-2479 and squashes the following commits:

2c9eadf [Rakesh Radhakrishnan] ZOOKEEPER-2479: avoids duplicate code
5af1314 [Rakesh Radhakrishnan] ZOOKEEPER-2479: Fixed Raul's review comments
cc011a0 [Rakesh Radhakrishnan] ZOOKEEPER-2479: Add 'electionTimeTaken' value in LeaderMXBean
and FollowerMXBean

(cherry picked from commit 8616a9ec8ce4bc8ac2987b7417a6f0c4b7333658)
Signed-off-by: fpj <fpj@apache.org>


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

Branch: refs/heads/branch-3.5
Commit: fbf6fe1ad9d1fcc632fa3fcb8f6b3740115d932b
Parents: cb20fcb
Author: Rakesh Radhakrishnan <rakeshr@apache.org>
Authored: Tue Dec 20 13:47:25 2016 +0000
Committer: fpj <fpj@apache.org>
Committed: Tue Dec 20 13:47:39 2016 +0000

----------------------------------------------------------------------
 .../zookeeper/server/quorum/Follower.java       |  6 ++--
 .../zookeeper/server/quorum/FollowerBean.java   |  7 ++++-
 .../zookeeper/server/quorum/FollowerMXBean.java |  5 +++
 .../apache/zookeeper/server/quorum/Leader.java  |  6 ++--
 .../zookeeper/server/quorum/LeaderBean.java     |  4 +++
 .../zookeeper/server/quorum/LeaderMXBean.java   |  5 +++
 .../zookeeper/server/quorum/QuorumPeer.java     | 22 +++++++++++++
 .../zookeeper/test/QuorumMajorityTest.java      | 33 +++++++++++++++++---
 8 files changed, 78 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zookeeper/blob/fbf6fe1a/src/java/main/org/apache/zookeeper/server/quorum/Follower.java
----------------------------------------------------------------------
diff --git a/src/java/main/org/apache/zookeeper/server/quorum/Follower.java b/src/java/main/org/apache/zookeeper/server/quorum/Follower.java
index d0f1a72..1cdc202 100644
--- a/src/java/main/org/apache/zookeeper/server/quorum/Follower.java
+++ b/src/java/main/org/apache/zookeeper/server/quorum/Follower.java
@@ -63,8 +63,10 @@ public class Follower extends Learner{
      */
     void followLeader() throws InterruptedException {
         self.end_fle = Time.currentElapsedTime();
-        LOG.info("FOLLOWING - LEADER ELECTION TOOK - " +
-              (self.end_fle - self.start_fle) + " " + QuorumPeer.FLE_TIME_UNIT);
+        long electionTimeTaken = self.end_fle - self.start_fle;
+        self.setElectionTimeTaken(electionTimeTaken);
+        LOG.info("FOLLOWING - LEADER ELECTION TOOK - {} {}", electionTimeTaken,
+                QuorumPeer.FLE_TIME_UNIT);
         self.start_fle = 0;
         self.end_fle = 0;
         fzk.registerJMX(new FollowerBean(this, zk), self.jmxLocalPeerBean);

http://git-wip-us.apache.org/repos/asf/zookeeper/blob/fbf6fe1a/src/java/main/org/apache/zookeeper/server/quorum/FollowerBean.java
----------------------------------------------------------------------
diff --git a/src/java/main/org/apache/zookeeper/server/quorum/FollowerBean.java b/src/java/main/org/apache/zookeeper/server/quorum/FollowerBean.java
index fd31fa2..8773ab8 100644
--- a/src/java/main/org/apache/zookeeper/server/quorum/FollowerBean.java
+++ b/src/java/main/org/apache/zookeeper/server/quorum/FollowerBean.java
@@ -22,7 +22,7 @@ import org.apache.zookeeper.server.ZooKeeperServer;
 import org.apache.zookeeper.server.ZooKeeperServerBean;
 
 /**
- * Follower MBean inteface implementation
+ * Follower MBean interface implementation
  */
 public class FollowerBean extends ZooKeeperServerBean implements FollowerMXBean {
     private final Follower follower;
@@ -47,4 +47,9 @@ public class FollowerBean extends ZooKeeperServerBean implements FollowerMXBean
     public int getPendingRevalidationCount() {
         return follower.getPendingRevalidationsCount();
     }
+
+    @Override
+    public long getElectionTimeTaken() {
+        return follower.self.getElectionTimeTaken();
+    }
 }

http://git-wip-us.apache.org/repos/asf/zookeeper/blob/fbf6fe1a/src/java/main/org/apache/zookeeper/server/quorum/FollowerMXBean.java
----------------------------------------------------------------------
diff --git a/src/java/main/org/apache/zookeeper/server/quorum/FollowerMXBean.java b/src/java/main/org/apache/zookeeper/server/quorum/FollowerMXBean.java
index ded0e1c..45c7fd8 100644
--- a/src/java/main/org/apache/zookeeper/server/quorum/FollowerMXBean.java
+++ b/src/java/main/org/apache/zookeeper/server/quorum/FollowerMXBean.java
@@ -38,4 +38,9 @@ public interface FollowerMXBean extends ZooKeeperServerMXBean {
      * @return count of pending revalidations
      */
     public int getPendingRevalidationCount();
+
+    /**
+     * @return time taken for leader election in milliseconds.
+     */
+    public long getElectionTimeTaken();
 }

http://git-wip-us.apache.org/repos/asf/zookeeper/blob/fbf6fe1a/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 db30114..7bec994 100644
--- a/src/java/main/org/apache/zookeeper/server/quorum/Leader.java
+++ b/src/java/main/org/apache/zookeeper/server/quorum/Leader.java
@@ -409,8 +409,10 @@ public class Leader {
      */
     void lead() throws IOException, InterruptedException {
         self.end_fle = Time.currentElapsedTime();
-        LOG.info("LEADING - LEADER ELECTION TOOK - " +
-              (self.end_fle - self.start_fle) + " " + QuorumPeer.FLE_TIME_UNIT);
+        long electionTimeTaken = self.end_fle - self.start_fle;
+        self.setElectionTimeTaken(electionTimeTaken);
+        LOG.info("LEADING - LEADER ELECTION TOOK - {} {}", electionTimeTaken,
+                QuorumPeer.FLE_TIME_UNIT);
         self.start_fle = 0;
         self.end_fle = 0;
 

http://git-wip-us.apache.org/repos/asf/zookeeper/blob/fbf6fe1a/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 b5a3a10..6ab2c30 100644
--- a/src/java/main/org/apache/zookeeper/server/quorum/LeaderBean.java
+++ b/src/java/main/org/apache/zookeeper/server/quorum/LeaderBean.java
@@ -50,4 +50,8 @@ public class LeaderBean extends ZooKeeperServerBean implements LeaderMXBean
{
         return sb.toString();
     }
 
+    @Override
+    public long getElectionTimeTaken() {
+        return leader.self.getElectionTimeTaken();
+    }
 }

http://git-wip-us.apache.org/repos/asf/zookeeper/blob/fbf6fe1a/src/java/main/org/apache/zookeeper/server/quorum/LeaderMXBean.java
----------------------------------------------------------------------
diff --git a/src/java/main/org/apache/zookeeper/server/quorum/LeaderMXBean.java b/src/java/main/org/apache/zookeeper/server/quorum/LeaderMXBean.java
index bf08104..66428a4 100644
--- a/src/java/main/org/apache/zookeeper/server/quorum/LeaderMXBean.java
+++ b/src/java/main/org/apache/zookeeper/server/quorum/LeaderMXBean.java
@@ -33,4 +33,9 @@ public interface LeaderMXBean extends ZooKeeperServerMXBean {
      * @return information on current followers
      */
     public String followerInfo();
+
+    /**
+     * @return time taken for leader election in milliseconds.
+     */
+    public long getElectionTimeTaken();
 }

http://git-wip-us.apache.org/repos/asf/zookeeper/blob/fbf6fe1a/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeer.java
----------------------------------------------------------------------
diff --git a/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeer.java b/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeer.java
index 68bef42..0274c9e 100644
--- a/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeer.java
+++ b/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeer.java
@@ -520,6 +520,12 @@ public class QuorumPeer extends ZooKeeperThread implements QuorumStats.Provider
     protected boolean quorumListenOnAllIPs = false;
 
     /**
+     * Keeps time taken for leader election in milliseconds. Sets the value to
+     * this variable only after the completion of leader election.
+     */
+    private long electionTimeTaken = -1;
+
+    /**
      * @deprecated As of release 3.4.0, this class has been deprecated, since
      * it is used with one of the udp-based versions of leader election, which
      * we are also deprecating.
@@ -1881,4 +1887,20 @@ public class QuorumPeer extends ZooKeeperThread implements QuorumStats.Provider
         String secure = secureCnxnFactory != null ? secureCnxnFactory.getLocalAddress().toString()
: "disabled";
         setName(String.format("QuorumPeer[myid=%d](plain=%s)(secure=%s)", getId(), plain,
secure));
     }
+
+    /**
+     * Sets the time taken for leader election in milliseconds.
+     *
+     * @param electionTimeTaken time taken for leader election
+     */
+    void setElectionTimeTaken(long electionTimeTaken) {
+        this.electionTimeTaken = electionTimeTaken;
+    }
+
+    /**
+     * @return the time taken for leader election in milliseconds.
+     */
+    long getElectionTimeTaken() {
+        return electionTimeTaken;
+    }
 }

http://git-wip-us.apache.org/repos/asf/zookeeper/blob/fbf6fe1a/src/java/test/org/apache/zookeeper/test/QuorumMajorityTest.java
----------------------------------------------------------------------
diff --git a/src/java/test/org/apache/zookeeper/test/QuorumMajorityTest.java b/src/java/test/org/apache/zookeeper/test/QuorumMajorityTest.java
index 28ed9f1..6966626 100644
--- a/src/java/test/org/apache/zookeeper/test/QuorumMajorityTest.java
+++ b/src/java/test/org/apache/zookeeper/test/QuorumMajorityTest.java
@@ -17,14 +17,16 @@
  */
 
 package org.apache.zookeeper.test;
-import java.util.HashSet;
+import java.util.ArrayList;
 
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.apache.zookeeper.server.quorum.Leader;
+import org.apache.zookeeper.jmx.CommonNames;
 import org.apache.zookeeper.server.quorum.Leader.Proposal;
+import org.apache.zookeeper.server.quorum.QuorumPeer;
+import org.apache.zookeeper.server.quorum.QuorumPeer.ServerState;
 import org.junit.Assert;
 import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class QuorumMajorityTest extends QuorumBase {
     protected static final Logger LOG = LoggerFactory.getLogger(QuorumMajorityTest.class);
@@ -36,7 +38,28 @@ public class QuorumMajorityTest extends QuorumBase {
     /***************************************************************/
     @Test
     public void testMajQuorums() throws Throwable {
-       
+        LOG.info("Verify QuorumPeer#electionTimeTaken jmx bean attribute");
+
+        ArrayList<QuorumPeer> peers = getPeerList();
+        for (int i = 1; i <= peers.size(); i++) {
+            QuorumPeer qp = peers.get(i - 1);
+            Long electionTimeTaken = -1L;
+            String bean = "";
+            if (qp.getPeerState() == ServerState.FOLLOWING) {
+                bean = String.format(
+                        "%s:name0=ReplicatedServer_id%d,name1=replica.%d,name2=Follower",
+                        CommonNames.DOMAIN, i, i);
+            } else if (qp.getPeerState() == ServerState.LEADING) {
+                bean = String.format(
+                        "%s:name0=ReplicatedServer_id%d,name1=replica.%d,name2=Leader",
+                        CommonNames.DOMAIN, i, i);
+            }
+            electionTimeTaken = (Long) JMXEnv.ensureBeanAttribute(bean,
+                    "ElectionTimeTaken");
+            Assert.assertTrue("Wrong electionTimeTaken value!",
+                    electionTimeTaken >= 0);
+        }
+
        //setup servers 1-5 to be followers
        setUp(false);
         


Mime
View raw message