diff options
author | Louis Williams <louis.williams@mongodb.com> | 2019-06-07 16:06:46 -0400 |
---|---|---|
committer | Louis Williams <louis.williams@mongodb.com> | 2019-06-07 16:06:46 -0400 |
commit | e48c36a61634718f548f29aa0e1e3787fc1a979b (patch) | |
tree | 06ecbef3399881378ba5fe2456fab7a7979ba6fb | |
parent | e67db1f1c523309be615ebf1ec7f12b944b21bd9 (diff) | |
download | mongo-e48c36a61634718f548f29aa0e1e3787fc1a979b.tar.gz |
SERVER-41581 index_builds_ignore_prepare_conflicts.js should not start a transaction until the index build releases its exclusive lock
-rw-r--r-- | jstests/noPassthrough/index_builds_ignore_prepare_conflicts.js | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/jstests/noPassthrough/index_builds_ignore_prepare_conflicts.js b/jstests/noPassthrough/index_builds_ignore_prepare_conflicts.js index 4973d4296d7..e46177d35b0 100644 --- a/jstests/noPassthrough/index_builds_ignore_prepare_conflicts.js +++ b/jstests/noPassthrough/index_builds_ignore_prepare_conflicts.js @@ -28,11 +28,11 @@ const primary = replSetTest.getPrimary(); const primaryDB = primary.getDB('test'); - const docsToInsert = 10; + let numDocs = 10; let setUp = function(coll) { coll.drop(); let bulk = coll.initializeUnorderedBulkOp(); - for (let i = 0; i < docsToInsert; i++) { + for (let i = 0; i < numDocs; i++) { bulk.insert({i: i}); } assert.commandWorked(bulk.execute()); @@ -54,6 +54,11 @@ const awaitBuild = IndexBuildTest.startIndexBuild(primary, coll.getFullName(), {i: 1}); const opId = IndexBuildTest.waitForIndexBuildToStart(testDB, collName, "i_1"); + // This insert will block until the index build pauses and releases its exclusive lock. + // This guarantees that the subsequent transaction can immediately acquire a lock and not + // fail with a LockTimeout error. + assert.commandWorked(coll.insert({i: numDocs++})); + // Start a session and introduce a document that is in a prepared state, but should be // ignored by the index build, at least until the transaction commits. const session = primaryDB.getMongo().startSession(); @@ -95,8 +100,8 @@ awaitBuild(); IndexBuildTest.waitForIndexBuildToStop(testDB, collName, "i_1"); - assert.eq(docsToInsert, coll.count()); - assert.eq(docsToInsert, coll.find().itcount()); + assert.eq(numDocs, coll.count()); + assert.eq(numDocs, coll.find().itcount()); }; runTest(replSetTest.getPrimary()); |