zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From eni...@apache.org
Subject [zookeeper] branch master updated: ZOOKEEPER-3502: improve the server command: zabstate to have a better observation on the process of leader election
Date Wed, 20 Nov 2019 06:01:04 GMT
This is an automated email from the ASF dual-hosted git repository.

enixon pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/zookeeper.git


The following commit(s) were added to refs/heads/master by this push:
     new 2e39cc0  ZOOKEEPER-3502: improve the server command: zabstate to have a better observation
on the process of leader election
2e39cc0 is described below

commit 2e39cc05713a052f738323dcb344b3615da7027a
Author: maoling <maoling199210191@sina.com>
AuthorDate: Tue Nov 19 22:00:56 2019 -0800

    ZOOKEEPER-3502: improve the server command: zabstate to have a better observation on the
process of leader election
    
    - Just as we knew, the rule of LE is that who has the biggest last zxid who will win.when
the zxid is the same, chose the myid number bigger one.
    - Do the following cmd will have a bird's-eye view on LE
    ```
     ➜  bin curl http://localhost:8081/commands/zabstate  http://localhost:8082/commands/zabstate
http://localhost:8083/commands/zabstate
    {
      "myid" : 1,
      "is_leader" : true,
      "endpoint" : "/127.0.0.1:2181",
      "voting" : true,
      "last_zxid" : "0xfa2c00000000",
      "zab_epoch" : 64044,
      "zab_counter" : 0,
      "zabstate" : "broadcast",
      "command" : "zabstate",
      "error" : null
    }{
      "myid" : 2,
      "is_leader" : false,
      "endpoint" : "/127.0.0.1:2182",
      "voting" : true,
      "last_zxid" : "0xfa2b00000004",
      "zab_epoch" : 64043,
      "zab_counter" : 4,
      "zabstate" : "broadcast",
      "command" : "zabstate",
      "error" : null
    }{
      "myid" : 3,
      "is_leader" : false,
      "endpoint" : "/127.0.0.1:2183",
      "voting" : true,
      "last_zxid" : "0xfa2b00000004",
      "zab_epoch" : 64043,
      "zab_counter" : 4,
      "zabstate" : "broadcast",
      "command" : "zabstate",
      "error" : null
    }%
    ```
    - more details in the [ZOOKEEPER-3502](https://issues.apache.org/jira/browse/ZOOKEEPER-3502)
    
    Author: maoling <maoling199210191@sina.com>
    
    Reviewers: Brian Nixon <enixon@apache.org>, Andor Molnar <andor@apache.org>,
Enrico Olivelli <eolivelli@apache.org>
    
    Closes #1052 from maoling/ZOOKEEPER-3502
---
 .../org/apache/zookeeper/server/admin/Commands.java    | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

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 36529f7..d4de57a 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
@@ -47,6 +47,7 @@ import org.apache.zookeeper.server.quorum.QuorumPeer;
 import org.apache.zookeeper.server.quorum.QuorumZooKeeperServer;
 import org.apache.zookeeper.server.quorum.ReadOnlyZooKeeperServer;
 import org.apache.zookeeper.server.quorum.flexible.QuorumVerifier;
+import org.apache.zookeeper.server.util.ZxidUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -796,10 +797,21 @@ public class Commands {
                 QuorumVerifier qv = peer.getQuorumVerifier();
 
                 QuorumPeer.QuorumServer voter = qv.getVotingMembers().get(peer.getId());
-                boolean voting = (voter != null
-                                  && voter.addr.equals(peer.getQuorumAddress())
-                                  && voter.electionAddr.equals(peer.getElectionAddress()));
+                boolean voting = (
+                        voter != null
+                                && voter.addr.equals(peer.getQuorumAddress())
+                                && voter.electionAddr.equals(peer.getElectionAddress())
+                );
+                response.put("myid", zkServer.getConf().getServerId());
+                response.put("is_leader", zkServer instanceof LeaderZooKeeperServer);
+                response.put("quorum_address", peer.getQuorumAddress());
+                response.put("election_address", peer.getElectionAddress());
+                response.put("client_address", peer.getClientAddress());
                 response.put("voting", voting);
+                long lastProcessedZxid = zkServer.getZKDatabase().getDataTreeLastProcessedZxid();
+                response.put("last_zxid", "0x" + ZxidUtils.zxidToString(lastProcessedZxid));
+                response.put("zab_epoch", ZxidUtils.getEpochFromZxid(lastProcessedZxid));
+                response.put("zab_counter", ZxidUtils.getCounterFromZxid(lastProcessedZxid));
                 response.put("zabstate", zabState.name().toLowerCase());
             } else {
                 response.put("voting", false);


Mime
View raw message