io.atomix.protocols.raft.protocol.PollResponse Java Examples

The following examples show how to use io.atomix.protocols.raft.protocol.PollResponse. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LeaderRole.java    From atomix with Apache License 2.0 6 votes vote down vote up
@Override
public CompletableFuture<PollResponse> onPoll(final PollRequest request) {
  logRequest(request);

  // If a member sends a PollRequest to the leader, that indicates that it likely healed from
  // a network partition and may have had its status set to UNAVAILABLE by the leader. In order
  // to ensure heartbeats are immediately stored to the member, update its status if necessary.
  RaftMemberContext member = raft.getCluster().getMemberState(request.candidate());
  if (member != null) {
    member.resetFailureCount();
  }

  return CompletableFuture.completedFuture(logResponse(PollResponse.builder()
      .withStatus(RaftResponse.Status.OK)
      .withTerm(raft.getTerm())
      .withAccepted(false)
      .build()));
}
 
Example #2
Source File: ActiveRole.java    From atomix with Apache License 2.0 6 votes vote down vote up
/**
 * Handles a poll request.
 */
protected PollResponse handlePoll(PollRequest request) {
  // If the request term is not as great as the current context term then don't
  // vote for the candidate. We want to vote for candidates that are at least
  // as up to date as us.
  if (request.term() < raft.getTerm()) {
    log.debug("Rejected {}: candidate's term is less than the current term", request);
    return PollResponse.builder()
        .withStatus(RaftResponse.Status.OK)
        .withTerm(raft.getTerm())
        .withAccepted(false)
        .build();
  } else if (isLogUpToDate(request.lastLogIndex(), request.lastLogTerm(), request)) {
    return PollResponse.builder()
        .withStatus(RaftResponse.Status.OK)
        .withTerm(raft.getTerm())
        .withAccepted(true)
        .build();
  } else {
    return PollResponse.builder()
        .withStatus(RaftResponse.Status.OK)
        .withTerm(raft.getTerm())
        .withAccepted(false)
        .build();
  }
}
 
Example #3
Source File: InactiveRole.java    From atomix with Apache License 2.0 5 votes vote down vote up
@Override
public CompletableFuture<PollResponse> onPoll(PollRequest request) {
  logRequest(request);
  return Futures.completedFuture(logResponse(PollResponse.builder()
      .withStatus(Status.ERROR)
      .withError(RaftError.Type.UNAVAILABLE)
      .build()));
}
 
Example #4
Source File: PassiveRole.java    From atomix with Apache License 2.0 5 votes vote down vote up
@Override
public CompletableFuture<PollResponse> onPoll(PollRequest request) {
  raft.checkThread();
  logRequest(request);

  return CompletableFuture.completedFuture(logResponse(PollResponse.builder()
      .withStatus(RaftResponse.Status.ERROR)
      .withError(RaftError.Type.ILLEGAL_MEMBER_STATE, "Cannot poll RESERVE member")
      .build()));
}
 
Example #5
Source File: ActiveRole.java    From atomix with Apache License 2.0 5 votes vote down vote up
@Override
public CompletableFuture<PollResponse> onPoll(PollRequest request) {
  raft.checkThread();
  logRequest(request);
  updateTermAndLeader(request.term(), null);
  return CompletableFuture.completedFuture(logResponse(handlePoll(request)));
}
 
Example #6
Source File: LocalRaftServerProtocol.java    From atomix with Apache License 2.0 4 votes vote down vote up
@Override
public void registerPollHandler(Function<PollRequest, CompletableFuture<PollResponse>> handler) {
  this.pollHandler = handler;
}
 
Example #7
Source File: RaftServerMessagingProtocol.java    From submarine with Apache License 2.0 4 votes vote down vote up
@Override
public CompletableFuture<PollResponse> poll(MemberId memberId, PollRequest request) {
  return sendAndReceive(memberId, "poll", request);
}
 
