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

The following examples show how to use io.atomix.protocols.raft.protocol.ConfigureRequest. 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: InactiveRole.java    From atomix with Apache License 2.0 6 votes vote down vote up
@Override
public CompletableFuture<ConfigureResponse> onConfigure(ConfigureRequest request) {
  raft.checkThread();
  logRequest(request);
  updateTermAndLeader(request.term(), request.leader());

  Configuration configuration = new Configuration(request.index(), request.term(), request.timestamp(), request.members());

  // Configure the cluster membership. This will cause this server to transition to the
  // appropriate state if its type has changed.
  raft.getCluster().configure(configuration);

  // If the configuration is already committed, commit it to disk.
  // Check against the actual cluster Configuration rather than the received configuration in
  // case the received configuration was an older configuration that was not applied.
  if (raft.getCommitIndex() >= raft.getCluster().getConfiguration().index()) {
    raft.getCluster().commit();
  }

  return CompletableFuture.completedFuture(logResponse(ConfigureResponse.builder()
      .withStatus(RaftResponse.Status.OK)
      .build()));
}
 
Example #2
Source File: AbstractAppender.java    From atomix with Apache License 2.0 5 votes vote down vote up
/**
 * Handles an OK configuration response.
 */
@SuppressWarnings("unused")
protected void handleConfigureResponseOk(RaftMemberContext member, ConfigureRequest request, ConfigureResponse response) {
  // Reset the member failure count and update the member's status if necessary.
  succeedAttempt(member);

  // Update the member's current configuration term and index according to the installed configuration.
  member.setConfigTerm(request.term());
  member.setConfigIndex(request.index());

  // Recursively append entries to the member.
  appendEntries(member);
}
 
Example #3
Source File: AbstractAppender.java    From atomix with Apache License 2.0 5 votes vote down vote up
/**
 * Builds a configure request for the given member.
 */
protected ConfigureRequest buildConfigureRequest(RaftMemberContext member) {
  DefaultRaftMember leader = raft.getLeader();
  return ConfigureRequest.builder()
      .withTerm(raft.getTerm())
      .withLeader(leader != null ? leader.memberId() : null)
      .withIndex(raft.getCluster().getConfiguration().index())
      .withTime(raft.getCluster().getConfiguration().time())
      .withMembers(raft.getCluster().getConfiguration().members())
      .build();
}
 
Example #4
Source File: AbstractAppender.java    From atomix with Apache License 2.0 5 votes vote down vote up
/**
 * Connects to the member and sends a configure request.
 */
protected void sendConfigureRequest(RaftMemberContext member, ConfigureRequest request) {
  log.debug("Configuring {}", member.getMember().memberId());

  // Start the configure to the member.
  member.startConfigure();

  long timestamp = System.currentTimeMillis();

  log.trace("Sending {} to {}", request, member.getMember().memberId());
  raft.getProtocol().configure(member.getMember().memberId(), request).whenCompleteAsync((response, error) -> {
    // Complete the configure to the member.
    member.completeConfigure();

    if (open) {
      if (error == null) {
        log.trace("Received {} from {}", response, member.getMember().memberId());
        handleConfigureResponse(member, request, response, timestamp);
      } else {
        if (log.isTraceEnabled()) {
          log.debug("Failed to configure {}", member.getMember().memberId(), error);
        } else {
          log.debug("Failed to configure {}", member.getMember().memberId());
        }
        handleConfigureResponseFailure(member, request, error);
      }
    }
  }, raft.getThreadContext());
}
 
Example #5
Source File: AbstractAppender.java    From atomix with Apache License 2.0 5 votes vote down vote up
/**
 * Handles a configuration response.
 */
protected void handleConfigureResponse(RaftMemberContext member, ConfigureRequest request, ConfigureResponse response, long timestamp) {
  if (response.status() == RaftResponse.Status.OK) {
    handleConfigureResponseOk(member, request, response);
  } else {
    handleConfigureResponseError(member, request, response);
  }
}
 
Example #6
Source File: AbstractAppender.java    From atomix with Apache License 2.0 4 votes vote down vote up
/**
 * Handles a configure failure.
 */
protected void handleConfigureResponseFailure(RaftMemberContext member, ConfigureRequest request, Throwable error) {
  // Log the failed attempt to contact the member.
  failAttempt(member, request, error);
}
 
Example #7
Source File: LocalRaftServerProtocol.java    From atomix with Apache License 2.0 4 votes vote down vote up
@Override
public void registerConfigureHandler(Function<ConfigureRequest, CompletableFuture<ConfigureResponse>> handler) {
  this.configureHandler = handler;
}
 
