I am using java sdk (java-client.2.7.6.jar) to update the existing documents in the couchbase.
If i retrieve the document and update the same using java sdk is working fine. But when retrieve document from N1QL query and update it using java sdk is not working.
I am not seeing exceptions. I am getting new CAS value as well in the couchbase upsert api response.
Has anyone faced this issue?
Also, please help me on how to trace this upsert request in couchbase server logs.
Welcome to Couchbase forums @Raghav !
If you are getting a new CAS value, that should mean that the upsert was a success (Data Operations | Couchbase Docs). Having said that, it will help us if you show the code snippet you are using for this exercise. If you can also provide the server and sdk client logs, we can triage it better. What is the server version you are working with?
You should be able to enable tracing for your code using Java SDK 2.7. There are some examples here to do the same: Request Tracing | Couchbase Docs.
Thanks for your reply.
One interesting thing i found is, the changes which happened by sdk upsert command is successful and visible when i query the same document using SDK but the same changes are not visible when i query the document using N1Q1 queryâŚsomething fishy hereâŚ
==SELECT * from bucket
where type=âObjectâ and (objectState = â1â or objectState = â2â) and objectExpiration < $currEpochTime LIMIT $maxlimit"
couchbase server version->6.6.1-9213
N1Q1 Query Code snippet:
===================== doing select * based on expired time
N1qlQueryResult queryResult=null;
Bucket bucket= getBucket(bucketType);
if(placeholderValues != null) {
N1qlParams params = N1qlParams.build();
ParameterizedN1qlQuery query = N1qlQuery.parameterized(qry, placeholderValues, params);
queryResult = bucket.query(query);
}
=======================
tried both ways as stated below.
- JsonObject doc = JsonObject.fromJson(dtoJson);
JsonDocument jsonDoc = JsonDocument.create(objectId, doc);
getBucket().upsert(jsonDoc);
================================================== - jsonDocuments = Observable
.from(docs)
.flatMap(doc â
{
Observable upsert = getBucket(bucketType).async().upsert(doc);
logger.debug(âupsert==>â+upsert);
return upsert;
})
.toList()
.toBlocking()
.single();
SDK debug logs:.
2021-04-17 21:29:02.956 Operations over threshold: [ {
âtopâ : [ {
âoperation_nameâ : âupsertâ,
âserver_usâ : 165,
âlast_local_idâ : â637D4040ADACDB30/FFFFFFFFF8860DC4â,
âencode_usâ : 630,
âlast_local_addressâ : âXXXXXX:58978â,
âlast_remote_addressâ : âXXXXXX:11210â,
âlast_dispatch_usâ : 6564,
âlast_operation_idâ : â0x2bâ,
âtotal_usâ : 60364
} ],
âserviceâ : âkvâ,
âcountâ : 1
} ]
Sounds like it might be a scan consistency issue. If you want to read your own writes, itâs necessary to specify a scan consistency other than the default, since the default prioritizes performance over consistency.
https://docs.couchbase.com/java-sdk/2.7/scan-consistency-examples.html
Yes, with Couchbase you donât have to wait on each write until the indexes are updated. Instead this is done asynchronously, and you choose at the point of the N1QL read how consistent with recent changes you need the indexes to be. E.g. you pay only for what you use.
Thanks alot, with above âscan-consitencyâ, it worked for me