Details
-
Bug
-
Resolution: Fixed
-
Critical
-
6.6.0, 6.6.1, 6.6.2, 6.6.3, 6.6.4, 6.6.5, 7.0.0, 7.1.0
-
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
- relates to
-
MB-50423 Bgfetched deleted item metadata is not cleaned up (value eviction)
- Closed
-
MB-37374 Implement support so Transactions do not need to create visible temporary docs
- Closed
-
MB-50742 Insert of document via subdoc incorrectly returns EExists instead of NotStored if key already present
- Open