-
Type: Task
-
Resolution: Fixed
-
Priority: Critical - P2
-
Affects Version/s: None
-
Component/s: None
-
None
-
Fully Compatible
-
Execution Team 2021-08-09, Execution Team 2021-08-23, Execution Team 2021-09-06
SERVER-56509 introduced a bug where the unique index constraint was not enforced in some cases. We should add more test coverage for this.
The issue could be reproduced with the following script that we can base additional testing on:
function repro1() { db.c.drop() db.c.createIndex({t: 1, i: 1}, {unique: true}) const n = 10000 const t = 0 for (var i = 0; i < n; i++) db.c.insert({t, i}) for (iter = 0; ; iter++) { print("iter", iter) for (var i = 0; i < n; i++) { r = db.c.insert({t, i, x: 'x'}) if (r.nInserted != 0) print("dup!", t, i, "iter", iter, "count", db.c.count({t, i})) } } }
Which reproduces the issue after a couple of iterations:
iter 0 iter 1 dup! 0 9999 iter 1 count 2
A multithreaded version also reproduces:
function repro() { db.c.drop() db.c.createIndex({t: 1, i: 1}, {unique: true}) nthreads = 100 threads = [] for (var t=0; t<nthreads; t++) { thread = new Thread(function(t) { for (var i = 0; i < 100; i++) db.c.insert({t, i, x: 'x'}) while (true) { for (var i = 0; i < 100; i++) { r = db.c.insert({t, i, x: 'x'}) if (r.nInserted != 0) print("dup!", t, i, "count", db.c.count({t, i})) } } }, t) threads.push(thread) thread.start() } for (var t = 0; t < nthreads; t++) threads[t].join() }
- is related to
-
SERVER-58936 Unique index constraints may not be enforced
- Closed
-
SERVER-56509 Wrap unique index insertion _keyExists call in a WT cursor reconfigure.
- Closed