Search in sources :

Example 1 with ClusterApplyListener

use of org.elasticsearch.cluster.service.ClusterApplier.ClusterApplyListener in project crate by crate.

the class Coordinator method handleApplyCommit.

private void handleApplyCommit(ApplyCommitRequest applyCommitRequest, ActionListener<Void> applyListener) {
    synchronized (mutex) {
        LOGGER.trace("handleApplyCommit: applying commit {}", applyCommitRequest);
        coordinationState.get().handleCommit(applyCommitRequest);
        final ClusterState committedState = hideStateIfNotRecovered(coordinationState.get().getLastAcceptedState());
        applierState = mode == Mode.CANDIDATE ? clusterStateWithNoMasterBlock(committedState) : committedState;
        if (applyCommitRequest.getSourceNode().equals(getLocalNode())) {
            // master node applies the committed state at the end of the publication process, not here.
            applyListener.onResponse(null);
        } else {
            clusterApplier.onNewClusterState(applyCommitRequest.toString(), () -> applierState, new ClusterApplyListener() {

                @Override
                public void onFailure(String source, Exception e) {
                    applyListener.onFailure(e);
                }

                @Override
                public void onSuccess(String source) {
                    applyListener.onResponse(null);
                }
            });
        }
    }
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) ClusterApplyListener(org.elasticsearch.cluster.service.ClusterApplier.ClusterApplyListener) IOException(java.io.IOException)

Example 2 with ClusterApplyListener

use of org.elasticsearch.cluster.service.ClusterApplier.ClusterApplyListener in project crate by crate.

the class ClusterServiceUtils method setState.

public static void setState(ClusterApplierService executor, ClusterState clusterState) {
    CountDownLatch latch = new CountDownLatch(1);
    AtomicReference<Exception> exception = new AtomicReference<>();
    executor.onNewClusterState("test setting state", () -> ClusterState.builder(clusterState).version(clusterState.version() + 1).build(), new ClusterApplyListener() {

        @Override
        public void onSuccess(String source) {
            latch.countDown();
        }

        @Override
        public void onFailure(String source, Exception e) {
            exception.set(e);
            latch.countDown();
        }
    });
    try {
        latch.await();
        if (exception.get() != null) {
            Throwables.rethrow(exception.get());
        }
    } catch (InterruptedException e) {
        throw new ElasticsearchException("unexpected exception", e);
    }
}
Also used : ClusterApplyListener(org.elasticsearch.cluster.service.ClusterApplier.ClusterApplyListener) AtomicReference(java.util.concurrent.atomic.AtomicReference) ElasticsearchException(org.elasticsearch.ElasticsearchException) CountDownLatch(java.util.concurrent.CountDownLatch) ElasticsearchException(org.elasticsearch.ElasticsearchException)

Aggregations

ClusterApplyListener (org.elasticsearch.cluster.service.ClusterApplier.ClusterApplyListener)2 IOException (java.io.IOException)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 ElasticsearchException (org.elasticsearch.ElasticsearchException)1 ClusterState (org.elasticsearch.cluster.ClusterState)1