Example #8
Source File: LocalRaftServerProtocol.java    From atomix with Apache License 2.0 4 votes vote down vote up
@Override
public CompletableFuture<ConfigureResponse> configure(MemberId memberId, ConfigureRequest request) {
  return getServer(memberId).thenCompose(listener -> listener.configure(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 registerConfigureHandler(Function<ConfigureRequest, CompletableFuture<ConfigureResponse>> handler) {
  registerHandler("configure", handler);
}
 
Example #10
Source File: RaftServerMessagingProtocol.java    From atomix with Apache License 2.0 4 votes vote down vote up
@Override
public CompletableFuture<ConfigureResponse> configure(MemberId memberId, ConfigureRequest request) {
  return sendAndReceive(memberId, "configure", request);
}
 
Example #11
Source File: FollowerRole.java    From atomix with Apache License 2.0 4 votes vote down vote up
@Override
public CompletableFuture<ConfigureResponse> onConfigure(ConfigureRequest request) {
  CompletableFuture<ConfigureResponse> future = super.onConfigure(request);
  resetHeartbeatTimeout();
  return future;
}
 
Example #12
Source File: LeaderAppender.java    From atomix with Apache License 2.0 4 votes vote down vote up
@Override
protected void handleConfigureResponse(RaftMemberContext member, ConfigureRequest request, ConfigureResponse response, long timestamp) {
  super.handleConfigureResponse(member, request, response, timestamp);
  recordHeartbeat(member, timestamp);
}
 
Example #13
Source File: AbstractAppender.java    From atomix with Apache License 2.0 4 votes vote down vote up
/**
 * Handles an ERROR configuration response.
 */
@SuppressWarnings("unused")
protected void handleConfigureResponseError(RaftMemberContext member, ConfigureRequest request, ConfigureResponse response) {
  // In the event of a configure response error, simply do nothing and await the next heartbeat.
  // This prevents infinite loops when cluster configurations fail.
}
 
Example #14
Source File: RaftServerMessagingProtocol.java    From submarine with Apache License 2.0 4 votes vote down vote up
@Override
public CompletableFuture<ConfigureResponse> configure(MemberId memberId,
                                                      ConfigureRequest request) {
  return sendAndReceive(memberId, "configure", request);
}
 
Example #15
Source File: RaftServerCommunicator.java    From atomix with Apache License 2.0 4 votes vote down vote up
@Override
public void registerConfigureHandler(Function<ConfigureRequest, CompletableFuture<ConfigureResponse>> handler) {
  clusterCommunicator.subscribe(context.configureSubject, serializer::decode, handler, serializer::encode);
}
 
Example #16
Source File: RaftServerCommunicator.java    From atomix with Apache License 2.0 4 votes vote down vote up
@Override
public CompletableFuture<ConfigureResponse> configure(MemberId memberId, ConfigureRequest request) {
  return sendAndReceive(context.configureSubject, request, memberId);
}
 
Example #17
Source File: LocalRaftServerProtocol.java    From zeppelin with Apache License 2.0 4 votes vote down vote up
@Override
public void registerConfigureHandler(Function<ConfigureRequest,
    CompletableFuture<ConfigureResponse>> handler) {
  this.configureHandler = handler;
}
 
Example #18
Source File: LocalRaftServerProtocol.java    From zeppelin with Apache License 2.0 4 votes vote down vote up
@Override
public CompletableFuture<ConfigureResponse> configure(MemberId memberId,
                                                      ConfigureRequest request) {
  return getServer(memberId).thenCompose(listener ->
      listener.configure(encode(request))).thenApply(this::decode);
}
 
Example #19
Source File: RaftServerMessagingProtocol.java    From zeppelin with Apache License 2.0 4 votes vote down vote up
@Override
public void registerConfigureHandler(Function<ConfigureRequest,
    CompletableFuture<ConfigureResponse>> handler) {
  registerHandler("configure", handler);
}
 
Example #20
Source File: RaftServerMessagingProtocol.java    From zeppelin with Apache License 2.0 4 votes vote down vote up
@Override
public CompletableFuture<ConfigureResponse> configure(MemberId memberId,
                                                      ConfigureRequest request) {
  return sendAndReceive(memberId, "configure", request);
}
 
Example #21
Source File: LocalRaftServerProtocol.java    From submarine with Apache License 2.0 4 votes vote down vote up
@Override
public void registerConfigureHandler(Function<ConfigureRequest,
    CompletableFuture<ConfigureResponse>> handler) {
  this.configureHandler = handler;
}
 
Example #22
Source File: LocalRaftServerProtocol.java    From submarine with Apache License 2.0 4 votes vote down vote up
@Override
public CompletableFuture<ConfigureResponse> configure(MemberId memberId,
                                                      ConfigureRequest request) {
  return getServer(memberId).thenCompose(listener ->
      listener.configure(encode(request))).thenApply(this::decode);
}
 
Example #23
Source File: RaftServerMessagingProtocol.java    From submarine with Apache License 2.0 4 votes vote down vote up
@Override
public void registerConfigureHandler(Function<ConfigureRequest,
    CompletableFuture<ConfigureResponse>> handler) {
  registerHandler("configure", handler);
}
 
Example #24
Source File: RaftRole.java    From atomix with Apache License 2.0 2 votes vote down vote up
/**
 * Handles a configure request.
 *
 * @param request The request to handle.
 * @return A completable future to be completed with the request response.
 */
CompletableFuture<ConfigureResponse> onConfigure(ConfigureRequest request);