use of com.couchbase.client.core.retry.reactor.RetryExhaustedException 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.retry.reactor.RetryExhaustedException in project couchbase-jvm-clients by couchbase.
the class CouchbaseArrayList method set.
@Override
public E set(int index, E element) {
// fail fast on negative values, as they are interpreted as "starting from the back of the array" otherwise
if (index < 0) {
throw new IndexOutOfBoundsException("Index: " + index);
}
String idx = "[" + index + "]";
for (int i = 0; i < arrayListOptions.casMismatchRetries(); i++) {
try {
LookupInResult current = collection.lookupIn(id, Collections.singletonList(LookupInSpec.get(idx)), lookupInOptions);
long returnCas = current.cas();
// this loop ensures we return exactly what we replaced
final E result = current.contentAs(0, entityTypeClass);
collection.mutateIn(id, Collections.singletonList(MutateInSpec.replace(idx, element)), arrayListOptions.mutateInOptions().cas(returnCas));
return result;
} catch (DocumentNotFoundException e) {
createEmptyList();
} catch (CasMismatchException ex) {
// will need to retry get-and-set
} catch (PathNotFoundException ex) {
throw new IndexOutOfBoundsException("Index: " + index);
}
}
throw new CouchbaseException("CouchbaseArrayList set failed", new RetryExhaustedException("Couldn't perform set in less than " + arrayListOptions.casMismatchRetries() + " iterations. It is likely concurrent modifications of this document are the reason"));
}
use of com.couchbase.client.core.retry.reactor.RetryExhaustedException in project couchbase-jvm-clients by couchbase.
the class CouchbaseArrayList method remove.
@Override
public E remove(int index) {
// fail fast on negative values, as they are interpreted as "starting from the back of the array" otherwise
if (index < 0) {
throw new IndexOutOfBoundsException("Index: " + index);
}
String idx = "[" + index + "]";
for (int i = 0; i < arrayListOptions.casMismatchRetries(); i++) {
try {
// this loop will allow us to _know_ what element we really did remove.
LookupInResult current = collection.lookupIn(id, Collections.singletonList(LookupInSpec.get(idx)), lookupInOptions);
long returnCas = current.cas();
E result = current.contentAs(0, entityTypeClass);
collection.mutateIn(id, Collections.singletonList(MutateInSpec.remove(idx)), arrayListOptions.mutateInOptions().cas(returnCas));
return result;
} catch (DocumentNotFoundException e) {
// ArrayList will throw if underlying list was cleared before a remove.
throw new IndexOutOfBoundsException("Index:" + index);
} catch (CasMismatchException ex) {
// will have to retry get-and-remove
} catch (PathNotFoundException e) {
throw new IndexOutOfBoundsException("Index: " + index);
}
}
throw new CouchbaseException("CouchbaseArrayList remove failed", new RetryExhaustedException("Couldn't perform remove in less than " + arrayListOptions.casMismatchRetries() + " iterations. It is likely concurrent modifications of this document are the reason"));
}
use of com.couchbase.client.core.retry.reactor.RetryExhaustedException in project couchbase-jvm-clients by couchbase.
the class CouchbaseArraySet method remove.
@Override
public boolean remove(Object t) {
enforcePrimitive(t);
for (int i = 0; i < arraySetOptions.casMismatchRetries(); i++) {
try {
GetResult result = collection.get(id);
JsonArray current = result.contentAsArray();
long cas = result.cas();
int index = 0;
boolean found = false;
for (Object next : current) {
if (safeEquals(next, t)) {
found = true;
break;
}
index++;
}
String path = "[" + index + "]";
if (!found) {
return false;
} else {
collection.mutateIn(id, Collections.singletonList(MutateInSpec.remove(path)), arraySetOptions.mutateInOptions().cas(cas));
return true;
}
} catch (CasMismatchException e) {
// retry
} catch (DocumentNotFoundException ex) {
return false;
}
}
throw new CouchbaseException("CouchbaseArraySet remove failed", new RetryExhaustedException("Couldn't perform remove in less than " + arraySetOptions.casMismatchRetries() + " iterations. It is likely concurrent modifications of this document are the reason"));
}
use of com.couchbase.client.core.retry.reactor.RetryExhaustedException in project couchbase-jvm-clients by couchbase.
the class CouchbaseMap method remove.
@Override
public E remove(Object key) {
String idx = checkKey(key);
for (int i = 0; i < mapOptions.casMismatchRetries(); i++) {
try {
LookupInResult current = collection.lookupIn(id, Collections.singletonList(LookupInSpec.get(idx)), lookupInOptions);
long returnCas = current.cas();
E result = current.contentAs(0, entityTypeClass);
collection.mutateIn(id, Collections.singletonList(MutateInSpec.remove(idx)), mapOptions.mutateInOptions().cas(returnCas));
return result;
} catch (DocumentNotFoundException | PathNotFoundException e) {
return null;
} catch (CasMismatchException ex) {
// will have to retry get-and-remove
}
}
throw new CouchbaseException("CouchbaseMap remove failed", new RetryExhaustedException("Couldn't perform remove in less than " + mapOptions.casMismatchRetries() + " iterations. It is likely concurrent modifications of this document are the reason"));
}
Aggregations