Search in sources :

Example 1 with UnambiguousTimeoutException

use of com.couchbase.client.core.error.UnambiguousTimeoutException in project couchbase-jvm-clients by couchbase.

the class QueryChunkResponseParser method errorsToThrowable.

static CouchbaseException errorsToThrowable(final byte[] bytes, HttpResponse header, RequestContext ctx) {
    int httpStatus = header != null ? header.status().code() : 0;
    final List<ErrorCodeAndMessage> errors = bytes.length == 0 ? Collections.emptyList() : ErrorCodeAndMessage.fromJsonArray(bytes);
    QueryErrorContext errorContext = new QueryErrorContext(ctx, errors, httpStatus);
    if (errors.size() >= 1) {
        ErrorCodeAndMessage codeAndMessage = errors.get(0);
        int code = codeAndMessage.code();
        String message = codeAndMessage.message();
        int reasonCode = codeAndMessage.reason() != null ? (int) codeAndMessage.reason().getOrDefault("code", 0) : 0;
        if (code == 3000) {
            return new ParsingFailureException(errorContext);
        } else if (PREPARED_ERROR_CODES.contains(code)) {
            return new PreparedStatementFailureException(errorContext, RETRYABLE_PREPARED_ERROR_CODES.contains(code));
        } else if (code == 4300 && message.matches("^.*index .*already exist.*")) {
            return new IndexExistsException(errorContext);
        } else if (code >= 4000 && code < 5000) {
            return new PlanningFailureException(errorContext);
        } else if (code == 12004 || code == 12016 || (code == 5000 && message.matches("^.*index .+ not found.*"))) {
            return new IndexNotFoundException(errorContext);
        } else if (code == 5000 && message.matches("^.*Index .*already exist.*")) {
            return new IndexExistsException(errorContext);
        } else if (code == 5000 && message.contains("limit for number of indexes that can be created per scope has been reached")) {
            return new QuotaLimitedException(errorContext);
        } else if (code >= 5000 && code < 6000) {
            return new InternalServerFailureException(errorContext);
        } else if (code == 12009) {
            if (message.contains("CAS mismatch") || reasonCode == 12033) {
                return new CasMismatchException(errorContext);
            } else if (reasonCode == 17014) {
                return new DocumentNotFoundException(errorContext);
            } else if (reasonCode == 17012) {
                return new DocumentExistsException(errorContext);
            } else {
                return new DmlFailureException(errorContext);
            }
        } else if ((code >= 10000 && code < 11000) || code == 13014) {
            return new AuthenticationFailureException("Could not authenticate query", errorContext, null);
        } else if ((code >= 12000 && code < 13000) || (code >= 14000 && code < 15000)) {
            return new IndexFailureException(errorContext);
        } else if (code == 1065) {
            if (message.contains("query_context")) {
                return FeatureNotAvailableException.scopeLevelQuery(ServiceType.QUERY);
            }
            if (message.contains("preserve_expiry")) {
                return FeatureNotAvailableException.queryPreserveExpiry();
            }
        } else if (code == 1080) {
            // engine will proactively send us a timeout and we need to convert it.
            return new UnambiguousTimeoutException("Query timed out while streaming/receiving rows", new CancellationErrorContext(errorContext));
        } else if (code == 1191 || code == 1192 || code == 1193 || code == 1194) {
            return new RateLimitedException(errorContext);
        } else if (code == 3230) {
            String feature = null;
            if (message.contains("Advisor") || message.contains("Advise")) {
                feature = "Query Index Advisor";
            } else if (message.contains("Window")) {
                feature = "Query Window Functions";
            }
            return FeatureNotAvailableException.communityEdition(feature);
        }
    }
    return new CouchbaseException("Unknown query error", errorContext);
}
Also used : IndexExistsException(com.couchbase.client.core.error.IndexExistsException) DocumentNotFoundException(com.couchbase.client.core.error.DocumentNotFoundException) DocumentExistsException(com.couchbase.client.core.error.DocumentExistsException) CasMismatchException(com.couchbase.client.core.error.CasMismatchException) PlanningFailureException(com.couchbase.client.core.error.PlanningFailureException) UnambiguousTimeoutException(com.couchbase.client.core.error.UnambiguousTimeoutException) AuthenticationFailureException(com.couchbase.client.core.error.AuthenticationFailureException) CouchbaseException(com.couchbase.client.core.error.CouchbaseException) QueryErrorContext(com.couchbase.client.core.error.context.QueryErrorContext) QuotaLimitedException(com.couchbase.client.core.error.QuotaLimitedException) ErrorCodeAndMessage(com.couchbase.client.core.error.ErrorCodeAndMessage) ParsingFailureException(com.couchbase.client.core.error.ParsingFailureException) PreparedStatementFailureException(com.couchbase.client.core.error.PreparedStatementFailureException) IndexNotFoundException(com.couchbase.client.core.error.IndexNotFoundException) DmlFailureException(com.couchbase.client.core.error.DmlFailureException) IndexFailureException(com.couchbase.client.core.error.IndexFailureException) CancellationErrorContext(com.couchbase.client.core.error.context.CancellationErrorContext) RateLimitedException(com.couchbase.client.core.error.RateLimitedException) InternalServerFailureException(com.couchbase.client.core.error.InternalServerFailureException)

