Skip to content

Zen2: Add Cluster State Applier #34257

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
Oct 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

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