Uploaded image for project: 'Couchbase C client library libcouchbase'
  1. Couchbase C client library libcouchbase
  2. CCBC-1382

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

    XMLWordPrintable

Details

    • Bug
    • Status: Resolved
    • Critical
    • Resolution: Fixed
    • 3.1.0
    • 3.1.1
    • None
    • 1

    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).

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          Michael Nitschinger can you give this a first pass look?

          ingenthr Matt Ingenthron added a comment - Michael Nitschinger can you give this a first pass look?

          Ankit Prabhu I think you are right. Just to double check, how are you setting your lcb_cmdsubdoc_store_semantics from eventing?

          daschl Michael Nitschinger added a comment - Ankit Prabhu I think you are right. Just to double check, how are you setting your lcb_cmdsubdoc_store_semantics from eventing?
          ankit.prabhu Ankit Prabhu added a comment -

            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

          ankit.prabhu Ankit Prabhu added a comment - 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

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

          daschl Michael Nitschinger added a comment - Ankit Prabhu which error were you getting previously with LCB 2 in this situation?
          ankit.prabhu Ankit Prabhu added a comment -

          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.

          ankit.prabhu Ankit Prabhu added a comment - 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.

          Ankit Prabhu 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).

          daschl Michael Nitschinger added a comment - Ankit Prabhu 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).

          Build couchbase-server-7.0.0-5043 contains libcouchbase commit 4cec4c6 with commit message:
          CCBC-1382: fix error translation for requests with REPLACE semantics

          build-team Couchbase Build Team added a comment - Build couchbase-server-7.0.0-5043 contains libcouchbase commit 4cec4c6 with commit message: CCBC-1382 : fix error translation for requests with REPLACE semantics

          People

            avsej Sergey Avseyev
            ankit.prabhu Ankit Prabhu
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes

                PagerDuty