Example 2 with UnambiguousTimeoutException

use of com.couchbase.client.core.error.UnambiguousTimeoutException in project couchbase-jvm-clients by couchbase.

the class WaitUntilReadyHelper method waitUntilReady.

@Stability.Internal
public static CompletableFuture<Void> waitUntilReady(final Core core, final Set<ServiceType> serviceTypes, final Duration timeout, final ClusterState desiredState, final Optional<String> bucketName) {
    final WaitUntilReadyState state = new WaitUntilReadyState();
    state.transition(WaitUntilReadyStage.CONFIG_LOAD);
    return Flux.interval(Duration.ofMillis(10), core.context().environment().scheduler()).onBackpressureDrop().filter(i -> !(core.configurationProvider().bucketConfigLoadInProgress() || core.configurationProvider().globalConfigLoadInProgress() || (bucketName.isPresent() && core.configurationProvider().collectionRefreshInProgress()) || (bucketName.isPresent() && core.clusterConfig().bucketConfig(bucketName.get()) == null))).filter(i -> {
        // created.
        if (bucketName.isPresent()) {
            state.transition(WaitUntilReadyStage.BUCKET_CONFIG_READY);
            BucketConfig bucketConfig = core.clusterConfig().bucketConfig(bucketName.get());
            long extNodes = bucketConfig.portInfos().stream().filter(p -> p.ports().containsKey(ServiceType.KV)).count();
            long visibleNodes = bucketConfig.nodes().stream().filter(n -> n.services().containsKey(ServiceType.KV)).count();
            return extNodes > 0 && extNodes == visibleNodes;
        } else {
            return true;
        }
    }).flatMap(i -> {
        if (bucketName.isPresent()) {
            state.transition(WaitUntilReadyStage.BUCKET_NODES_HEALTHY);
            // To avoid tmpfails on the bucket, we double check that all nodes from the nodes list are
            // in a healthy status - but for this we need to actually fetch the verbose config, since
            // the terse one doesn't have that status in it.
            GenericManagerRequest request = new GenericManagerRequest(core.context(), () -> new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/pools/default/buckets/" + bucketName.get()), true, null);
            core.send(request);
            return Reactor.wrap(request, request.response(), true).filter(response -> {
                if (response.status() != ResponseStatus.SUCCESS) {
                    return false;
                }
                ObjectNode root = (ObjectNode) Mapper.decodeIntoTree(response.content());
                ArrayNode nodes = (ArrayNode) root.get("nodes");
                long healthy = StreamSupport.stream(nodes.spliterator(), false).filter(node -> node.get("status").asText().equals("healthy")).count();
                return nodes.size() == healthy;
            }).map(ignored -> i);
        } else {
            return Flux.just(i);
        }
    }).take(1).flatMap(aLong -> {
        // to being ready at this point. Bucket level wait until ready is the way to go there.
        if (!bucketName.isPresent() && !core.clusterConfig().hasClusterOrBucketConfig()) {
            state.transition(WaitUntilReadyStage.COMPLETE);
            WaitUntilReadyContext waitUntilReadyContext = new WaitUntilReadyContext(servicesToCheck(core, serviceTypes, bucketName), timeout, desiredState, bucketName, core.diagnostics().collect(Collectors.groupingBy(EndpointDiagnostics::type)), state);
            core.context().environment().eventBus().publish(new WaitUntilReadyCompletedEvent(waitUntilReadyContext, WaitUntilReadyCompletedEvent.Reason.CLUSTER_LEVEL_NOT_SUPPORTED));
            return Flux.empty();
        }
        state.transition(WaitUntilReadyStage.PING);
        final Flux<ClusterState> diagnostics = Flux.interval(Duration.ofMillis(10), core.context().environment().scheduler()).onBackpressureDrop().map(i -> diagnosticsCurrentState(core)).takeUntil(s -> s == desiredState);
        return Flux.concat(ping(core, servicesToCheck(core, serviceTypes, bucketName), timeout, bucketName), diagnostics);
    }).then().timeout(timeout, Mono.defer(() -> {
        WaitUntilReadyContext waitUntilReadyContext = new WaitUntilReadyContext(servicesToCheck(core, serviceTypes, bucketName), timeout, desiredState, bucketName, core.diagnostics().collect(Collectors.groupingBy(EndpointDiagnostics::type)), state);
        CancellationErrorContext errorContext = new CancellationErrorContext(waitUntilReadyContext);
        return Mono.error(new UnambiguousTimeoutException("WaitUntilReady timed out", errorContext));
    }), core.context().environment().scheduler()).doOnSuccess(unused -> {
        state.transition(WaitUntilReadyStage.COMPLETE);
        WaitUntilReadyContext waitUntilReadyContext = new WaitUntilReadyContext(servicesToCheck(core, serviceTypes, bucketName), timeout, desiredState, bucketName, core.diagnostics().collect(Collectors.groupingBy(EndpointDiagnostics::type)), state);
        core.context().environment().eventBus().publish(new WaitUntilReadyCompletedEvent(waitUntilReadyContext, WaitUntilReadyCompletedEvent.Reason.SUCCESS));
    }).toFuture();
}
Also used : CbCollections.isNullOrEmpty(com.couchbase.client.core.util.CbCollections.isNullOrEmpty) UnambiguousTimeoutException(com.couchbase.client.core.error.UnambiguousTimeoutException) HttpVersion(com.couchbase.client.core.deps.io.netty.handler.codec.http.HttpVersion) RequestTarget(com.couchbase.client.core.msg.RequestTarget) CompletableFuture(java.util.concurrent.CompletableFuture) Function(java.util.function.Function) ServiceType(com.couchbase.client.core.service.ServiceType) Duration(java.time.Duration) Map(java.util.Map) Stability(com.couchbase.client.core.annotation.Stability) GenericManagerRequest(com.couchbase.client.core.msg.manager.GenericManagerRequest) StreamSupport(java.util.stream.StreamSupport) BucketConfig(com.couchbase.client.core.config.BucketConfig) ObjectNode(com.couchbase.client.core.deps.com.fasterxml.jackson.databind.node.ObjectNode) CancellationErrorContext(com.couchbase.client.core.error.context.CancellationErrorContext) ArrayNode(com.couchbase.client.core.deps.com.fasterxml.jackson.databind.node.ArrayNode) Reactor(com.couchbase.client.core.Reactor) HttpMethod(com.couchbase.client.core.deps.io.netty.handler.codec.http.HttpMethod) Mapper(com.couchbase.client.core.json.Mapper) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) DefaultFullHttpRequest(com.couchbase.client.core.deps.io.netty.handler.codec.http.DefaultFullHttpRequest) Mono(reactor.core.publisher.Mono) Collectors(java.util.stream.Collectors) ResponseStatus(com.couchbase.client.core.msg.ResponseStatus) TimeUnit(java.util.concurrent.TimeUnit) Flux(reactor.core.publisher.Flux) AtomicLong(java.util.concurrent.atomic.AtomicLong) WaitUntilReadyCompletedEvent(com.couchbase.client.core.cnc.events.core.WaitUntilReadyCompletedEvent) TreeMap(java.util.TreeMap) Optional(java.util.Optional) Core(com.couchbase.client.core.Core) DefaultFullHttpRequest(com.couchbase.client.core.deps.io.netty.handler.codec.http.DefaultFullHttpRequest) ObjectNode(com.couchbase.client.core.deps.com.fasterxml.jackson.databind.node.ObjectNode) UnambiguousTimeoutException(com.couchbase.client.core.error.UnambiguousTimeoutException) BucketConfig(com.couchbase.client.core.config.BucketConfig) GenericManagerRequest(com.couchbase.client.core.msg.manager.GenericManagerRequest) WaitUntilReadyCompletedEvent(com.couchbase.client.core.cnc.events.core.WaitUntilReadyCompletedEvent) ArrayNode(com.couchbase.client.core.deps.com.fasterxml.jackson.databind.node.ArrayNode) CancellationErrorContext(com.couchbase.client.core.error.context.CancellationErrorContext)

