Search in sources :

Example 6 with CouchbaseException

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

the class ViewChunkResponseParser method signalComplete.

@Override
public void signalComplete() {
    Optional<CouchbaseException> maybeError = error();
    if (maybeError.isPresent()) {
        failRows(maybeError.get());
    } else {
        completeRows();
    }
    completeTrailer(new ViewChunkTrailer(error));
}
Also used : CouchbaseException(com.couchbase.client.core.error.CouchbaseException) ViewChunkTrailer(com.couchbase.client.core.msg.view.ViewChunkTrailer)

Example 7 with CouchbaseException

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

the class AsyncQueryIndexManager method watchIndexes.

/**
 * Watches/Polls indexes until they are online with custom options.
 * <p>
 * By default, this method will watch the indexes on the bucket. If the indexes should be watched on a collection,
 * both {@link WatchQueryIndexesOptions#scopeName(String)} and
 * {@link WatchQueryIndexesOptions#collectionName(String)} must be set.
 *
 * @param bucketName the name of the bucket where the indexes should be watched.
 * @param indexNames the names of the indexes to watch.
 * @param timeout the maximum amount of time the indexes should be watched.
 * @param options the custom options to apply.
 * @return a {@link CompletableFuture} completing when the operation is applied or failed with an error.
 * @throws CouchbaseException (async) if any other generic unhandled/unexpected errors.
 */
