Intermittently Silent Failure in Upsert while upserting documents Java SDK 2.5.6



I am this code for saving single couchbase document.

Observable inserted = couchbaseBucket.async()
.upsert(RawJsonDocument.create(documentId, expirationTime, convertObjectToJson(object)));

inserted.doOnError(erros -> LOGGER.error(“saveOrUpdate::Error while saving document”, erros))
.doOnCompleted(() -> LOGGER.debug(“saveOrUpdate::Save Successfully”))

This works fine most of the time, but sometimes it doesn’t save the document. And more surprisingly doesn’t return any error. Neither on complete block gets called.

I even tried retry logic to make it failsafe like mentioned below but results are same

Observable upsertObservable = couchbaseBucket.async()
.upsert(RawJsonDocument.create(documentId, expirationTime, convertObjectToJson(object))).
delay(Delay.exponential(TimeUnit.MILLISECONDS, 30)).max(10).build());


Please point if I am doing anything wrong?


If you use the blocking API, does it work as expected? Also, what is your expirationTime set to?


Expiration is set to 30 days for now. Upsert works as expected in most of cases but in all cases. I doubt if it’s because of blocking API because I’ve tried sync API as well. It has same problem of intermittent failure that too silent ones.


can you try not setting a TTL and seeing if the issue persists?


Tried after removing TTL, but it didn’t work.
Also, implemented retry logic on the basis of mutationToken like this

RawJsonDocument upsertDoc = null;
LOGGER.warn(“upsert::cb upsert document with id {} (sync)”+ documentId);
int currentAttempts = 0;
int maxAttemptAllowed = 3;
while(currentAttempts<maxAttemptAllowed && (upsertDoc==null || upsertDoc.mutationToken()==null)) {
try {
LOGGER.warn(“upsert::cb upsert document with attempt number–”+ currentAttempts);
upsertDoc = couchbaseBucket.
upsert(RawJsonDocument.create(documentId, convertObjectToJson(object)));
catch (Exception e) {
LOGGER.error(“upsert::exception while saving object”, e);
LOGGER.warn(“upsert::Finally called”);
long waitTime = currentAttempts*2000L;
try {
} catch (InterruptedException e) {
LOGGER.error(“upsert::Exception occured”, e);


and Enabled mutationToken

CouchbaseEnvironment env = DefaultCouchbaseEnvironment.builder().mutationTokensEnabled(true).build();
cluster = CouchbaseCluster.create(env,serverHostName);

In this block of code, retrying upsert if mutationToken is not changed.
Unfortunatly this didn’t work either. In the scenario where save didn’t work, 2nd attempt was never triggered.