Search in sources :

Example 1 with IncompatibleClusterStateVersionException

use of org.opensearch.cluster.IncompatibleClusterStateVersionException in project OpenSearch by opensearch-project.

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 = new InputStreamStreamInput(compressor.threadLocalInputStream(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;
            // Close early to release resources used by the de-compression as early as possible
            try (StreamInput input = in) {
                incomingState = ClusterState.readFrom(input, 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 {
                    final Diff<ClusterState> diff;
                    // Close stream early to release resources used by the de-compression as early as possible
                    try (StreamInput input = in) {
                        diff = ClusterState.readDiffFrom(input, 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.opensearch.cluster.ClusterState) InputStreamStreamInput(org.opensearch.common.io.stream.InputStreamStreamInput) NamedWriteableAwareStreamInput(org.opensearch.common.io.stream.NamedWriteableAwareStreamInput) StreamInput(org.opensearch.common.io.stream.StreamInput) Compressor(org.opensearch.common.compress.Compressor) NamedWriteableAwareStreamInput(org.opensearch.common.io.stream.NamedWriteableAwareStreamInput) IncompatibleClusterStateVersionException(org.opensearch.cluster.IncompatibleClusterStateVersionException) OpenSearchException(org.opensearch.OpenSearchException) IncompatibleClusterStateVersionException(org.opensearch.cluster.IncompatibleClusterStateVersionException) IOException(java.io.IOException) TransportException(org.opensearch.transport.TransportException) InputStreamStreamInput(org.opensearch.common.io.stream.InputStreamStreamInput)

Aggregations

IOException (java.io.IOException)1 OpenSearchException (org.opensearch.OpenSearchException)1 ClusterState (org.opensearch.cluster.ClusterState)1 IncompatibleClusterStateVersionException (org.opensearch.cluster.IncompatibleClusterStateVersionException)1 Compressor (org.opensearch.common.compress.Compressor)1 InputStreamStreamInput (org.opensearch.common.io.stream.InputStreamStreamInput)1 NamedWriteableAwareStreamInput (org.opensearch.common.io.stream.NamedWriteableAwareStreamInput)1 StreamInput (org.opensearch.common.io.stream.StreamInput)1 TransportException (org.opensearch.transport.TransportException)1