Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
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;

Expand Down Expand Up @@ -796,10 +797,21 @@ public CommandResponse run(ZooKeeperServer zkServer, Map<String, String> kwargs)
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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We' better not use 'instanceof', can you please add a method to the base class and implement it with a default value of 'false'?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eolivelli

  • I just follow the implementation of command:LeaderCommand and I have no idea whether there is a better way

  • We' better not use 'instanceof', can you please add a method to the base class and implement it with a default value of 'false'?

    I may not get your idea,Could you plz give me more info?

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);
Expand Down