Search in sources :

Example 6 with RetryExhaustedException

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"));
}
Also used : LookupInResult(com.couchbase.client.java.kv.LookupInResult) CouchbaseException(com.couchbase.client.core.error.CouchbaseException) DocumentNotFoundException(com.couchbase.client.core.error.DocumentNotFoundException) RetryExhaustedException(com.couchbase.client.core.retry.reactor.RetryExhaustedException) CasMismatchException(com.couchbase.client.core.error.CasMismatchException) PathNotFoundException(com.couchbase.client.core.error.subdoc.PathNotFoundException)

Example 7 with RetryExhaustedException

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"));
}
Also used : LookupInResult(com.couchbase.client.java.kv.LookupInResult) CouchbaseException(com.couchbase.client.core.error.CouchbaseException) DocumentNotFoundException(com.couchbase.client.core.error.DocumentNotFoundException) RetryExhaustedException(com.couchbase.client.core.retry.reactor.RetryExhaustedException) CasMismatchException(com.couchbase.client.core.error.CasMismatchException) PathNotFoundException(com.couchbase.client.core.error.subdoc.PathNotFoundException)

Aggregations

CouchbaseException (com.couchbase.client.core.error.CouchbaseException)7 RetryExhaustedException (com.couchbase.client.core.retry.reactor.RetryExhaustedException)7 CasMismatchException (com.couchbase.client.core.error.CasMismatchException)6 DocumentNotFoundException (com.couchbase.client.core.error.DocumentNotFoundException)6 PathNotFoundException (com.couchbase.client.core.error.subdoc.PathNotFoundException)5 LookupInResult (com.couchbase.client.java.kv.LookupInResult)5 JsonArray (com.couchbase.client.java.json.JsonArray)2 Reactor (com.couchbase.client.core.Reactor)1 Stability (com.couchbase.client.core.annotation.Stability)1 RequestSpan (com.couchbase.client.core.cnc.RequestSpan)1 TracingIdentifiers (com.couchbase.client.core.cnc.TracingIdentifiers)1 IndexExistsException (com.couchbase.client.core.error.IndexExistsException)1 IndexFailureException (com.couchbase.client.core.error.IndexFailureException)1 IndexNotFoundException (com.couchbase.client.core.error.IndexNotFoundException)1 IndexesNotReadyException (com.couchbase.client.core.error.IndexesNotReadyException)1 InvalidArgumentException (com.couchbase.client.core.error.InvalidArgumentException)1 QueryException (com.couchbase.client.core.error.QueryException)1 Mapper (com.couchbase.client.core.json.Mapper)1 RedactableArgument.redactMeta (com.couchbase.client.core.logging.RedactableArgument.redactMeta)1 Retry (com.couchbase.client.core.retry.reactor.Retry)1