Search in sources :

Example 1 with IncompatibleClusterStateVersionException

use of org.elasticsearch.cluster.IncompatibleClusterStateVersionException in project elasticsearch by elastic.

the class PublishClusterStateAction method handleIncomingClusterStateRequest.

protected void handleIncomingClusterStateRequest(BytesTransportRequest request, TransportChannel channel) throws IOException {
    Compressor compressor = CompressorFactory.compressor(request.bytes());
    StreamInput in = request.bytes().streamInput();
    try {
        if (compressor != null) {
            in = compressor.streamInput(in);
        }
        in = new NamedWriteableAwareStreamInput(in, namedWriteableRegistry);
        in.setVersion(request.version());
        synchronized (lastSeenClusterStateMutex) {
            final ClusterState incomingState;
            // If true we received full cluster state - otherwise diffs
            if (in.readBoolean()) {
                incomingState = ClusterState.readFrom(in, clusterStateSupplier.get().nodes().getLocalNode());
                logger.debug("received full cluster state version [{}] with size [{}]", incomingState.version(), request.bytes().length());
            } else if (lastSeenClusterState != null) {
                Diff<ClusterState> diff = ClusterState.readDiffFrom(in, lastSeenClusterState.nodes().getLocalNode());
                incomingState = diff.apply(lastSeenClusterState);
                logger.debug("received diff cluster state version [{}] with uuid [{}], diff size [{}]", incomingState.version(), incomingState.stateUUID(), request.bytes().length());
            } else {
                logger.debug("received diff for but don't have any local cluster state - requesting full state");
                throw new IncompatibleClusterStateVersionException("have no local cluster state");
            }
            // sanity check incoming state
            validateIncomingState(incomingState, lastSeenClusterState);
            pendingStatesQueue.addPending(incomingState);
            lastSeenClusterState = incomingState;
        }
    } finally {
        IOUtils.close(in);
    }
    channel.sendResponse(TransportResponse.Empty.INSTANCE);
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) Diff(org.elasticsearch.cluster.Diff) NamedWriteableAwareStreamInput(org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput) StreamInput(org.elasticsearch.common.io.stream.StreamInput) Compressor(org.elasticsearch.common.compress.Compressor) NamedWriteableAwareStreamInput(org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput) IncompatibleClusterStateVersionException(org.elasticsearch.cluster.IncompatibleClusterStateVersionException)

Example 2 with IncompatibleClusterStateVersionException

use of org.elasticsearch.cluster.IncompatibleClusterStateVersionException in project elasticsearch by elastic.

the class PublishClusterStateAction method sendClusterStateToNode.

private void sendClusterStateToNode(final ClusterState clusterState, BytesReference bytes, final DiscoveryNode node, final TimeValue publishTimeout, final SendingController sendingController, final boolean sendDiffs, final Map<Version, BytesReference> serializedStates) {
    try {
        // -> no need to put a timeout on the options here, because we want the response to eventually be received
        //  and not log an error if it arrives after the timeout
        // -> no need to compress, we already compressed the bytes
        TransportRequestOptions options = TransportRequestOptions.builder().withType(TransportRequestOptions.Type.STATE).withCompress(false).build();
        transportService.sendRequest(node, SEND_ACTION_NAME, new BytesTransportRequest(bytes, node.getVersion()), options, new EmptyTransportResponseHandler(ThreadPool.Names.SAME) {

            @Override
            public void handleResponse(TransportResponse.Empty response) {
                if (sendingController.getPublishingTimedOut()) {
                    logger.debug("node {} responded for cluster state [{}] (took longer than [{}])", node, clusterState.version(), publishTimeout);
                }
                sendingController.onNodeSendAck(node);
            }

            @Override
            public void handleException(TransportException exp) {
                if (sendDiffs && exp.unwrapCause() instanceof IncompatibleClusterStateVersionException) {
                    logger.debug("resending full cluster state to node {} reason {}", node, exp.getDetailedMessage());
                    sendFullClusterState(clusterState, serializedStates, node, publishTimeout, sendingController);
                } else {
                    logger.debug((org.apache.logging.log4j.util.Supplier<?>) () -> new ParameterizedMessage("failed to send cluster state to {}", node), exp);
                    sendingController.onNodeSendFailed(node, exp);
                }
            }
        });
    } catch (Exception e) {
        logger.warn((org.apache.logging.log4j.util.Supplier<?>) () -> new ParameterizedMessage("error sending cluster state to {}", node), e);
        sendingController.onNodeSendFailed(node, e);
    }
}
Also used : TransportResponse(org.elasticsearch.transport.TransportResponse) TransportException(org.elasticsearch.transport.TransportException) ElasticsearchException(org.elasticsearch.ElasticsearchException) IncompatibleClusterStateVersionException(org.elasticsearch.cluster.IncompatibleClusterStateVersionException) IOException(java.io.IOException) TransportException(org.elasticsearch.transport.TransportException) BytesTransportRequest(org.elasticsearch.transport.BytesTransportRequest) TransportRequestOptions(org.elasticsearch.transport.TransportRequestOptions) Supplier(java.util.function.Supplier) ParameterizedMessage(org.apache.logging.log4j.message.ParameterizedMessage) EmptyTransportResponseHandler(org.elasticsearch.transport.EmptyTransportResponseHandler) IncompatibleClusterStateVersionException(org.elasticsearch.cluster.IncompatibleClusterStateVersionException)