Example 3 with UnambiguousTimeoutException

use of com.couchbase.client.core.error.UnambiguousTimeoutException in project connectors-se by Talend.

the class CouchbaseService method openConnection.

public Cluster openConnection(CouchbaseDataStore dataStore) {
    String bootStrapNodes = dataStore.getBootstrapNodes();
    String username = dataStore.getUsername();
    String password = dataStore.getPassword();
    String urls = Arrays.stream(resolveAddresses(bootStrapNodes)).collect(Collectors.joining(","));
    ClusterHolder holder = clustersPool.computeIfAbsent(dataStore, ds -> {
        ClusterEnvironment.Builder envBuilder = ClusterEnvironment.builder();
        if (dataStore.isUseConnectionParameters()) {
            Builder timeoutBuilder = TimeoutConfig.builder();
            dataStore.getConnectionParametersList().forEach(conf -> setTimeout(timeoutBuilder, envBuilder, conf.getParameterName(), parseValue(conf.getParameterValue())));
            envBuilder.timeoutConfig(timeoutBuilder);
        }
        ClusterEnvironment environment = envBuilder.build();
        Cluster cluster = Cluster.connect(urls, ClusterOptions.clusterOptions(username, password).environment(environment));
        try {
            cluster.waitUntilReady(Duration.ofSeconds(3), WaitUntilReadyOptions.waitUntilReadyOptions().desiredState(ClusterState.ONLINE));
        } catch (UnambiguousTimeoutException e) {
            LOG.error(i18n.connectionKO());
            throw new ComponentException(e);
        }
        return new ClusterHolder(environment, cluster);
    });
    holder.use();
    Cluster cluster = holder.getCluster();
    // connection is lazily initialized; need to send actual request to test it
    cluster.buckets().getAllBuckets();
    PingResult pingResult = cluster.ping();
    LOG.debug(i18n.connectedToCluster(pingResult.id()));
    return cluster;
}
Also used : ClusterEnvironment(com.couchbase.client.java.env.ClusterEnvironment) PingResult(com.couchbase.client.core.diagnostics.PingResult) Builder(com.couchbase.client.core.env.TimeoutConfig.Builder) ComponentException(org.talend.sdk.component.api.exception.ComponentException) Cluster(com.couchbase.client.java.Cluster) UnambiguousTimeoutException(com.couchbase.client.core.error.UnambiguousTimeoutException)

