CB server v7.0.5
java sdk v3.4.3/3.6.0
Whenever I am doing replaceWithCas for more than 1 document over single connection, it always fails with CasMismatchException
CasMismatchException: Document has been concurrently modified on the server {"completed":true,"coreId":"0x2929a68a00000001","idempotent":false,"lastChannelId":"2929A68A00000001/00000000E6F0546E","lastDispatchedFrom":"a.b.c.d","lastDispatchedTo":"x.x.x.x:11210","requestId":34,"requestType":"ReplaceRequest","retried":0,"serverDuration":38,"service":{"bucket":"storage-test","collection":"_default","documentId":"5ff7ff4c-fbe9-437e-8bcf-92d198adbe33","errorCode":{"description":"key already exists, or CAS mismatch","name":"KEY_EEXISTS"},"opaque":"0x44","scope":"_default","type":"kv","vbucket":685},"status":"EXISTS","timeoutMs":2500,"timings":{"dispatchMicros":19828,"encodingMicros":38580,"totalDispatchMicros":19828,"totalServerMicros":0,"totalMicros":20927,"serverMicros":0}}
I tried this both using CompletableFutures as well as serial insert of documents. Just before invoking replace, I print the CAS which matches the one in the Get call. Also, I read CAS using N1QL in web console, it gives wrong CAS and ast 2 digits are 0s for all documents. So it looks like the rounding bug is also still not resolved.
Here is the code I use to do replaceWithCas
public Map<String, MutationResult> replaceWithCas(@NotNull ArrayList<CoreIo.Document> replaceDocInput,
Predicate<GetResult> predicate) throws RetryableException {
for (CoreIo.Document doc : replaceDocInput) {
Collection collection =
cbBuckets.get(doc.getBucketName()).getBucket().defaultCollection();
try {
logger.debug("replace_with_cas:" + doc.getKey());
GetResult result = collection.get(doc.getKey());
System.out.println("to replace get doc:"+ result.contentAsObject().toString()+","+ result.cas());
System.out.println("to replace modified doc:"+ result.contentAsObject().toString()+","+ result.cas());
MutationResult res = collection.replace(
doc.getKey(),
doc.getData(),
ReplaceOptions.replaceOptions().cas(doc.getCas())
);
logger.debug("replace_with_cas:success:" + doc.getKey());
logger.debug("replace_with_cas:success:" + res.cas());
} catch (DocumentNotFoundException ex) {
logger.error("replace_with_cas:document not existent:" + doc.getKey());
} catch (Exception ex) {
logger.error("replace_with_cas:exception:" + doc.getKey() + ":" + ex.getMessage());
ex.printStackTrace();
}
}
Map<String, MutationResult> mutationResultMap = new HashMap<>();
logger.debug("replace_with_cas:done");
return mutationResultMap;
}