Uploaded image for project: 'Couchbase Server'
  1. Couchbase Server
  2. MB-50425

Subdoc: Race in checking for already-existing Deleted document with Add|CreateAsDeleted

    XMLWordPrintable

Details

    • Triaged
    • 1
    • No
    • KV 2022-Jan, KV Oct 2022

    Description

      Something that I've spotted in our transactions testing is that when we try to insert the same document multiple times concurrently, we expect all but one of those operations to fail with DocumentExistsException - but intermittently both succeed.

      I've been able to replicate this in a simplified form outside of transactions, and found that it only happens if durability is enabled:

        @RepeatedTest(5000)
        void insertConflictDetected() throws InterruptedException {
          String id = UUID.randomUUID().toString();
          AtomicInteger errorCount = new AtomicInteger();
       
          Runnable r = () -> {
            try {
              collection.mutateIn(id, Arrays.asList(
                              MutateInSpec.upsert("txn", JsonObject.create()).xattr().createPath(),
                      MutateInSpec.upsert("txn.op.crc32", MutateInMacro.VALUE_CRC_32C).xattr()),
                      mutateInOptions()
                              // If next line is removed, test passes
                              .durability(DurabilityLevel.MAJORITY)
                              .storeSemantics(StoreSemantics.INSERT)
                              .accessDeleted(true)
                              .createAsDeleted(true)
              );
            } catch (DocumentExistsException err) {
              errorCount.incrementAndGet();
            }
            catch (RuntimeException err) {
              fail();
            }
          };
       
          Thread t1 = new Thread(r);
          Thread t2 = new Thread(r);
       
          t1.start();
          t2.start();
          t1.join();
          t2.join();
          // Intermittently this fails as errorCount is 0 - both operations have succeeded
          assertEquals(1, errorCount.get());
        } 

      The exact MutateInSpec specs sent don't appear to matter.  There may be some correlation between the number of specs sent and how frequently the issue occurs. With the two specs in the test, both operations succeed roughly 50% of the time.  If I just send the first spec it's much rarer - about 1 in 1000 times.

      I'm testing with 7.1.0 build 2021.

      Attachments

        Issue Links

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

          Activity

            People

              ashwin.govindarajulu Ashwin Govindarajulu
              graham.pople Graham Pople
              Votes:
              0 Vote for this issue
              Watchers:
              11 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                PagerDuty