Couchbase CAS value

Hi Team,
we are trying to get CAS value for a given CB document we see some differences. When we get the document from Java SDK and get the CAS value it is displaying different value than the actual document meta cas value. any reason why is this different coming up?

CAS - actual CB - under meta - 0x0000776f93608316
from Getdocument API - 1622246483560562688

Thanks.

Hi @nagarajan_subbaraj ,

Thanks for posting! I’ve got some questions that might help us get to the root of the issue.

Can you please explain in a bit more detail how you are getting the “CAS - actual CB - under meta” ?

Can you share the code you’re using to fetch the CAS values?

Also, what versions of Couchbase Server and the Java SDK are we talking about?

Is Sync Gateway involved somehow?

Thanks,
David

1 Like

Additionally to what @david.nault had asked.

I am also curious when you say CAS - actual CB - under meta which attr are you referring to here ?

Hi David,
To get the CAS value under meta attribute we are using below,

 LookupInResult result = srcColl.lookupIn("XXXXX::YYYYYY",
			 Collections.singletonList(LookupInSpec.get("_sync.cas").xattr()));
	System.out.println("CAS:"+result.contentAs(0, String.class));

To get CAS value from getResult,
GetResult srcDoc = srcColl.get(“XXXXX::YYYYYY”);
System.out.println(srcDoc.toString());
System.out.println(srcDoc.cas());

CB version - 6.6
SDK version - 3.0.10

Yes syncgw is also involved - because these documents will synced to mobile devices, but no change/update from mobile devices, only read is allowed.

1 Like

_sync.cas is an internal property, and is only intended for use by Sync Gateway. You shouldn’t be relying on that for any SDK CAS functionality.

1 Like

Hi Adam,
ok then can we relay on what ever we get from getresult-> cas ? how is this value is getting generated. Is there internal value stored in document level? just for our understanding.

Thanks.

_sync.cas is used internally as part of Sync Gateway’s import processing, and isn’t part of the CAS check used for SDK operations. It’s stored in a system xattr (which is why you see it in meta), but it’s not intended (or required) for use by anyone other than Sync Gateway.

Hi Adam,
How SDK CAS value is getting generated?

Thanks.

Hi @nagarajan_subbaraj ,

Couchbase Server assigns a new CAS value whenever a document is modified in any way. To quote Graham Pople,

Thanks,
David