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));
}
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());
}
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);
}
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);
}
}
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);
}
});
}
Aggregations