public CompletableFuture<Void> watchIndexes(final String bucketName, final Collection<String> indexNames, final Duration timeout, final WatchQueryIndexesOptions options) {
    notNullOrEmpty(bucketName, "BucketName");
    notNull(indexNames, "IndexNames");
    notNull(timeout, "Timeout");
    notNull(options, "Options");
    Set<String> indexNameSet = new HashSet<>(indexNames);
    WatchQueryIndexesOptions.Built builtOpts = options.build();
    RequestSpan parent = cluster.environment().requestTracer().requestSpan(TracingIdentifiers.SPAN_REQUEST_MQ_WATCH_INDEXES, null);
    parent.attribute(TracingIdentifiers.ATTR_SYSTEM, TracingIdentifiers.ATTR_SYSTEM_COUCHBASE);
    return Mono.fromFuture(() -> failIfIndexesOffline(bucketName, indexNameSet, builtOpts.watchPrimary(), parent, builtOpts.scopeName(), builtOpts.collectionName())).retryWhen(Retry.onlyIf(ctx -> hasCause(ctx.exception(), IndexesNotReadyException.class)).exponentialBackoff(Duration.ofMillis(50), Duration.ofSeconds(1)).timeout(timeout).toReactorRetry()).onErrorMap(t -> t instanceof RetryExhaustedException ? toWatchTimeoutException(t, timeout) : t).toFuture().whenComplete((r, t) -> parent.end());
}
Also used : Arrays(java.util.Arrays) Validators.notNull(com.couchbase.client.core.util.Validators.notNull) RetryExhaustedException(com.couchbase.client.core.retry.reactor.RetryExhaustedException) CbThrowables.findCause(com.couchbase.client.core.util.CbThrowables.findCause) TimeoutException(java.util.concurrent.TimeoutException) QueryResult(com.couchbase.client.java.query.QueryResult) Collectors.toMap(java.util.stream.Collectors.toMap) Duration(java.time.Duration) Map(java.util.Map) CbThrowables.throwIfUnchecked(com.couchbase.client.core.util.CbThrowables.throwIfUnchecked) RequestSpan(com.couchbase.client.core.cnc.RequestSpan) READ_ONLY(com.couchbase.client.java.manager.query.AsyncQueryIndexManager.QueryType.READ_ONLY) IndexExistsException(com.couchbase.client.core.error.IndexExistsException) Collectors.toSet(java.util.stream.Collectors.toSet) DropPrimaryQueryIndexOptions.dropPrimaryQueryIndexOptions(com.couchbase.client.java.manager.query.DropPrimaryQueryIndexOptions.dropPrimaryQueryIndexOptions) CbThrowables.hasCause(com.couchbase.client.core.util.CbThrowables.hasCause) Predicate(java.util.function.Predicate) Mapper(com.couchbase.client.core.json.Mapper) Collection(java.util.Collection) Set(java.util.Set) InvalidArgumentException(com.couchbase.client.core.error.InvalidArgumentException) Collectors(java.util.stream.Collectors) Validators.notNullOrEmpty(com.couchbase.client.core.util.Validators.notNullOrEmpty) QueryOptions(com.couchbase.client.java.query.QueryOptions) List(java.util.List) GetAllQueryIndexesOptions.getAllQueryIndexesOptions(com.couchbase.client.java.manager.query.GetAllQueryIndexesOptions.getAllQueryIndexesOptions) RedactableArgument.redactMeta(com.couchbase.client.core.logging.RedactableArgument.redactMeta) Optional(java.util.Optional) WRITE(com.couchbase.client.java.manager.query.AsyncQueryIndexManager.QueryType.WRITE) CreatePrimaryQueryIndexOptions.createPrimaryQueryIndexOptions(com.couchbase.client.java.manager.query.CreatePrimaryQueryIndexOptions.createPrimaryQueryIndexOptions) CreateQueryIndexOptions.createQueryIndexOptions(com.couchbase.client.java.manager.query.CreateQueryIndexOptions.createQueryIndexOptions) Retry(com.couchbase.client.core.retry.reactor.Retry) CouchbaseException(com.couchbase.client.core.error.CouchbaseException) CompletableFuture(java.util.concurrent.CompletableFuture) WatchQueryIndexesOptions.watchQueryIndexesOptions(com.couchbase.client.java.manager.query.WatchQueryIndexesOptions.watchQueryIndexesOptions) QueryException(com.couchbase.client.core.error.QueryException) Function(java.util.function.Function) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) CommonOptions(com.couchbase.client.java.CommonOptions) TracingIdentifiers(com.couchbase.client.core.cnc.TracingIdentifiers) Objects.requireNonNull(java.util.Objects.requireNonNull) Stability(com.couchbase.client.core.annotation.Stability) IndexFailureException(com.couchbase.client.core.error.IndexFailureException) IndexesNotReadyException(com.couchbase.client.core.error.IndexesNotReadyException) DropQueryIndexOptions.dropQueryIndexOptions(com.couchbase.client.java.manager.query.DropQueryIndexOptions.dropQueryIndexOptions) Reactor(com.couchbase.client.core.Reactor) IndexNotFoundException(com.couchbase.client.core.error.IndexNotFoundException) Mono(reactor.core.publisher.Mono) JsonArray(com.couchbase.client.java.json.JsonArray) Collectors.toList(java.util.stream.Collectors.toList) BuildQueryIndexOptions.buildDeferredQueryIndexesOptions(com.couchbase.client.java.manager.query.BuildQueryIndexOptions.buildDeferredQueryIndexesOptions) AsyncCluster(com.couchbase.client.java.AsyncCluster) RetryExhaustedException(com.couchbase.client.core.retry.reactor.RetryExhaustedException) HashSet(java.util.HashSet) RequestSpan(com.couchbase.client.core.cnc.RequestSpan)

Example 8 with CouchbaseException

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

the class AnalyticsChunkResponseParser method errorsToThrowable.

