Insert through subdoc operations gives cas mismatch error when document already exist

Description

Libcouchbase returns Cas mismatch error for insert done through subdoc operations(lcb_subdoc).
https://github.com/couchbase/libcouchbase/blob/ed8b57e731e04e2749393c8bed8f9eb88d5d663d/src/handler.cc#L264
Here libcouchbase checks for opcode as CMD_ADD(0x02) but subdoc operation set opcode to MULTI_MUTATE(0xd1) and insert/replace/upsert is set as command flags.
https://github.com/couchbase/libcouchbase/blob/ed8b57e731e04e2749393c8bed8f9eb88d5d663d/src/operations/subdoc.cc#L871

This issue breaks backward compatibility for eventing. And also shows different behaviour in 7.0.0 with different bucket binding insert(which uses normal lcb_store insert) and source bucket binding insert(which uses lcb_subdoc insert).

Environment

None

Gerrit Reviews

None

Release Notes Description

None

Activity

Show:

CB robot April 27, 2021 at 6:58 AM

Build couchbase-server-7.0.0-5043 contains libcouchbase commit 4cec4c6 with commit message:
https://couchbasecloud.atlassian.net/browse/CCBC-1382#icft=CCBC-1382: fix error translation for requests with REPLACE semantics

Michael Nitschinger March 11, 2021 at 12:15 PM

until we get this sorted out, as a workaround (since this is marked as critical) you can map the LCB_ERR_CAS_MISMATCH to LCB_ERR_DOCUMENT_EXISTS for yourself, since a cas mismatch is only relevant on replace - so even once this is fixed up the workaround should not cause problems (since then it just should not show up anymore).

Ankit Prabhu March 11, 2021 at 10:39 AM

For insert if document is already present libcouchbase 2.x gives LCB_KEY_EEXISTS for both subdoc and store operations.

In 3.1.0 lcb_store gives "LCB_ERR_DOCUMENT_EXISTS" which is expected if document already present in the bucket/collection for insert operation. But lcb_subdoc gives "LCB_ERR_CAS_MISMATCH" for insert operation.

Michael Nitschinger March 11, 2021 at 10:32 AM

which error were you getting previously with LCB 2 in this situation?

Ankit Prabhu March 11, 2021 at 10:30 AM

lcb_cmdsubdoc_store_semantics(cmd, op_type);

We set the op_type based on customer function. For couchbase.insert function and if its on source bucket, op_type is set to LCB_SUBDOC_STORE_INSERT

https://github.com/couchbase/eventing/blob/bdd5bf6acf593fcd0e887c2daed1cbfcb994f5bd/features/src/bucket.cc#L415

Fixed
Pinned fields
Click on the next to a field label to start pinning.

Details

Assignee

Fix versions

Story Points

Labels

Reporter

Affects versions

Priority

Instabug

Open Instabug

PagerDuty

Sentry

Zendesk Support

Created March 11, 2021 at 4:16 AM
Updated April 27, 2021 at 6:58 AM
Resolved March 16, 2021 at 3:41 PM
Instabug