diff options
author | Gregory Noma <gregory.noma@gmail.com> | 2021-11-17 22:22:31 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-12-01 18:17:40 +0000 |
commit | 52e9e4fe03089c106a7c91206256c55631829a25 (patch) | |
tree | 85615fddb82be266ba12538663951975ef7dcc52 /jstests/noPassthrough | |
parent | a2779124f00d7abad00f33ba0e052a5fcc808b66 (diff) | |
download | mongo-52e9e4fe03089c106a7c91206256c55631829a25.tar.gz |
SERVER-61427 Skip duplicate index key handler when exact key already exists in index
(cherry picked from commit 9f15b2b1eeb356f4e3d0c6e06302941ec685cc0a)
(cherry picked from commit cbfe08edee4a6aa41694b73be690b4e56de0bb3a)
Diffstat (limited to 'jstests/noPassthrough')
-rw-r--r-- | jstests/noPassthrough/unique_index_insert_during_collection_scan.js | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/jstests/noPassthrough/unique_index_insert_during_collection_scan.js b/jstests/noPassthrough/unique_index_insert_during_collection_scan.js new file mode 100644 index 00000000000..947a9b234fe --- /dev/null +++ b/jstests/noPassthrough/unique_index_insert_during_collection_scan.js @@ -0,0 +1,37 @@ +/** + * Tests inserting into collection while a unique index build is in the collection scan phase. + * Ensures that even though the insert is seen by both the collection scan and the side writes + * table, the index build does not need to resolve any duplicate keys. + */ +(function() { +"use strict"; + +load('jstests/libs/fail_point_util.js'); +load('jstests/libs/parallel_shell_helpers.js'); + +const conn = MongoRunner.runMongod(); +const coll = conn.getDB('test')[jsTestName()]; + +assert.commandWorked(coll.insert({_id: 0, a: 0})); + +const fp = configureFailPoint(conn, 'hangAfterInitializingIndexBuild'); +const awaitCreateIndex = + startParallelShell(funWithArgs(function(collName) { + assert.commandWorked(db[collName].createIndex({a: 1}, {unique: true})); + }, coll.getName()), conn.port); +fp.wait(); +assert.commandWorked(coll.insert({_id: 1, a: 1})); +fp.off(); + +awaitCreateIndex(); + +// Ensure that the second document was seen by both the collection scan and the side writes table. +checkLog.containsJson(conn, 20685, {namespace: coll.getFullName(), index: 'a_1', keysInserted: 2}); +checkLog.containsJson( + conn, 20689, {namespace: coll.getFullName(), index: 'a_1', numApplied: 1, totalInserted: 1}); + +// Ensure that there were no duplicates to resolve. +assert(!checkLog.checkContainsOnceJson(conn, 20677, {indexName: 'a_1'})); + +MongoRunner.stopMongod(conn); +})(); |