Example 3 with IncompatibleClusterStateVersionException

use of org.elasticsearch.cluster.IncompatibleClusterStateVersionException in project crate by crate.

the class PublicationTransportHandler method sendClusterStateToNode.

private void sendClusterStateToNode(ClusterState clusterState, BytesReference bytes, DiscoveryNode node, ActionListener<PublishWithJoinResponse> responseActionListener, boolean sendDiffs, Map<Version, BytesReference> serializedStates) {
    try {
        final BytesTransportRequest request = new BytesTransportRequest(bytes, node.getVersion());
        final Consumer<TransportException> transportExceptionHandler = exp -> {
            if (sendDiffs && exp.unwrapCause() instanceof IncompatibleClusterStateVersionException) {
                LOGGER.debug("resending full cluster state to node {} reason {}", node, exp.getDetailedMessage());
                sendFullClusterState(clusterState, serializedStates, node, responseActionListener);
            } else {
                LOGGER.debug(() -> new ParameterizedMessage("failed to send cluster state to {}", node), exp);
                responseActionListener.onFailure(exp);
            }
        };
        final TransportResponseHandler<PublishWithJoinResponse> publishWithJoinResponseHandler = new TransportResponseHandler<PublishWithJoinResponse>() {

            @Override
            public PublishWithJoinResponse read(StreamInput in) throws IOException {
                return new PublishWithJoinResponse(in);
            }

            @Override
            public void handleResponse(PublishWithJoinResponse response) {
                responseActionListener.onResponse(response);
            }

            @Override
            public void handleException(TransportException exp) {
                transportExceptionHandler.accept(exp);
            }

            @Override
            public String executor() {
                return ThreadPool.Names.GENERIC;
            }
        };
        transportService.sendRequest(node, PUBLISH_STATE_ACTION_NAME, request, stateRequestOptions, publishWithJoinResponseHandler);
    } catch (Exception e) {
        LOGGER.warn(() -> new ParameterizedMessage("error sending cluster state to {}", node), e);
        responseActionListener.onFailure(e);
    }
}
Also used : ElasticsearchException(org.elasticsearch.ElasticsearchException) StreamOutput(org.elasticsearch.common.io.stream.StreamOutput) TransportChannel(org.elasticsearch.transport.TransportChannel) IncompatibleClusterStateVersionException(org.elasticsearch.cluster.IncompatibleClusterStateVersionException) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput) HashMap(java.util.HashMap) ParameterizedMessage(org.apache.logging.log4j.message.ParameterizedMessage) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) Diff(org.elasticsearch.cluster.Diff) ClusterState(org.elasticsearch.cluster.ClusterState) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) NamedWriteableRegistry(org.elasticsearch.common.io.stream.NamedWriteableRegistry) Map(java.util.Map) BiConsumer(java.util.function.BiConsumer) ThreadPool(org.elasticsearch.threadpool.ThreadPool) TransportResponse(org.elasticsearch.transport.TransportResponse) TransportService(org.elasticsearch.transport.TransportService) BytesTransportRequest(org.elasticsearch.transport.BytesTransportRequest) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes) Compressor(org.elasticsearch.common.compress.Compressor) IOUtils(io.crate.common.io.IOUtils) IOException(java.io.IOException) BytesReference(org.elasticsearch.common.bytes.BytesReference) ClusterChangedEvent(org.elasticsearch.cluster.ClusterChangedEvent) CompressorFactory(org.elasticsearch.common.compress.CompressorFactory) Consumer(java.util.function.Consumer) AtomicLong(java.util.concurrent.atomic.AtomicLong) NamedWriteableAwareStreamInput(org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput) Logger(org.apache.logging.log4j.Logger) Version(org.elasticsearch.Version) StreamInput(org.elasticsearch.common.io.stream.StreamInput) TransportResponseHandler(org.elasticsearch.transport.TransportResponseHandler) TransportRequestOptions(org.elasticsearch.transport.TransportRequestOptions) LogManager(org.apache.logging.log4j.LogManager) TransportException(org.elasticsearch.transport.TransportException) ActionListener(org.elasticsearch.action.ActionListener) BytesTransportRequest(org.elasticsearch.transport.BytesTransportRequest) TransportResponseHandler(org.elasticsearch.transport.TransportResponseHandler) NamedWriteableAwareStreamInput(org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput) StreamInput(org.elasticsearch.common.io.stream.StreamInput) ParameterizedMessage(org.apache.logging.log4j.message.ParameterizedMessage) IncompatibleClusterStateVersionException(org.elasticsearch.cluster.IncompatibleClusterStateVersionException) TransportException(org.elasticsearch.transport.TransportException) ElasticsearchException(org.elasticsearch.ElasticsearchException) IncompatibleClusterStateVersionException(org.elasticsearch.cluster.IncompatibleClusterStateVersionException) IOException(java.io.IOException) TransportException(org.elasticsearch.transport.TransportException)

