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

The following examples show how to use io.atomix.protocols.raft.protocol.LeaveRequest. 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: PassiveRole.java    From atomix with Apache License 2.0 6 votes vote down vote up
@Override
public CompletableFuture<LeaveResponse> onLeave(LeaveRequest request) {
  raft.checkThread();
  logRequest(request);

  if (raft.getLeader() == null) {
    return CompletableFuture.completedFuture(logResponse(LeaveResponse.builder()
        .withStatus(RaftResponse.Status.ERROR)
        .withError(RaftError.Type.NO_LEADER)
        .build()));
  } else {
    return forward(request, raft.getProtocol()::leave)
        .exceptionally(error -> LeaveResponse.builder()
            .withStatus(RaftResponse.Status.ERROR)
            .withError(RaftError.Type.NO_LEADER)
            .build())
        .thenApply(this::logResponse);
  }
}
 
Example #2
Source File: InactiveRole.java    From atomix with Apache License 2.0 5 votes vote down vote up
@Override
public CompletableFuture<LeaveResponse> onLeave(LeaveRequest request) {
  logRequest(request);
  return Futures.completedFuture(logResponse(LeaveResponse.builder()
      .withStatus(Status.ERROR)
      .withError(RaftError.Type.UNAVAILABLE)
      .build()));
}
 
Example #3
Source File: RaftClusterContext.java    From atomix with Apache License 2.0 5 votes vote down vote up
/**
 * Attempts to leave the cluster.
 */
private void leave(CompletableFuture<Void> future) {
  // Set a timer to retry the attempt to leave the cluster.
  leaveTimeout = raft.getThreadContext().schedule(raft.getElectionTimeout(), () -> {
    leave(future);
  });

  // Attempt to leave the cluster by submitting a LeaveRequest directly to the server state.
  // Non-leader states should forward the request to the leader if there is one. Leader states
  // will log, replicate, and commit the reconfiguration.
  raft.getRaftRole().onLeave(LeaveRequest.builder()
      .withMember(getMember())
      .build()).whenComplete((response, error) -> {
        // Cancel the leave timer.
        cancelLeaveTimer();

        if (error == null && response.status() == RaftResponse.Status.OK) {
          Configuration configuration = new Configuration(response.index(), response.term(), response.timestamp(), response.members());

          // Configure the cluster and commit the configuration as we know the successful response
          // indicates commitment.
          configure(configuration).commit();
          future.complete(null);
        } else {
          // Reset the leave timer.
          leaveTimeout = raft.getThreadContext().schedule(raft.getElectionTimeout(), () -> {
            leave(future);
          });
        }
      });
}
 
Example #4
Source File: RaftServerCommunicator.java    From atomix with Apache License 2.0 4 votes vote down vote up
@Override
public void registerLeaveHandler(Function<LeaveRequest, CompletableFuture<LeaveResponse>> handler) {
  clusterCommunicator.subscribe(context.leaveSubject, serializer::decode, handler, serializer::encode);
}
 
Example #5
Source File: LocalRaftServerProtocol.java    From atomix with Apache License 2.0 4 votes vote down vote up
@Override
public void registerLeaveHandler(Function<LeaveRequest, CompletableFuture<LeaveResponse>> handler) {
  this.leaveHandler = handler;
}
 
Example #6
Source File: LocalRaftServerProtocol.java    From atomix with Apache License 2.0 4 votes vote down vote up
@Override
public CompletableFuture<LeaveResponse> leave(MemberId memberId, LeaveRequest request) {
  return getServer(memberId).thenCompose(listener -> listener.leave(encode(request))).thenApply(this::decode);
}
 
Example #7
Source File: RaftServerMessagingProtocol.java    From atomix with Apache License 2.0 4 votes vote down vote up
@Override
public void registerLeaveHandler(Function<LeaveRequest, CompletableFuture<LeaveResponse>> handler) {
  registerHandler("leave", handler);
}
 
Example #8
Source File: RaftServerMessagingProtocol.java    From atomix with Apache License 2.0 4 votes vote down vote up
@Override
public CompletableFuture<LeaveResponse> leave(MemberId memberId, LeaveRequest request) {
  return sendAndReceive(memberId, "leave", request);
}
 
Example #9
Source File: RaftServerMessagingProtocol.java    From submarine with Apache License 2.0 4 votes vote down vote up
@Override
public CompletableFuture<LeaveResponse> leave(MemberId memberId, LeaveRequest request) {
  return sendAndReceive(memberId, "leave", request);
}
 
Example #10
Source File: RaftServerCommunicator.java    From atomix with Apache License 2.0 4 votes vote down vote up
@Override
public CompletableFuture<LeaveResponse> leave(MemberId memberId, LeaveRequest request) {
  return sendAndReceive(context.leaveSubject, request, memberId);
}
 
Example #11
Source File: LocalRaftServerProtocol.java    From zeppelin with Apache License 2.0 4 votes vote down vote up
@Override
public void registerLeaveHandler(Function<LeaveRequest,
    CompletableFuture<LeaveResponse>> handler) {
  this.leaveHandler = handler;
}
 
Example #12
Source File: LocalRaftServerProtocol.java    From zeppelin with Apache License 2.0 4 votes vote down vote up
@Override
public CompletableFuture<LeaveResponse> leave(MemberId memberId, LeaveRequest request) {
  return getServer(memberId).thenCompose(listener ->
      listener.leave(encode(request))).thenApply(this::decode);
}
 
Example #13
Source File: RaftServerMessagingProtocol.java    From zeppelin with Apache License 2.0 4 votes vote down vote up
@Override
public void registerLeaveHandler(Function<LeaveRequest,
    CompletableFuture<LeaveResponse>> handler) {
  registerHandler("leave", handler);
}
 
Example #14
Source File: RaftServerMessagingProtocol.java    From zeppelin with Apache License 2.0 4 votes vote down vote up
@Override
public CompletableFuture<LeaveResponse> leave(MemberId memberId, LeaveRequest request) {
  return sendAndReceive(memberId, "leave", request);
}
 
Example #15
Source File: LocalRaftServerProtocol.java    From submarine with Apache License 2.0 4 votes vote down vote up
@Override
public void registerLeaveHandler(Function<LeaveRequest,
    CompletableFuture<LeaveResponse>> handler) {
  this.leaveHandler = handler;
}
 
Example #16
Source File: LocalRaftServerProtocol.java    From submarine with Apache License 2.0 4 votes vote down vote up
@Override
public CompletableFuture<LeaveResponse> leave(MemberId memberId, LeaveRequest request) {
  return getServer(memberId).thenCompose(listener ->
      listener.leave(encode(request))).thenApply(this::decode);
}
 
Example #17
Source File: RaftServerMessagingProtocol.java    From submarine with Apache License 2.0 4 votes vote down vote up
@Override
public void registerLeaveHandler(Function<LeaveRequest,
    CompletableFuture<LeaveResponse>> handler) {
  registerHandler("leave", handler);
}
 
Example #18
Source File: RaftRole.java    From atomix with Apache License 2.0 2 votes vote down vote up
/**
 * Handles a leave request.
 *
 * @param request The request to handle.
 * @return A completable future to be completed with the request response.
 */
CompletableFuture<LeaveResponse> onLeave(LeaveRequest request);