use of com.couchbase.client.core.error.CasMismatchException in project couchbase-jvm-clients by couchbase.
the class QueryChunkResponseParser method errorsToThrowable.
static CouchbaseException errorsToThrowable(final byte[] bytes, HttpResponse header, RequestContext ctx) {
int httpStatus = header != null ? header.status().code() : 0;
final List<ErrorCodeAndMessage> errors = bytes.length == 0 ? Collections.emptyList() : ErrorCodeAndMessage.fromJsonArray(bytes);
QueryErrorContext errorContext = new QueryErrorContext(ctx, errors, httpStatus);
if (errors.size() >= 1) {
ErrorCodeAndMessage codeAndMessage = errors.get(0);
int code = codeAndMessage.code();
String message = codeAndMessage.message();
int reasonCode = codeAndMessage.reason() != null ? (int) codeAndMessage.reason().getOrDefault("code", 0) : 0;
if (code == 3000) {
return new ParsingFailureException(errorContext);
} else if (PREPARED_ERROR_CODES.contains(code)) {
return new PreparedStatementFailureException(errorContext, RETRYABLE_PREPARED_ERROR_CODES.contains(code));
} else if (code == 4300 && message.matches("^.*index .*already exist.*")) {
return new IndexExistsException(errorContext);
} else if (code >= 4000 && code < 5000) {
return new PlanningFailureException(errorContext);
} else if (code == 12004 || code == 12016 || (code == 5000 && message.matches("^.*index .+ not found.*"))) {
return new IndexNotFoundException(errorContext);
} else if (code == 5000 && message.matches("^.*Index .*already exist.*")) {
return new IndexExistsException(errorContext);
} else if (code == 5000 && message.contains("limit for number of indexes that can be created per scope has been reached")) {
return new QuotaLimitedException(errorContext);
} else if (code >= 5000 && code < 6000) {
return new InternalServerFailureException(errorContext);
} else if (code == 12009) {
if (message.contains("CAS mismatch") || reasonCode == 12033) {
return new CasMismatchException(errorContext);
} else if (reasonCode == 17014) {
return new DocumentNotFoundException(errorContext);
} else if (reasonCode == 17012) {
return new DocumentExistsException(errorContext);
} else {
return new DmlFailureException(errorContext);
}
} else if ((code >= 10000 && code < 11000) || code == 13014) {
return new AuthenticationFailureException("Could not authenticate query", errorContext, null);
} else if ((code >= 12000 && code < 13000) || (code >= 14000 && code < 15000)) {
return new IndexFailureException(errorContext);
} else if (code == 1065) {
if (message.contains("query_context")) {
return FeatureNotAvailableException.scopeLevelQuery(ServiceType.QUERY);
}
if (message.contains("preserve_expiry")) {
return FeatureNotAvailableException.queryPreserveExpiry();
}
} else if (code == 1080) {
// engine will proactively send us a timeout and we need to convert it.
return new UnambiguousTimeoutException("Query timed out while streaming/receiving rows", new CancellationErrorContext(errorContext));
} else if (code == 1191 || code == 1192 || code == 1193 || code == 1194) {
return new RateLimitedException(errorContext);
} else if (code == 3230) {
String feature = null;
if (message.contains("Advisor") || message.contains("Advise")) {
feature = "Query Index Advisor";
} else if (message.contains("Window")) {
feature = "Query Window Functions";
}
return FeatureNotAvailableException.communityEdition(feature);
}
}
return new CouchbaseException("Unknown query error", errorContext);
}
use of com.couchbase.client.core.error.CasMismatchException 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.error.CasMismatchException in project couchbase-jvm-clients by couchbase.
the class KeyValueErrorIntegrationTest method verifyUnlockCasMismatch.
/**
* Ignored for the mock because it still returns TMPFAIL (like the old servers)
*/
@Test
@IgnoreWhen(clusterTypes = ClusterType.MOCKED)
void verifyUnlockCasMismatch() {
String id = UUID.randomUUID().toString();
collection.upsert(id, "foo");
GetResult result = collection.getAndLock(id, Duration.ofSeconds(5));
CasMismatchException thrown = assertThrows(CasMismatchException.class, () -> collection.unlock(id, result.cas() + 1));
assertNotNull(thrown.context());
}
use of com.couchbase.client.core.error.CasMismatchException in project couchbase-jvm-clients by couchbase.
the class SubdocMutateIntegrationTest method reviveDocumentWithCAS3.
@IgnoreWhen(missesCapabilities = { Capabilities.SUBDOC_REVIVE_DOCUMENT })
@Test
void reviveDocumentWithCAS3() {
String docId = docId();
JsonObject body = JsonObject.create().put("foo", "bar");
MutateInResult mr = coll.mutateIn(docId, Collections.singletonList(upsert("txn", JsonObject.create().put("stgd", body).put("baz", "qux")).xattr().createPath()), MutateInOptions.mutateInOptions().createAsDeleted(true).accessDeleted(true).storeSemantics(StoreSemantics.INSERT));
// Create a CAS mismatch
coll.insert(docId, JsonObject.create());
try {
coll.mutateIn(docId, Arrays.asList(new ReplaceBodyWithXattr("txn.stgd"), MutateInSpec.remove("txn").xattr()), MutateInOptions.mutateInOptions().accessDeleted(true).cas(mr.cas()).storeSemantics(StoreSemantics.REVIVE));
fail();
} catch (CasMismatchException ignored) {
// It hits this rather than CannotReviveAliveDocumentException
}
}
use of com.couchbase.client.core.error.CasMismatchException in project couchbase-jvm-clients by couchbase.
the class KeyValueErrorIntegrationTest method verifyReplaceExceptions.
@Test
void verifyReplaceExceptions() {
DocumentNotFoundException thrown = assertThrows(DocumentNotFoundException.class, () -> collection.replace(UUID.randomUUID().toString(), "bar"));
assertNotNull(thrown.context());
assertThrows(InvalidArgumentException.class, () -> collection.replace("foo", null));
assertThrows(InvalidArgumentException.class, () -> collection.replace(null, "bar"));
assertThrows(InvalidArgumentException.class, () -> collection.replace("foo", "bar", null));
String id = UUID.randomUUID().toString();
MutationResult result = collection.upsert(id, "bar");
CasMismatchException mismatch = assertThrows(CasMismatchException.class, () -> collection.replace(id, "bar", replaceOptions().cas(result.cas() + 1)));
assertNotNull(mismatch.context());
}
Aggregations