Skip to content

Commit

Permalink
Zen2: Add Cluster State Applier (#34257)
Browse files Browse the repository at this point in the history
Adds the cluster state applier to Coordinator, and adds tests for cluster state acking.
  • Loading branch information
ywelsch authored Oct 4, 2018
1 parent c6b0f08 commit b32abcb
Show file tree
Hide file tree
Showing 6 changed files with 695 additions and 196 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ public void onFaultyNode(DiscoveryNode faultyNode) {
onPossibleCompletion();
}

public boolean isCommitted() {
return applyCommitRequest.isPresent();
}

private void onPossibleCompletion() {
if (isCompleted) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@

import org.elasticsearch.action.ActionListener;
import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.common.component.AbstractComponent;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.TransportException;
import org.elasticsearch.transport.TransportRequestOptions;
Expand All @@ -29,19 +31,20 @@
import org.elasticsearch.transport.TransportService;

import java.io.IOException;
import java.util.function.Consumer;
import java.util.function.BiConsumer;
import java.util.function.Function;

public class PublicationTransportHandler {
public class PublicationTransportHandler extends AbstractComponent {

public static final String PUBLISH_STATE_ACTION_NAME = "internal:cluster/coordination/publish_state";
public static final String COMMIT_STATE_ACTION_NAME = "internal:cluster/coordination/commit_state";

private final TransportService transportService;

public PublicationTransportHandler(TransportService transportService,
public PublicationTransportHandler(Settings settings, TransportService transportService,
Function<PublishRequest, PublishWithJoinResponse> handlePublishRequest,
Consumer<ApplyCommitRequest> handleApplyCommit) {
BiConsumer<ApplyCommitRequest, ActionListener<Void>> handleApplyCommit) {
super(settings);
this.transportService = transportService;

transportService.registerRequestHandler(PUBLISH_STATE_ACTION_NAME, ThreadPool.Names.GENERIC, false, false,
Expand All @@ -50,10 +53,27 @@ public PublicationTransportHandler(TransportService transportService,

transportService.registerRequestHandler(COMMIT_STATE_ACTION_NAME, ThreadPool.Names.GENERIC, false, false,
ApplyCommitRequest::new,
(request, channel, task) -> {
handleApplyCommit.accept(request);
channel.sendResponse(TransportResponse.Empty.INSTANCE);
});
(request, channel, task) -> handleApplyCommit.accept(request, new ActionListener<Void>() {

@Override
public void onResponse(Void aVoid) {
try {
channel.sendResponse(TransportResponse.Empty.INSTANCE);
} catch (IOException e) {
logger.debug("failed to send response on commit", e);
}
}

@Override
public void onFailure(Exception e) {
try {
channel.sendResponse(e);
} catch (IOException ie) {
e.addSuppressed(ie);
logger.debug("failed to send response on commit", e);
}
}
}));
}

public void sendPublishRequest(DiscoveryNode destination, PublishRequest publishRequest,
Expand Down
Loading

0 comments on commit b32abcb

Please sign in to comment.