Example #8
Source File: LocalRaftServerProtocol.java    From atomix with Apache License 2.0 4 votes vote down vote up
@Override
public CompletableFuture<PollResponse> poll(MemberId memberId, PollRequest request) {
  return getServer(memberId).thenCompose(listener -> listener.poll(encode(request))).thenApply(this::decode);
}
 
Example #9
Source File: RaftServerMessagingProtocol.java    From atomix with Apache License 2.0 4 votes vote down vote up
@Override
public void registerPollHandler(Function<PollRequest, CompletableFuture<PollResponse>> handler) {
  registerHandler("poll", handler);
}
 
Example #10
Source File: RaftServerMessagingProtocol.java    From atomix with Apache License 2.0 4 votes vote down vote up
@Override
public CompletableFuture<PollResponse> poll(MemberId memberId, PollRequest request) {
  return sendAndReceive(memberId, "poll", request);
}
 
Example #11
Source File: RaftServerCommunicator.java    From atomix with Apache License 2.0 4 votes vote down vote up
@Override
public void registerPollHandler(Function<PollRequest, CompletableFuture<PollResponse>> handler) {
  clusterCommunicator.subscribe(context.pollSubject, serializer::decode, handler, serializer::encode);
}
 
Example #12
Source File: RaftServerCommunicator.java    From atomix with Apache License 2.0 4 votes vote down vote up
@Override
public CompletableFuture<PollResponse> poll(MemberId memberId, PollRequest request) {
  return sendAndReceive(context.pollSubject, request, memberId);
}
 
Example #13
Source File: LocalRaftServerProtocol.java    From zeppelin with Apache License 2.0 4 votes vote down vote up
@Override
public void registerPollHandler(Function<PollRequest,
    CompletableFuture<PollResponse>> handler) {
  this.pollHandler = handler;
}
 
Example #14
Source File: LocalRaftServerProtocol.java    From zeppelin with Apache License 2.0 4 votes vote down vote up
@Override
public CompletableFuture<PollResponse> poll(MemberId memberId, PollRequest request) {
  return getServer(memberId).thenCompose(listener ->
      listener.poll(encode(request))).thenApply(this::decode);
}
 
Example #15
Source File: RaftServerMessagingProtocol.java    From zeppelin with Apache License 2.0 4 votes vote down vote up
@Override
public void registerPollHandler(Function<PollRequest,
    CompletableFuture<PollResponse>> handler) {
  registerHandler("poll", handler);
}
 
Example #16
Source File: RaftServerMessagingProtocol.java    From zeppelin with Apache License 2.0 4 votes vote down vote up
@Override
public CompletableFuture<PollResponse> poll(MemberId memberId, PollRequest request) {
  return sendAndReceive(memberId, "poll", request);
}
 
Example #17
Source File: LocalRaftServerProtocol.java    From submarine with Apache License 2.0 4 votes vote down vote up
@Override
public void registerPollHandler(Function<PollRequest,
    CompletableFuture<PollResponse>> handler) {
  this.pollHandler = handler;
}
 
Example #18
Source File: LocalRaftServerProtocol.java    From submarine with Apache License 2.0 4 votes vote down vote up
@Override
public CompletableFuture<PollResponse> poll(MemberId memberId, PollRequest request) {
  return getServer(memberId).thenCompose(listener ->
      listener.poll(encode(request))).thenApply(this::decode);
}
 
Example #19
Source File: RaftServerMessagingProtocol.java    From submarine with Apache License 2.0 4 votes vote down vote up
@Override
public void registerPollHandler(Function<PollRequest,
    CompletableFuture<PollResponse>> handler) {
  registerHandler("poll", handler);
}
 
Example #20
Source File: RaftRole.java    From atomix with Apache License 2.0 2 votes vote down vote up
/**
 * Handles a poll request.
 *
 * @param request The request to handle.
 * @return A completable future to be completed with the request response.
 */
CompletableFuture<PollResponse> onPoll(PollRequest request);