use of org.apache.bookkeeper.proto.DataFormats.AuditorVoteFormat in project bookkeeper by apache.
the class AuditorElector method getCurrentAuditor.
/**
* Query zookeeper for the currently elected auditor.
* @return the bookie id of the current auditor
*/
public static BookieSocketAddress getCurrentAuditor(ServerConfiguration conf, ZooKeeper zk) throws KeeperException, InterruptedException, IOException {
String electionRoot = conf.getZkLedgersRootPath() + '/' + BookKeeperConstants.UNDER_REPLICATION_NODE + '/' + ELECTION_ZNODE;
List<String> children = zk.getChildren(electionRoot, false);
Collections.sort(children, new AuditorElector.ElectionComparator());
if (children.size() < 1) {
return null;
}
String ledger = electionRoot + "/" + children.get(AUDITOR_INDEX);
byte[] data = zk.getData(ledger, false, null);
AuditorVoteFormat.Builder builder = AuditorVoteFormat.newBuilder();
TextFormat.merge(new String(data, UTF_8), builder);
AuditorVoteFormat v = builder.build();
String[] parts = v.getBookieId().split(":");
return new BookieSocketAddress(parts[0], Integer.parseInt(parts[1]));
}
Aggregations