use of com.couchbase.client.core.retry.reactor.RetryExhaustedException in project couchbase-jvm-clients by couchbase.
the class CouchbaseMap method put.
@Override
public E put(String key, E value) {
checkKey(key);
for (int i = 0; i < mapOptions.casMismatchRetries(); i++) {
try {
long returnCas = 0;
E result = null;
try {
LookupInResult current = collection.lookupIn(id, Collections.singletonList(LookupInSpec.get(key)), lookupInOptions);
returnCas = current.cas();
if (current.exists(0)) {
result = current.contentAs(0, entityTypeClass);
}
} catch (PathNotFoundException e) {
// that's ok, we will just upsert anyways, and return null
} catch (DocumentNotFoundException e) {
// we will create an empty doc and remember the cas
returnCas = createEmpty();
}
collection.mutateIn(id, Collections.singletonList(MutateInSpec.upsert(key, value)), mapOptions.mutateInOptions().cas(returnCas));
return result;
} catch (CasMismatchException ex) {
// will need to retry get-and-set
}
}
throw new CouchbaseException("CouchbaseMap put failed", new RetryExhaustedException("Couldn't perform put in less than " + mapOptions.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 CouchbaseQueue method poll.
@Override
public E poll() {
// FIFO queue as offer uses ARRAY_PREPEND
String idx = "[-1]";
for (int i = 0; i < queueOptions.casMismatchRetries(); i++) {
try {
LookupInResult result = collection.lookupIn(id, Collections.singletonList(LookupInSpec.get(idx)), lookupInOptions);
E current = result.contentAs(0, entityTypeClass);
long returnCas = result.cas();
collection.mutateIn(id, Collections.singletonList(MutateInSpec.remove(idx)), queueOptions.mutateInOptions().cas(returnCas));
return current;
} catch (DocumentNotFoundException | PathNotFoundException ex) {
return null;
} catch (CasMismatchException ex) {
// will have to retry get-and-remove
}
}
throw new CouchbaseException("CouchbaseQueue poll failed", new RetryExhaustedException("Couldn't perform poll in less than " + queueOptions.casMismatchRetries() + " iterations. It is likely concurrent modifications of this document are the reason"));
}
Aggregations