@Stability.Internal
static CouchbaseException errorsToThrowable(final byte[] bytes, RequestContext ctx, HttpResponseStatus httpStatus) {
    int httpCode = httpStatus != null ? httpStatus.code() : 0;
    final List<ErrorCodeAndMessage> errors = bytes.length == 0 ? Collections.emptyList() : ErrorCodeAndMessage.from(bytes);
    AnalyticsErrorContext errorContext = new AnalyticsErrorContext(ctx, errors, httpCode);
    if (errors.size() >= 1) {
        ErrorCodeAndMessage error = errors.get(0);
        // Analytics error code reference:
        // https://docs.couchbase.com/server/current/analytics/error-codes.html
        int code = error.code();
        if (code >= 25000 && code < 26000) {
            return new InternalServerFailureException(errorContext);
        } else if (code >= 20000 && code < 21000) {
            return new AuthenticationFailureException("Could not authenticate analytics query", errorContext, null);
        } else if (code == 23000 || code == 23003) {
            return new TemporaryFailureException(errorContext);
        } else if (code == 23007) {
            return new JobQueueFullException(errorContext);
        } else if (code == 24000) {
            return new ParsingFailureException(errorContext);
        } else if (code == 24006) {
            return new LinkNotFoundException(errorContext);
        } else if (code == 24055) {
            return new LinkExistsException(errorContext);
        } else if (code == 24040) {
            return new DatasetExistsException(errorContext);
        } else if (code == 24044 || code == 24045 || code == 24025) {
            return new DatasetNotFoundException(errorContext);
        } else if (code == 24034) {
            return new DataverseNotFoundException(errorContext);
        } else if (code == 24039) {
            return new DataverseExistsException(errorContext);
        } else if (code == 24047) {
            return new IndexNotFoundException(errorContext);
        } else if (code == 24048) {
            return new IndexExistsException(errorContext);
        } else if (code > 24000 && code < 25000) {
            return new CompilationFailureException(errorContext);
        } else {
            return new CouchbaseException("Unknown analytics error: " + error, errorContext);
        }
    }
    return new CouchbaseException("Unknown analytics error", errorContext);
}
Also used : AnalyticsErrorContext(com.couchbase.client.core.error.context.AnalyticsErrorContext) DataverseNotFoundException(com.couchbase.client.core.error.DataverseNotFoundException) DataverseExistsException(com.couchbase.client.core.error.DataverseExistsException) IndexExistsException(com.couchbase.client.core.error.IndexExistsException) TemporaryFailureException(com.couchbase.client.core.error.TemporaryFailureException) LinkNotFoundException(com.couchbase.client.core.error.LinkNotFoundException) AuthenticationFailureException(com.couchbase.client.core.error.AuthenticationFailureException) CompilationFailureException(com.couchbase.client.core.error.CompilationFailureException) DatasetExistsException(com.couchbase.client.core.error.DatasetExistsException) CouchbaseException(com.couchbase.client.core.error.CouchbaseException) JobQueueFullException(com.couchbase.client.core.error.JobQueueFullException) ErrorCodeAndMessage(com.couchbase.client.core.error.ErrorCodeAndMessage) ParsingFailureException(com.couchbase.client.core.error.ParsingFailureException) IndexNotFoundException(com.couchbase.client.core.error.IndexNotFoundException) DatasetNotFoundException(com.couchbase.client.core.error.DatasetNotFoundException) LinkExistsException(com.couchbase.client.core.error.LinkExistsException) InternalServerFailureException(com.couchbase.client.core.error.InternalServerFailureException)

Example 9 with CouchbaseException

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

the class ChunkedMessageHandler method maybeCompleteResponseWithFailure.

private void maybeCompleteResponseWithFailure() {
    if (!currentRequest.completed()) {
        final CouchbaseException cause = chunkResponseParser.decodingFailure().orElseGet(() -> chunkResponseParser.error().orElseGet(() -> new CouchbaseException("Request failed, but no more information available")));
        Optional<RetryReason> qualifies = qualifiesForRetry(cause);
        if (qualifies.isPresent()) {
            RetryOrchestrator.maybeRetry(ioContext, currentRequest, qualifies.get());
        } else {
            currentRequest.fail(cause);
        }
    } else {
        ioContext.environment().orphanReporter().report(currentRequest);
    }
}
Also used : CouchbaseException(com.couchbase.client.core.error.CouchbaseException) RetryReason(com.couchbase.client.core.retry.RetryReason)

Example 10 with CouchbaseException

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

the class DefaultConfigurationProvider method refreshCollectionId.

