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”))
.onErrorResumeNext(Observable.empty()).toBlocking()
.singleOrDefault(null);

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))).
retryWhen(RetryBuilder.anyOf(CouchbaseException.class,RuntimeException.class).
delay(Delay.exponential(TimeUnit.MILLISECONDS, 30)).max(10).build());

  upsertObservable.toBlocking()
  		.singleOrDefault(null);

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);
}
finally
{
LOGGER.warn(“upsert::Finally called”);
long waitTime = currentAttempts*2000L;
try {
Thread.sleep(waitTime);
} catch (InterruptedException e) {
LOGGER.error(“upsert::Exception occured”, e);
}
currentAttempts++;

    }
  }

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.

@abhishekmbmit is this issue got resolved? i am facing similar issue, with ttl it is failing to upsert where as without ttl it is working fine.

Hey @Sri
This is an old thread so you’re probably best off creating a new one with a full description of the problem, including code snippets and what errors you’re receiving. If it’s always failing with TTL, that sounds different to the problem above anyway, which was intermittent.

Hi @graham.pople ,

Thank you for the quick reply. my issue is also intermittent. It is failing to insert few documents and i am not seeing any error or exceptions.