Example 4 with UnambiguousTimeoutException

use of com.couchbase.client.core.error.UnambiguousTimeoutException in project couchbase-jvm-clients by couchbase.

the class BaseRequest method cancel.

@Override
public void cancel(final CancellationReason reason, Function<Throwable, Throwable> exceptionTranslator) {
    if (STATE_UPDATER.compareAndSet(this, State.INCOMPLETE, State.CANCELLED)) {
        cancelTimeoutRegistration();
        cancellationReason = reason;
        final Throwable exception;
        final String msg = this.getClass().getSimpleName() + ", Reason: " + reason;
        final CancellationErrorContext ctx = new CancellationErrorContext(context());
        if (reason == CancellationReason.TIMEOUT) {
            exception = idempotent() ? new UnambiguousTimeoutException(msg, ctx) : new AmbiguousTimeoutException(msg, ctx);
        } else {
            exception = new RequestCanceledException(msg, reason, ctx);
        }
        response.completeExceptionally(exceptionTranslator.apply(exception));
    }
}
Also used : RequestCanceledException(com.couchbase.client.core.error.RequestCanceledException) AmbiguousTimeoutException(com.couchbase.client.core.error.AmbiguousTimeoutException) UnambiguousTimeoutException(com.couchbase.client.core.error.UnambiguousTimeoutException) CancellationErrorContext(com.couchbase.client.core.error.context.CancellationErrorContext)

Aggregations

UnambiguousTimeoutException (com.couchbase.client.core.error.UnambiguousTimeoutException)4 CancellationErrorContext (com.couchbase.client.core.error.context.CancellationErrorContext)3 Core (com.couchbase.client.core.Core)1 Reactor (com.couchbase.client.core.Reactor)1 Stability (com.couchbase.client.core.annotation.Stability)1 WaitUntilReadyCompletedEvent (com.couchbase.client.core.cnc.events.core.WaitUntilReadyCompletedEvent)1 BucketConfig (com.couchbase.client.core.config.BucketConfig)1 ArrayNode (com.couchbase.client.core.deps.com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (com.couchbase.client.core.deps.com.fasterxml.jackson.databind.node.ObjectNode)1 DefaultFullHttpRequest (com.couchbase.client.core.deps.io.netty.handler.codec.http.DefaultFullHttpRequest)1 HttpMethod (com.couchbase.client.core.deps.io.netty.handler.codec.http.HttpMethod)1 HttpVersion (com.couchbase.client.core.deps.io.netty.handler.codec.http.HttpVersion)1 PingResult (com.couchbase.client.core.diagnostics.PingResult)1 Builder (com.couchbase.client.core.env.TimeoutConfig.Builder)1 AmbiguousTimeoutException (com.couchbase.client.core.error.AmbiguousTimeoutException)1 AuthenticationFailureException (com.couchbase.client.core.error.AuthenticationFailureException)1 CasMismatchException (com.couchbase.client.core.error.CasMismatchException)1 CouchbaseException (com.couchbase.client.core.error.CouchbaseException)1 DmlFailureException (com.couchbase.client.core.error.DmlFailureException)1 DocumentExistsException (com.couchbase.client.core.error.DocumentExistsException)1