@Override
public synchronized void refreshCollectionId(final CollectionIdentifier identifier) {
    if (collectionRefreshInProgress(identifier)) {
        eventBus.publish(new CollectionMapRefreshIgnoredEvent(core.context(), identifier));
        return;
    }
    collectionMapRefreshInProgress.add(identifier);
    long start = System.nanoTime();
    GetCollectionIdRequest request = new GetCollectionIdRequest(core.context().environment().timeoutConfig().kvTimeout(), core.context(), BestEffortRetryStrategy.INSTANCE, identifier);
    core.send(request);
    request.response().whenComplete((response, throwable) -> {
        try {
            final Duration duration = Duration.ofNanos(System.nanoTime() - start);
            if (throwable != null) {
                eventBus.publish(new CollectionMapRefreshFailedEvent(duration, core.context(), identifier, throwable, CollectionMapRefreshFailedEvent.Reason.FAILED));
                return;
            }
            if (response.status().success()) {
                if (response.collectionId().isPresent()) {
                    long cid = response.collectionId().get();
                    collectionMap.put(identifier, UnsignedLEB128.encode(cid));
                    eventBus.publish(new CollectionMapRefreshSucceededEvent(duration, core.context(), identifier, cid));
                } else {
                    eventBus.publish(new CollectionMapRefreshFailedEvent(duration, core.context(), identifier, null, CollectionMapRefreshFailedEvent.Reason.COLLECTION_ID_NOT_PRESENT));
                }
            } else {
                Throwable cause = null;
                CollectionMapRefreshFailedEvent.Reason reason;
                if (response.status() == ResponseStatus.UNKNOWN || response.status() == ResponseStatus.NO_COLLECTIONS_MANIFEST) {
                    reason = CollectionMapRefreshFailedEvent.Reason.NOT_SUPPORTED;
                } else if (response.status() == ResponseStatus.UNKNOWN_COLLECTION) {
                    reason = CollectionMapRefreshFailedEvent.Reason.UNKNOWN_COLLECTION;
                } else if (response.status() == ResponseStatus.UNKNOWN_SCOPE) {
                    reason = CollectionMapRefreshFailedEvent.Reason.UNKNOWN_SCOPE;
                } else if (response.status() == ResponseStatus.INVALID_REQUEST) {
                    reason = CollectionMapRefreshFailedEvent.Reason.INVALID_REQUEST;
                } else {
                    cause = new CouchbaseException(response.toString());
                    reason = CollectionMapRefreshFailedEvent.Reason.UNKNOWN;
                }
                eventBus.publish(new CollectionMapRefreshFailedEvent(duration, core.context(), identifier, cause, reason));
            }
        } finally {
            collectionMapRefreshInProgress.remove(identifier);
        }
    });
}
Also used : CouchbaseException(com.couchbase.client.core.error.CouchbaseException) CollectionMapRefreshSucceededEvent(com.couchbase.client.core.cnc.events.config.CollectionMapRefreshSucceededEvent) CollectionMapRefreshFailedEvent(com.couchbase.client.core.cnc.events.config.CollectionMapRefreshFailedEvent) Duration(java.time.Duration) GetCollectionIdRequest(com.couchbase.client.core.msg.kv.GetCollectionIdRequest) CollectionMapRefreshIgnoredEvent(com.couchbase.client.core.cnc.events.config.CollectionMapRefreshIgnoredEvent)

Aggregations

CouchbaseException (com.couchbase.client.core.error.CouchbaseException)46 DocumentNotFoundException (com.couchbase.client.core.error.DocumentNotFoundException)8 Test (org.junit.jupiter.api.Test)8 ByteBuf (com.couchbase.client.core.deps.io.netty.buffer.ByteBuf)7 CasMismatchException (com.couchbase.client.core.error.CasMismatchException)7 RetryExhaustedException (com.couchbase.client.core.retry.reactor.RetryExhaustedException)7 LookupInResult (com.couchbase.client.java.kv.LookupInResult)7 JavaIntegrationTest (com.couchbase.client.java.util.JavaIntegrationTest)7 Duration (java.time.Duration)7 IgnoreWhen (com.couchbase.client.test.IgnoreWhen)6 ArrayList (java.util.ArrayList)6 AuthenticationFailureException (com.couchbase.client.core.error.AuthenticationFailureException)5 RateLimitedException (com.couchbase.client.core.error.RateLimitedException)5 IndexNotFoundException (com.couchbase.client.core.error.IndexNotFoundException)4 UnambiguousTimeoutException (com.couchbase.client.core.error.UnambiguousTimeoutException)4 PathNotFoundException (com.couchbase.client.core.error.subdoc.PathNotFoundException)4 JsonObject (com.couchbase.client.java.json.JsonObject)4 SearchIndex (com.couchbase.client.java.manager.search.SearchIndex)4 List (java.util.List)4 RequestSpan (com.couchbase.client.core.cnc.RequestSpan)3