diff options
author | Louis Williams <louis.williams@mongodb.com> | 2019-06-11 11:28:30 -0400 |
---|---|---|
committer | Louis Williams <louis.williams@mongodb.com> | 2019-06-11 11:28:30 -0400 |
commit | 24d6fb41ff2a1fd3ff5fb5cd54e0cc4b2cc075b6 (patch) | |
tree | 9892d1253c95cef60ad54ab3945f9c4ae414ec71 | |
parent | 52149b64892ba7a26f3cb1aee569baa0fae8450e (diff) | |
download | mongo-24d6fb41ff2a1fd3ff5fb5cd54e0cc4b2cc075b6.tar.gz |
SERVER-41581 index_builds_ignore_prepare_conflicts.js should not start a transaction until the index build releases its exclusive lock
(cherry picked from commit e48c36a61634718f548f29aa0e1e3787fc1a979b)
-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()); |