Example 4 with IncompatibleClusterStateVersionException

use of org.elasticsearch.cluster.IncompatibleClusterStateVersionException in project crate by crate.

the class PublicationTransportHandler method handleIncomingPublishRequest.

private PublishWithJoinResponse handleIncomingPublishRequest(BytesTransportRequest request) throws IOException {
    final Compressor compressor = CompressorFactory.compressor(request.bytes());
    StreamInput in = request.bytes().streamInput();
    try {
        if (compressor != null) {
            in = compressor.streamInput(in);
        }
        in = new NamedWriteableAwareStreamInput(in, namedWriteableRegistry);
        in.setVersion(request.version());
        // If true we received full cluster state - otherwise diffs
        if (in.readBoolean()) {
            final ClusterState incomingState;
            try {
                incomingState = ClusterState.readFrom(in, transportService.getLocalNode());
            } catch (Exception e) {
                LOGGER.warn("unexpected error while deserializing an incoming cluster state", e);
                throw e;
            }
            fullClusterStateReceivedCount.incrementAndGet();
            LOGGER.debug("received full cluster state version [{}] with size [{}]", incomingState.version(), request.bytes().length());
            final PublishWithJoinResponse response = acceptState(incomingState);
            lastSeenClusterState.set(incomingState);
            return response;
        } else {
            final ClusterState lastSeen = lastSeenClusterState.get();
            if (lastSeen == null) {
                LOGGER.debug("received diff for but don't have any local cluster state - requesting full state");
                incompatibleClusterStateDiffReceivedCount.incrementAndGet();
                throw new IncompatibleClusterStateVersionException("have no local cluster state");
            } else {
                ClusterState incomingState;
                try {
                    Diff<ClusterState> diff = ClusterState.readDiffFrom(in, lastSeen.nodes().getLocalNode());
                    // might throw IncompatibleClusterStateVersionException
                    incomingState = diff.apply(lastSeen);
                } catch (IncompatibleClusterStateVersionException e) {
                    incompatibleClusterStateDiffReceivedCount.incrementAndGet();
                    throw e;
                } catch (Exception e) {
                    LOGGER.warn("unexpected error while deserializing an incoming cluster state", e);
                    throw e;
                }
                compatibleClusterStateDiffReceivedCount.incrementAndGet();
                LOGGER.debug("received diff cluster state version [{}] with uuid [{}], diff size [{}]", incomingState.version(), incomingState.stateUUID(), request.bytes().length());
                final PublishWithJoinResponse response = acceptState(incomingState);
                lastSeenClusterState.compareAndSet(lastSeen, incomingState);
                return response;
            }
        }
    } finally {
        IOUtils.close(in);
    }
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) NamedWriteableAwareStreamInput(org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput) StreamInput(org.elasticsearch.common.io.stream.StreamInput) Compressor(org.elasticsearch.common.compress.Compressor) NamedWriteableAwareStreamInput(org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput) IncompatibleClusterStateVersionException(org.elasticsearch.cluster.IncompatibleClusterStateVersionException) ElasticsearchException(org.elasticsearch.ElasticsearchException) IncompatibleClusterStateVersionException(org.elasticsearch.cluster.IncompatibleClusterStateVersionException) IOException(java.io.IOException) TransportException(org.elasticsearch.transport.TransportException)

Aggregations

IncompatibleClusterStateVersionException (org.elasticsearch.cluster.IncompatibleClusterStateVersionException)4 IOException (java.io.IOException)3 ElasticsearchException (org.elasticsearch.ElasticsearchException)3 ClusterState (org.elasticsearch.cluster.ClusterState)3 Compressor (org.elasticsearch.common.compress.Compressor)3 NamedWriteableAwareStreamInput (org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput)3 StreamInput (org.elasticsearch.common.io.stream.StreamInput)3 TransportException (org.elasticsearch.transport.TransportException)3 ParameterizedMessage (org.apache.logging.log4j.message.ParameterizedMessage)2 Diff (org.elasticsearch.cluster.Diff)2 BytesTransportRequest (org.elasticsearch.transport.BytesTransportRequest)2 TransportRequestOptions (org.elasticsearch.transport.TransportRequestOptions)2 TransportResponse (org.elasticsearch.transport.TransportResponse)2 IOUtils (io.crate.common.io.IOUtils)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 BiConsumer (java.util.function.BiConsumer)1 Consumer (java.util.function.Consumer)1