فهرست منبع

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
maoling 5 سال پیش
والد
کامیت
2e39cc0571
1فایلهای تغییر یافته به همراه15 افزوده شده و 3 حذف شده
  1. 15 3
      zookeeper-server/src/main/java/org/apache/zookeeper/server/admin/Commands.java

+ 15 - 3
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.QuorumZooKeeperServer;
 import org.apache.zookeeper.server.quorum.ReadOnlyZooKeeperServer;
 import org.apache.zookeeper.server.quorum.ReadOnlyZooKeeperServer;
 import org.apache.zookeeper.server.quorum.flexible.QuorumVerifier;
 import org.apache.zookeeper.server.quorum.flexible.QuorumVerifier;
+import org.apache.zookeeper.server.util.ZxidUtils;
 import org.slf4j.Logger;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.slf4j.LoggerFactory;
 
 
@@ -796,10 +797,21 @@ public class Commands {
                 QuorumVerifier qv = peer.getQuorumVerifier();
                 QuorumVerifier qv = peer.getQuorumVerifier();
 
 
                 QuorumPeer.QuorumServer voter = qv.getVotingMembers().get(peer.getId());
                 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);
                 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());
                 response.put("zabstate", zabState.name().toLowerCase());
             } else {
             } else {
                 response.put("voting", false);
                 response.put("voting", false);