diff options
author | Henrik Edin <henrik.edin@mongodb.com> | 2021-07-28 15:52:32 -0400 |
---|---|---|
committer | Henrik Edin <henrik.edin@mongodb.com> | 2021-07-28 15:52:32 -0400 |
commit | 6d9ec525e78465dcecadcff99cce953d380fedc8 (patch) | |
tree | 26bdb93c2c57e770d5a6bb26b5baf03b4b73ce85 | |
parent | b29131246ca7f24f1841436f34ba45c0d9df1540 (diff) | |
download | mongo-6d9ec525e78465dcecadcff99cce953d380fedc8.tar.gz |
Revert "SERVER-56509 Wrap unique index insertion _keyExists call in a WT cursor reconfigure"r5.0.2-rc0r5.0.2
This reverts commit 297e2977ef3e394e02d61aedc954c9aaadc37e73.
-rw-r--r-- | jstests/noPassthrough/profile_operation_metrics.js | 17 | ||||
-rw-r--r-- | src/mongo/db/storage/wiredtiger/wiredtiger_index.cpp | 13 |
2 files changed, 13 insertions, 17 deletions
diff --git a/jstests/noPassthrough/profile_operation_metrics.js b/jstests/noPassthrough/profile_operation_metrics.js index b80c3418bb9..e527ec3e24e 100644 --- a/jstests/noPassthrough/profile_operation_metrics.js +++ b/jstests/noPassthrough/profile_operation_metrics.js @@ -692,8 +692,9 @@ const operations = [ // Insert should not perform any reads. assert.eq(profileDoc.docBytesRead, 0); assert.eq(profileDoc.docUnitsRead, 0); - assert.eq(profileDoc.idxEntryBytesRead, 0); - assert.eq(profileDoc.idxEntryUnitsRead, 0); + // Reads the index entry for 'a' to determine uniqueness. + assert.eq(profileDoc.idxEntryBytesRead, 6); + assert.eq(profileDoc.idxEntryUnitsRead, 1); assert.eq(profileDoc.cursorSeeks, 1); assert.eq(profileDoc.docBytesWritten, 29); assert.eq(profileDoc.docUnitsWritten, 1); @@ -759,9 +760,9 @@ const operations = [ assert.gte(profileDoc.docUnitsRead, 1); assert.gte(profileDoc.cursorSeeks, 4); } - // Reads index entries on '_id' for the lookup. - assert.eq(profileDoc.idxEntryBytesRead, 3); - assert.eq(profileDoc.idxEntryUnitsRead, 1); + // Reads index entries on '_id' for the lookup and 'a' to ensure uniqueness. + assert.eq(profileDoc.idxEntryBytesRead, 9); + assert.eq(profileDoc.idxEntryUnitsRead, 2); // This out-of-place update should perform a direct insert because it is not large // enough to qualify for the in-place update path. assert.eq(profileDoc.docBytesWritten, 29); @@ -799,9 +800,9 @@ const operations = [ assert.gte(profileDoc.docUnitsRead, 9); assert.gte(profileDoc.cursorSeeks, 4); } - // Reads index entries on '_id'. - assert.eq(profileDoc.idxEntryBytesRead, 4); - assert.eq(profileDoc.idxEntryUnitsRead, 1); + // Reads index entries on '_id' for the lookup and 'a' to ensure uniqueness. + assert.eq(profileDoc.idxEntryBytesRead, 10); + assert.eq(profileDoc.idxEntryUnitsRead, 2); if (FixtureHelpers.isReplSet(db)) { // When WT_MODIFY is used on a replicated collection fewer bytes are written per the // comment about WT_MODIFY above. diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_index.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_index.cpp index 01a7d64f72f..690fbc0d0d8 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_index.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_index.cpp @@ -1408,13 +1408,13 @@ bool WiredTigerIndexUnique::_keyExists(OperationContext* opCtx, int cmp; int ret = wiredTigerPrepareConflictRetry(opCtx, [&] { return c->search_near(c, &cmp); }); - auto& metricsCollector = ResourceConsumption::MetricsCollector::get(opCtx); - metricsCollector.incrementOneCursorSeek(); - if (ret == WT_NOTFOUND) return false; invariantWTOK(ret); + auto& metricsCollector = ResourceConsumption::MetricsCollector::get(opCtx); + metricsCollector.incrementOneCursorSeek(); + if (cmp == 0) return true; @@ -1565,12 +1565,7 @@ Status WiredTigerIndexUnique::_insert(OperationContext* opCtx, invariantWTOK(ret); // Second phase looks up for existence of key to avoid insertion of duplicate key - // The usage of 'prefix_key=true' enables an optimization that allows this search to return - // more quickly. See SERVER-56509. - c->reconfigure(c, "prefix_key=true"); - ON_BLOCK_EXIT([c] { c->reconfigure(c, "prefix_key=false"); }); - auto keyExists = _keyExists(opCtx, c, keyString.getBuffer(), sizeWithoutRecordId); - if (keyExists) { + if (_keyExists(opCtx, c, keyString.getBuffer(), sizeWithoutRecordId)) { auto key = KeyString::toBson( keyString.getBuffer(), sizeWithoutRecordId, _ordering, keyString.getTypeBits()); auto entry = _desc->getEntry(); |