CasMismatchException handling in JAVA SDK 3.1

Hello, periodically I get this exception in server log:

com.couchbase.client.core.error.CasMismatchException: Document has been concurrently modified on the server {“completed”:true,“coreId”:“0x10d33d1f00000001”,“errors”:[{“code”:12009,“message”:"DML Error, possible causes include CAS mismatch or concurrent modificationFailed to perform update - cause: MCResponse status=KEY_EEXISTS, opcode=SET, opaque=0, msg: "}],“idempotent”:false,“lastDispatchedFrom”:“”,“lastDispatchedTo”:“localhost:8093”,“requestId”:20964,“requestType”:“QueryRequest”,“retried”:0,“service”:{“operationId”:“ea6ef1e3-1c7b-4e61-ab8d-00e8b8d96a23”,“statement”:“UPDATE … SET …”,“type”:“query”},“timeoutMs”:16000,“timings”:{“dispatchMicros”:43773,“totalMicros”:127352}}

I want to implement global retry strategy in ClusterEnvironment for this request. According to this documentation: Handling Errors | Couchbase Docs I create custom retry strategy on top of BestEffortRetryStrategy, but I cannot find any way to access ErrorContext with many useful information such as retry count and last retry time (described in last paragraph on documentation page, probably, this part removed in SDK 3.+, but still present in docs?),.
Also there is no CasMismatchException in RetryReason reference, so could you please help me implement retry strategy in such case of error based on previous retry count and its timings.


Hi @Poltar
On a CAS mismatch you need to redo the document read and then mutate it again. So it’s not possible to handle this with a RetryStrategy, as that can only deal with failures involving a single operation (see just the read or just the mutation). Instead it needs to be handled in the application with a retry loop.