Search in sources :

Example 1 with StartLeaderElectionReplyProto

use of org.apache.ratis.proto.RaftProtos.StartLeaderElectionReplyProto in project incubator-ratis by apache.

the class LeaderStateImpl method sendStartLeaderElectionToHigherPriorityPeer.

private synchronized void sendStartLeaderElectionToHigherPriorityPeer(RaftPeerId follower, TermIndex lastEntry) {
    ServerState state = server.getState();
    TermIndex currLastEntry = state.getLastEntry();
    if (ServerState.compareLog(currLastEntry, lastEntry) != 0) {
        LOG.warn("{} can not send StartLeaderElectionRequest to follower:{} because currLastEntry:{} " + "did not match lastEntry:{}", this, follower, currLastEntry, lastEntry);
        return;
    }
    final StartLeaderElectionRequestProto r = ServerProtoUtils.toStartLeaderElectionRequestProto(server.getMemberId(), follower, lastEntry);
    CompletableFuture.supplyAsync(() -> {
        server.getLeaderElectionMetrics().onTransferLeadership();
        try {
            StartLeaderElectionReplyProto replyProto = server.getServerRpc().startLeaderElection(r);
            LOG.info("{} received {} reply of StartLeaderElectionRequest from follower:{}", this, replyProto.getServerReply().getSuccess() ? "success" : "fail", follower);
        } catch (IOException e) {
            LOG.warn("{} send StartLeaderElectionRequest throw exception", this, e);
        }
        return null;
    });
}
Also used : StartLeaderElectionRequestProto(org.apache.ratis.proto.RaftProtos.StartLeaderElectionRequestProto) StartLeaderElectionReplyProto(org.apache.ratis.proto.RaftProtos.StartLeaderElectionReplyProto) IOException(java.io.IOException) TermIndex(org.apache.ratis.server.protocol.TermIndex)

Aggregations

IOException (java.io.IOException)1 StartLeaderElectionReplyProto (org.apache.ratis.proto.RaftProtos.StartLeaderElectionReplyProto)1 StartLeaderElectionRequestProto (org.apache.ratis.proto.RaftProtos.StartLeaderElectionRequestProto)1 TermIndex (org.apache.ratis.server.protocol.TermIndex)1