use of com.baidu.hugegraph.backend.store.raft.rpc.RaftRequests.SetLeaderRequest in project incubator-hugegraph by apache.
the class RaftGroupManagerImpl method setLeader.
@Override
public String setLeader(String endpoint) {
PeerId newLeaderId = PeerId.parsePeer(endpoint);
Node node = this.raftNode.node();
// If expected endpoint has already been raft leader
if (node.getLeaderId().equals(newLeaderId)) {
return newLeaderId.toString();
}
if (this.raftNode.selfIsLeader()) {
// If current node is the leader, transfer directly
this.transferLeaderTo(endpoint);
} else {
// If current node is not leader, forward request to leader
SetLeaderRequest request = SetLeaderRequest.newBuilder().setEndpoint(endpoint).build();
try {
RaftClosure<SetLeaderResponse> future;
future = this.forwardToLeader(request);
future.waitFinished();
} catch (Throwable e) {
throw new BackendException("Failed to set leader to '%s'", e, endpoint);
}
}
return newLeaderId.toString();
}
Aggregations