diff options
24 files changed, 524 insertions, 423 deletions
diff --git a/src/mongo/db/storage/biggie/biggie_sorted_impl.cpp b/src/mongo/db/storage/biggie/biggie_sorted_impl.cpp index 28c3e9c14c2..533df0fa552 100644 --- a/src/mongo/db/storage/biggie/biggie_sorted_impl.cpp +++ b/src/mongo/db/storage/biggie/biggie_sorted_impl.cpp @@ -327,16 +327,6 @@ SortedDataInterface::SortedDataInterface(const Ordering& ordering, bool isUnique } Status SortedDataInterface::insert(OperationContext* opCtx, - const BSONObj& key, - const RecordId& loc, - bool dupsAllowed) { - // The KeyString representation of the key. - KeyString::HeapBuilder keyString(_keyStringVersion, key, _ordering, loc); - - return insert(opCtx, std::move(keyString.release()), loc, dupsAllowed); -} - -Status SortedDataInterface::insert(OperationContext* opCtx, const KeyString::Value& keyString, const RecordId& loc, bool dupsAllowed) { @@ -404,15 +394,6 @@ Status SortedDataInterface::insert(OperationContext* opCtx, } void SortedDataInterface::unindex(OperationContext* opCtx, - const BSONObj& key, - const RecordId& loc, - bool dupsAllowed) { - KeyString::HeapBuilder keyString(_keyStringVersion, key, _ordering, loc); - - unindex(opCtx, std::move(keyString.release()), loc, dupsAllowed); -} - -void SortedDataInterface::unindex(OperationContext* opCtx, const KeyString::Value& keyString, const RecordId& loc, bool dupsAllowed) { diff --git a/src/mongo/db/storage/biggie/biggie_sorted_impl.h b/src/mongo/db/storage/biggie/biggie_sorted_impl.h index af20af0c10b..1d3970ea74a 100644 --- a/src/mongo/db/storage/biggie/biggie_sorted_impl.h +++ b/src/mongo/db/storage/biggie/biggie_sorted_impl.h @@ -82,18 +82,10 @@ public: virtual SortedDataBuilderInterface* getBulkBuilder(OperationContext* opCtx, bool dupsAllowed) override; virtual Status insert(OperationContext* opCtx, - const BSONObj& key, - const RecordId& loc, - bool dupsAllowed) override; - virtual Status insert(OperationContext* opCtx, const KeyString::Value& keyString, const RecordId& loc, bool dupsAllowed) override; virtual void unindex(OperationContext* opCtx, - const BSONObj& key, - const RecordId& loc, - bool dupsAllowed) override; - virtual void unindex(OperationContext* opCtx, const KeyString::Value& keyString, const RecordId& loc, bool dupsAllowed) override; diff --git a/src/mongo/db/storage/devnull/devnull_kv_engine.cpp b/src/mongo/db/storage/devnull/devnull_kv_engine.cpp index fabfd9f5d7f..b4838bf34bb 100644 --- a/src/mongo/db/storage/devnull/devnull_kv_engine.cpp +++ b/src/mongo/db/storage/devnull/devnull_kv_engine.cpp @@ -190,13 +190,6 @@ public: } virtual Status insert(OperationContext* opCtx, - const BSONObj& key, - const RecordId& loc, - bool dupsAllowed) { - return Status::OK(); - } - - virtual Status insert(OperationContext* opCtx, const KeyString::Value& keyString, const RecordId& loc, bool dupsAllowed) { @@ -204,11 +197,6 @@ public: } virtual void unindex(OperationContext* opCtx, - const BSONObj& key, - const RecordId& loc, - bool dupsAllowed) {} - - virtual void unindex(OperationContext* opCtx, const KeyString::Value& keyString, const RecordId& loc, bool dupsAllowed) {} diff --git a/src/mongo/db/storage/kv/kv_engine_test_harness.cpp b/src/mongo/db/storage/kv/kv_engine_test_harness.cpp index 034d7b673f5..14faebc450a 100644 --- a/src/mongo/db/storage/kv/kv_engine_test_harness.cpp +++ b/src/mongo/db/storage/kv/kv_engine_test_harness.cpp @@ -180,7 +180,12 @@ TEST(KVEngineTestHarness, SimpleSorted1) { { MyOperationContext opCtx(engine); WriteUnitOfWork uow(&opCtx); - ASSERT_OK(sorted->insert(&opCtx, BSON("" << 5), RecordId(6, 4), true)); + const RecordId recordId(6, 4); + const KeyString::Value keyString = + KeyString::HeapBuilder( + sorted->getKeyStringVersion(), BSON("" << 5), sorted->getOrdering(), recordId) + .release(); + ASSERT_OK(sorted->insert(&opCtx, keyString, recordId, true)); uow.commit(); } diff --git a/src/mongo/db/storage/mobile/mobile_index.cpp b/src/mongo/db/storage/mobile/mobile_index.cpp index f66050f6b72..c542bf70b0b 100644 --- a/src/mongo/db/storage/mobile/mobile_index.cpp +++ b/src/mongo/db/storage/mobile/mobile_index.cpp @@ -60,18 +60,6 @@ MobileIndex::MobileIndex(OperationContext* opCtx, _keyPattern(desc->keyPattern()) {} Status MobileIndex::insert(OperationContext* opCtx, - const BSONObj& key, - const RecordId& recId, - bool dupsAllowed) { - invariant(recId.isValid()); - invariant(!key.hasFieldNames()); - - KeyString::HeapBuilder keyString(_keyStringVersion, key, _ordering, recId); - - return insert(opCtx, std::move(keyString.release()), recId, dupsAllowed); -} - -Status MobileIndex::insert(OperationContext* opCtx, const KeyString::Value& keyString, const RecordId& recId, bool dupsAllowed) { @@ -118,21 +106,10 @@ Status MobileIndex::doInsert(OperationContext* opCtx, } void MobileIndex::unindex(OperationContext* opCtx, - const BSONObj& key, - const RecordId& recId, - bool dupsAllowed) { - invariant(recId.isValid()); - invariant(!key.hasFieldNames()); - - KeyString::HeapBuilder keyString(_keyStringVersion, key, _ordering, recId); - - unindex(opCtx, std::move(keyString.release()), recId, dupsAllowed); -} - -void MobileIndex::unindex(OperationContext* opCtx, const KeyString::Value& keyString, const RecordId& recId, bool dupsAllowed) { + invariant(recId.isValid()); _unindex(opCtx, keyString, recId, dupsAllowed); } diff --git a/src/mongo/db/storage/mobile/mobile_index.h b/src/mongo/db/storage/mobile/mobile_index.h index 2ab95649743..76d48fa47fb 100644 --- a/src/mongo/db/storage/mobile/mobile_index.h +++ b/src/mongo/db/storage/mobile/mobile_index.h @@ -53,21 +53,11 @@ public: virtual ~MobileIndex() {} Status insert(OperationContext* opCtx, - const BSONObj& key, - const RecordId& recId, - bool dupsAllowed) override; - - Status insert(OperationContext* opCtx, const KeyString::Value& keyString, const RecordId& recId, bool dupsAllowed) override; void unindex(OperationContext* opCtx, - const BSONObj& key, - const RecordId& recId, - bool dupsAllowed) override; - - void unindex(OperationContext* opCtx, const KeyString::Value& keyString, const RecordId& recId, bool dupsAllowed) override; diff --git a/src/mongo/db/storage/sorted_data_interface.h b/src/mongo/db/storage/sorted_data_interface.h index 97891f6c7f2..62ee4f8168d 100644 --- a/src/mongo/db/storage/sorted_data_interface.h +++ b/src/mongo/db/storage/sorted_data_interface.h @@ -78,23 +78,6 @@ public: bool dupsAllowed) = 0; /** - * Insert an entry into the index with the specified key and RecordId. - * - * @param opCtx the transaction under which the insert takes place - * @param dupsAllowed true if duplicate keys are allowed, and false - * otherwise - * - * @return Status::OK() if the insert succeeded, - * - * ErrorCodes::DuplicateKey if 'key' already exists in 'this' index - * at a RecordId other than 'loc' and duplicates were not allowed - */ - virtual Status insert(OperationContext* opCtx, - const BSONObj& key, - const RecordId& loc, - bool dupsAllowed) = 0; - - /** * Insert an entry into the index with the specified KeyString and RecordId. * * @param opCtx the transaction under which the insert takes place @@ -112,18 +95,6 @@ public: bool dupsAllowed) = 0; /** - * Remove the entry from the index with the specified key and RecordId. - * - * @param opCtx the transaction under which the remove takes place - * @param dupsAllowed true if duplicate keys are allowed, and false - * otherwise - */ - virtual void unindex(OperationContext* opCtx, - const BSONObj& key, - const RecordId& loc, - bool dupsAllowed) = 0; - - /** * Remove the entry from the index with the specified KeyString and RecordId. * * @param opCtx the transaction under which the remove takes place diff --git a/src/mongo/db/storage/sorted_data_interface_test_cursor.cpp b/src/mongo/db/storage/sorted_data_interface_test_cursor.cpp index 289399916a5..9d3ae65350e 100644 --- a/src/mongo/db/storage/sorted_data_interface_test_cursor.cpp +++ b/src/mongo/db/storage/sorted_data_interface_test_cursor.cpp @@ -104,7 +104,8 @@ TEST(SortedDataInterface, ExhaustCursor) { WriteUnitOfWork uow(opCtx.get()); BSONObj key = BSON("" << i); RecordId loc(42, i * 2); - ASSERT_OK(sorted->insert(opCtx.get(), key, loc, true)); + ASSERT_OK( + sorted->insert(opCtx.get(), makeKeyString(sorted.get(), key, loc), loc, true)); uow.commit(); } } @@ -147,7 +148,8 @@ TEST(SortedDataInterface, ExhaustCursorReversed) { WriteUnitOfWork uow(opCtx.get()); BSONObj key = BSON("" << i); RecordId loc(42, i * 2); - ASSERT_OK(sorted->insert(opCtx.get(), key, loc, true)); + ASSERT_OK( + sorted->insert(opCtx.get(), makeKeyString(sorted.get(), key, loc), loc, true)); uow.commit(); } } @@ -185,7 +187,7 @@ void testBoundaries(bool unique, bool forward, bool inclusive) { WriteUnitOfWork uow(opCtx.get()); BSONObj key = BSON("" << i); RecordId loc(42 + i * 2); - ASSERT_OK(sorted->insert(opCtx.get(), key, loc, true)); + ASSERT_OK(sorted->insert(opCtx.get(), makeKeyString(sorted.get(), key, loc), loc, true)); uow.commit(); } diff --git a/src/mongo/db/storage/sorted_data_interface_test_cursor_advanceto.cpp b/src/mongo/db/storage/sorted_data_interface_test_cursor_advanceto.cpp index 726e2cea9a0..7b459a9b22b 100644 --- a/src/mongo/db/storage/sorted_data_interface_test_cursor_advanceto.cpp +++ b/src/mongo/db/storage/sorted_data_interface_test_cursor_advanceto.cpp @@ -56,11 +56,20 @@ TEST(SortedDataInterface, AdvanceTo) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - ASSERT_OK(sorted->insert(opCtx.get(), key1, loc1, true)); - ASSERT_OK(sorted->insert(opCtx.get(), key1, loc2, true /* allow duplicates */)); - ASSERT_OK(sorted->insert(opCtx.get(), key1, loc3, true /* allow duplicates */)); - ASSERT_OK(sorted->insert(opCtx.get(), key2, loc4, true)); - ASSERT_OK(sorted->insert(opCtx.get(), key3, loc5, true)); + ASSERT_OK( + sorted->insert(opCtx.get(), makeKeyString(sorted.get(), key1, loc1), loc1, true)); + ASSERT_OK(sorted->insert(opCtx.get(), + makeKeyString(sorted.get(), key1, loc2), + loc2, + true /* allow duplicates */)); + ASSERT_OK(sorted->insert(opCtx.get(), + makeKeyString(sorted.get(), key1, loc3), + loc3, + true /* allow duplicates */)); + ASSERT_OK( + sorted->insert(opCtx.get(), makeKeyString(sorted.get(), key2, loc4), loc4, true)); + ASSERT_OK( + sorted->insert(opCtx.get(), makeKeyString(sorted.get(), key3, loc5), loc5, true)); uow.commit(); } } @@ -112,11 +121,20 @@ TEST(SortedDataInterface, AdvanceToReversed) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - ASSERT_OK(sorted->insert(opCtx.get(), key1, loc1, true)); - ASSERT_OK(sorted->insert(opCtx.get(), key2, loc2, true)); - ASSERT_OK(sorted->insert(opCtx.get(), key3, loc3, true)); - ASSERT_OK(sorted->insert(opCtx.get(), key3, loc4, true /* allow duplicates */)); - ASSERT_OK(sorted->insert(opCtx.get(), key3, loc5, true /* allow duplicates */)); + ASSERT_OK( + sorted->insert(opCtx.get(), makeKeyString(sorted.get(), key1, loc1), loc1, true)); + ASSERT_OK( + sorted->insert(opCtx.get(), makeKeyString(sorted.get(), key2, loc2), loc2, true)); + ASSERT_OK( + sorted->insert(opCtx.get(), makeKeyString(sorted.get(), key3, loc3), loc3, true)); + ASSERT_OK(sorted->insert(opCtx.get(), + makeKeyString(sorted.get(), key3, loc4), + loc4, + true /* allow duplicates */)); + ASSERT_OK(sorted->insert(opCtx.get(), + makeKeyString(sorted.get(), key3, loc5), + loc5, + true /* allow duplicates */)); uow.commit(); } } @@ -167,8 +185,10 @@ TEST(SortedDataInterface, AdvanceToKeyBeforeCursorPosition) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - ASSERT_OK(sorted->insert(opCtx.get(), key1, loc1, true)); - ASSERT_OK(sorted->insert(opCtx.get(), key2, loc2, true)); + ASSERT_OK( + sorted->insert(opCtx.get(), makeKeyString(sorted.get(), key1, loc1), loc1, true)); + ASSERT_OK( + sorted->insert(opCtx.get(), makeKeyString(sorted.get(), key2, loc2), loc2, true)); uow.commit(); } } @@ -212,8 +232,10 @@ TEST(SortedDataInterface, AdvanceToKeyAfterCursorPositionReversed) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - ASSERT_OK(sorted->insert(opCtx.get(), key1, loc1, true)); - ASSERT_OK(sorted->insert(opCtx.get(), key2, loc2, true)); + ASSERT_OK( + sorted->insert(opCtx.get(), makeKeyString(sorted.get(), key1, loc1), loc1, true)); + ASSERT_OK( + sorted->insert(opCtx.get(), makeKeyString(sorted.get(), key2, loc2), loc2, true)); uow.commit(); } } @@ -260,7 +282,8 @@ TEST(SortedDataInterface, AdvanceToKeyAtCursorPosition) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - ASSERT_OK(sorted->insert(opCtx.get(), key1, loc1, true)); + ASSERT_OK( + sorted->insert(opCtx.get(), makeKeyString(sorted.get(), key1, loc1), loc1, true)); uow.commit(); } } @@ -306,7 +329,8 @@ TEST(SortedDataInterface, AdvanceToKeyAtCursorPositionReversed) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - ASSERT_OK(sorted->insert(opCtx.get(), key1, loc1, true)); + ASSERT_OK( + sorted->insert(opCtx.get(), makeKeyString(sorted.get(), key1, loc1), loc1, true)); uow.commit(); } } @@ -352,11 +376,20 @@ TEST(SortedDataInterface, AdvanceToExclusive) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - ASSERT_OK(sorted->insert(opCtx.get(), key1, loc1, true)); - ASSERT_OK(sorted->insert(opCtx.get(), key1, loc2, true /* allow duplicates */)); - ASSERT_OK(sorted->insert(opCtx.get(), key1, loc3, true /* allow duplicates */)); - ASSERT_OK(sorted->insert(opCtx.get(), key2, loc4, true)); - ASSERT_OK(sorted->insert(opCtx.get(), key3, loc5, true)); + ASSERT_OK( + sorted->insert(opCtx.get(), makeKeyString(sorted.get(), key1, loc1), loc1, true)); + ASSERT_OK(sorted->insert(opCtx.get(), + makeKeyString(sorted.get(), key1, loc2), + loc2, + true /* allow duplicates */)); + ASSERT_OK(sorted->insert(opCtx.get(), + makeKeyString(sorted.get(), key1, loc3), + loc3, + true /* allow duplicates */)); + ASSERT_OK( + sorted->insert(opCtx.get(), makeKeyString(sorted.get(), key2, loc4), loc4, true)); + ASSERT_OK( + sorted->insert(opCtx.get(), makeKeyString(sorted.get(), key3, loc5), loc5, true)); uow.commit(); } } @@ -407,11 +440,20 @@ TEST(SortedDataInterface, AdvanceToExclusiveReversed) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - ASSERT_OK(sorted->insert(opCtx.get(), key1, loc1, true)); - ASSERT_OK(sorted->insert(opCtx.get(), key2, loc2, true)); - ASSERT_OK(sorted->insert(opCtx.get(), key3, loc3, true)); - ASSERT_OK(sorted->insert(opCtx.get(), key3, loc4, true /* allow duplicates */)); - ASSERT_OK(sorted->insert(opCtx.get(), key3, loc5, true /* allow duplicates */)); + ASSERT_OK( + sorted->insert(opCtx.get(), makeKeyString(sorted.get(), key1, loc1), loc1, true)); + ASSERT_OK( + sorted->insert(opCtx.get(), makeKeyString(sorted.get(), key2, loc2), loc2, true)); + ASSERT_OK( + sorted->insert(opCtx.get(), makeKeyString(sorted.get(), key3, loc3), loc3, true)); + ASSERT_OK(sorted->insert(opCtx.get(), + makeKeyString(sorted.get(), key3, loc4), + loc4, + true /* allow duplicates */)); + ASSERT_OK(sorted->insert(opCtx.get(), + makeKeyString(sorted.get(), key3, loc5), + loc5, + true /* allow duplicates */)); uow.commit(); } } @@ -464,9 +506,12 @@ TEST(SortedDataInterface, AdvanceToIndirect) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - ASSERT_OK(sorted->insert(opCtx.get(), key1, loc1, true)); - ASSERT_OK(sorted->insert(opCtx.get(), key3, loc2, true)); - ASSERT_OK(sorted->insert(opCtx.get(), key5, loc3, true)); + ASSERT_OK( + sorted->insert(opCtx.get(), makeKeyString(sorted.get(), key1, loc1), loc1, true)); + ASSERT_OK( + sorted->insert(opCtx.get(), makeKeyString(sorted.get(), key3, loc2), loc2, true)); + ASSERT_OK( + sorted->insert(opCtx.get(), makeKeyString(sorted.get(), key5, loc3), loc3, true)); uow.commit(); } } @@ -515,9 +560,12 @@ TEST(SortedDataInterface, AdvanceToIndirectReversed) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - ASSERT_OK(sorted->insert(opCtx.get(), key1, loc1, true)); - ASSERT_OK(sorted->insert(opCtx.get(), key3, loc2, true)); - ASSERT_OK(sorted->insert(opCtx.get(), key5, loc3, true)); + ASSERT_OK( + sorted->insert(opCtx.get(), makeKeyString(sorted.get(), key1, loc1), loc1, true)); + ASSERT_OK( + sorted->insert(opCtx.get(), makeKeyString(sorted.get(), key3, loc2), loc2, true)); + ASSERT_OK( + sorted->insert(opCtx.get(), makeKeyString(sorted.get(), key5, loc3), loc3, true)); uow.commit(); } } @@ -569,9 +617,12 @@ TEST(SortedDataInterface, AdvanceToIndirectExclusive) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - ASSERT_OK(sorted->insert(opCtx.get(), key1, loc1, true)); - ASSERT_OK(sorted->insert(opCtx.get(), key3, loc2, true)); - ASSERT_OK(sorted->insert(opCtx.get(), key5, loc3, true)); + ASSERT_OK( + sorted->insert(opCtx.get(), makeKeyString(sorted.get(), key1, loc1), loc1, true)); + ASSERT_OK( + sorted->insert(opCtx.get(), makeKeyString(sorted.get(), key3, loc2), loc2, true)); + ASSERT_OK( + sorted->insert(opCtx.get(), makeKeyString(sorted.get(), key5, loc3), loc3, true)); uow.commit(); } } @@ -627,9 +678,12 @@ TEST(SortedDataInterface, AdvanceToIndirectExclusiveReversed) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - ASSERT_OK(sorted->insert(opCtx.get(), key1, loc1, true)); - ASSERT_OK(sorted->insert(opCtx.get(), key3, loc2, true)); - ASSERT_OK(sorted->insert(opCtx.get(), key5, loc3, true)); + ASSERT_OK( + sorted->insert(opCtx.get(), makeKeyString(sorted.get(), key1, loc1), loc1, true)); + ASSERT_OK( + sorted->insert(opCtx.get(), makeKeyString(sorted.get(), key3, loc2), loc2, true)); + ASSERT_OK( + sorted->insert(opCtx.get(), makeKeyString(sorted.get(), key5, loc3), loc3, true)); uow.commit(); } } diff --git a/src/mongo/db/storage/sorted_data_interface_test_cursor_locate.cpp b/src/mongo/db/storage/sorted_data_interface_test_cursor_locate.cpp index f4cf8d4965a..9ebb509d0c6 100644 --- a/src/mongo/db/storage/sorted_data_interface_test_cursor_locate.cpp +++ b/src/mongo/db/storage/sorted_data_interface_test_cursor_locate.cpp @@ -54,7 +54,8 @@ TEST(SortedDataInterface, Locate) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - ASSERT_OK(sorted->insert(opCtx.get(), key1, loc1, true)); + ASSERT_OK( + sorted->insert(opCtx.get(), makeKeyString(sorted.get(), key1, loc1), loc1, true)); uow.commit(); } } @@ -86,7 +87,8 @@ TEST(SortedDataInterface, LocateReversed) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - ASSERT_OK(sorted->insert(opCtx.get(), key1, loc1, true)); + ASSERT_OK( + sorted->insert(opCtx.get(), makeKeyString(sorted.get(), key1, loc1), loc1, true)); uow.commit(); } } @@ -118,7 +120,8 @@ TEST(SortedDataInterface, LocateCompoundKey) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - ASSERT_OK(sorted->insert(opCtx.get(), compoundKey1a, loc1, true)); + ASSERT_OK(sorted->insert( + opCtx.get(), makeKeyString(sorted.get(), compoundKey1a, loc1), loc1, true)); uow.commit(); } } @@ -150,7 +153,8 @@ TEST(SortedDataInterface, LocateCompoundKeyReversed) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - ASSERT_OK(sorted->insert(opCtx.get(), compoundKey1a, loc1, true)); + ASSERT_OK(sorted->insert( + opCtx.get(), makeKeyString(sorted.get(), compoundKey1a, loc1), loc1, true)); uow.commit(); } } @@ -182,8 +186,10 @@ TEST(SortedDataInterface, LocateMultiple) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - ASSERT_OK(sorted->insert(opCtx.get(), key1, loc1, true)); - ASSERT_OK(sorted->insert(opCtx.get(), key2, loc2, true)); + ASSERT_OK( + sorted->insert(opCtx.get(), makeKeyString(sorted.get(), key1, loc1), loc1, true)); + ASSERT_OK( + sorted->insert(opCtx.get(), makeKeyString(sorted.get(), key2, loc2), loc2, true)); uow.commit(); } } @@ -201,7 +207,8 @@ TEST(SortedDataInterface, LocateMultiple) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - ASSERT_OK(sorted->insert(opCtx.get(), key3, loc3, true)); + ASSERT_OK( + sorted->insert(opCtx.get(), makeKeyString(sorted.get(), key3, loc3), loc3, true)); uow.commit(); } } @@ -239,8 +246,10 @@ TEST(SortedDataInterface, LocateMultipleReversed) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - ASSERT_OK(sorted->insert(opCtx.get(), key1, loc1, true)); - ASSERT_OK(sorted->insert(opCtx.get(), key2, loc2, true)); + ASSERT_OK( + sorted->insert(opCtx.get(), makeKeyString(sorted.get(), key1, loc1), loc1, true)); + ASSERT_OK( + sorted->insert(opCtx.get(), makeKeyString(sorted.get(), key2, loc2), loc2, true)); uow.commit(); } } @@ -259,7 +268,8 @@ TEST(SortedDataInterface, LocateMultipleReversed) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - ASSERT_OK(sorted->insert(opCtx.get(), key3, loc3, true)); + ASSERT_OK( + sorted->insert(opCtx.get(), makeKeyString(sorted.get(), key3, loc3), loc3, true)); uow.commit(); } } @@ -297,9 +307,12 @@ TEST(SortedDataInterface, LocateMultipleCompoundKeys) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - ASSERT_OK(sorted->insert(opCtx.get(), compoundKey1a, loc1, true)); - ASSERT_OK(sorted->insert(opCtx.get(), compoundKey1b, loc2, true)); - ASSERT_OK(sorted->insert(opCtx.get(), compoundKey2b, loc3, true)); + ASSERT_OK(sorted->insert( + opCtx.get(), makeKeyString(sorted.get(), compoundKey1a, loc1), loc1, true)); + ASSERT_OK(sorted->insert( + opCtx.get(), makeKeyString(sorted.get(), compoundKey1b, loc2), loc2, true)); + ASSERT_OK(sorted->insert( + opCtx.get(), makeKeyString(sorted.get(), compoundKey2b, loc3), loc3, true)); uow.commit(); } } @@ -318,8 +331,10 @@ TEST(SortedDataInterface, LocateMultipleCompoundKeys) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - ASSERT_OK(sorted->insert(opCtx.get(), compoundKey1c, loc4, true)); - ASSERT_OK(sorted->insert(opCtx.get(), compoundKey3a, loc5, true)); + ASSERT_OK(sorted->insert( + opCtx.get(), makeKeyString(sorted.get(), compoundKey1c, loc4), loc4, true)); + ASSERT_OK(sorted->insert( + opCtx.get(), makeKeyString(sorted.get(), compoundKey3a, loc5), loc5, true)); uow.commit(); } } @@ -355,9 +370,12 @@ TEST(SortedDataInterface, LocateMultipleCompoundKeysReversed) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - ASSERT_OK(sorted->insert(opCtx.get(), compoundKey1a, loc1, true)); - ASSERT_OK(sorted->insert(opCtx.get(), compoundKey1b, loc2, true)); - ASSERT_OK(sorted->insert(opCtx.get(), compoundKey2b, loc3, true)); + ASSERT_OK(sorted->insert( + opCtx.get(), makeKeyString(sorted.get(), compoundKey1a, loc1), loc1, true)); + ASSERT_OK(sorted->insert( + opCtx.get(), makeKeyString(sorted.get(), compoundKey1b, loc2), loc2, true)); + ASSERT_OK(sorted->insert( + opCtx.get(), makeKeyString(sorted.get(), compoundKey2b, loc3), loc3, true)); uow.commit(); } } @@ -377,8 +395,10 @@ TEST(SortedDataInterface, LocateMultipleCompoundKeysReversed) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - ASSERT_OK(sorted->insert(opCtx.get(), compoundKey1c, loc4, true)); - ASSERT_OK(sorted->insert(opCtx.get(), compoundKey3a, loc5, true)); + ASSERT_OK(sorted->insert( + opCtx.get(), makeKeyString(sorted.get(), compoundKey1c, loc4), loc4, true)); + ASSERT_OK(sorted->insert( + opCtx.get(), makeKeyString(sorted.get(), compoundKey3a, loc5), loc5, true)); uow.commit(); } } @@ -414,8 +434,10 @@ TEST(SortedDataInterface, LocateIndirect) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - ASSERT_OK(sorted->insert(opCtx.get(), key1, loc1, true)); - ASSERT_OK(sorted->insert(opCtx.get(), key2, loc2, true)); + ASSERT_OK( + sorted->insert(opCtx.get(), makeKeyString(sorted.get(), key1, loc1), loc1, true)); + ASSERT_OK( + sorted->insert(opCtx.get(), makeKeyString(sorted.get(), key2, loc2), loc2, true)); uow.commit(); } } @@ -432,7 +454,8 @@ TEST(SortedDataInterface, LocateIndirect) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - ASSERT_OK(sorted->insert(opCtx.get(), key3, loc3, true)); + ASSERT_OK( + sorted->insert(opCtx.get(), makeKeyString(sorted.get(), key3, loc3), loc3, true)); uow.commit(); } } @@ -466,8 +489,10 @@ TEST(SortedDataInterface, LocateIndirectReversed) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - ASSERT_OK(sorted->insert(opCtx.get(), key1, loc1, true)); - ASSERT_OK(sorted->insert(opCtx.get(), key2, loc2, true)); + ASSERT_OK( + sorted->insert(opCtx.get(), makeKeyString(sorted.get(), key1, loc1), loc1, true)); + ASSERT_OK( + sorted->insert(opCtx.get(), makeKeyString(sorted.get(), key2, loc2), loc2, true)); uow.commit(); } } @@ -485,7 +510,8 @@ TEST(SortedDataInterface, LocateIndirectReversed) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - ASSERT_OK(sorted->insert(opCtx.get(), key3, loc3, true)); + ASSERT_OK( + sorted->insert(opCtx.get(), makeKeyString(sorted.get(), key3, loc3), loc3, true)); uow.commit(); } } @@ -519,9 +545,12 @@ TEST(SortedDataInterface, LocateIndirectCompoundKeys) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - ASSERT_OK(sorted->insert(opCtx.get(), compoundKey1a, loc1, true)); - ASSERT_OK(sorted->insert(opCtx.get(), compoundKey1b, loc2, true)); - ASSERT_OK(sorted->insert(opCtx.get(), compoundKey2b, loc3, true)); + ASSERT_OK(sorted->insert( + opCtx.get(), makeKeyString(sorted.get(), compoundKey1a, loc1), loc1, true)); + ASSERT_OK(sorted->insert( + opCtx.get(), makeKeyString(sorted.get(), compoundKey1b, loc2), loc2, true)); + ASSERT_OK(sorted->insert( + opCtx.get(), makeKeyString(sorted.get(), compoundKey2b, loc3), loc3, true)); uow.commit(); } } @@ -539,8 +568,10 @@ TEST(SortedDataInterface, LocateIndirectCompoundKeys) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - ASSERT_OK(sorted->insert(opCtx.get(), compoundKey1c, loc4, true)); - ASSERT_OK(sorted->insert(opCtx.get(), compoundKey3a, loc5, true)); + ASSERT_OK(sorted->insert( + opCtx.get(), makeKeyString(sorted.get(), compoundKey1c, loc4), loc4, true)); + ASSERT_OK(sorted->insert( + opCtx.get(), makeKeyString(sorted.get(), compoundKey3a, loc5), loc5, true)); uow.commit(); } } @@ -573,9 +604,12 @@ TEST(SortedDataInterface, LocateIndirectCompoundKeysReversed) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - ASSERT_OK(sorted->insert(opCtx.get(), compoundKey1a, loc1, true)); - ASSERT_OK(sorted->insert(opCtx.get(), compoundKey1b, loc2, true)); - ASSERT_OK(sorted->insert(opCtx.get(), compoundKey2b, loc3, true)); + ASSERT_OK(sorted->insert( + opCtx.get(), makeKeyString(sorted.get(), compoundKey1a, loc1), loc1, true)); + ASSERT_OK(sorted->insert( + opCtx.get(), makeKeyString(sorted.get(), compoundKey1b, loc2), loc2, true)); + ASSERT_OK(sorted->insert( + opCtx.get(), makeKeyString(sorted.get(), compoundKey2b, loc3), loc3, true)); uow.commit(); } } @@ -594,8 +628,10 @@ TEST(SortedDataInterface, LocateIndirectCompoundKeysReversed) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - ASSERT_OK(sorted->insert(opCtx.get(), compoundKey1c, loc4, true)); - ASSERT_OK(sorted->insert(opCtx.get(), compoundKey3a, loc5, true)); + ASSERT_OK(sorted->insert( + opCtx.get(), makeKeyString(sorted.get(), compoundKey1c, loc4), loc4, true)); + ASSERT_OK(sorted->insert( + opCtx.get(), makeKeyString(sorted.get(), compoundKey3a, loc5), loc5, true)); uow.commit(); } } diff --git a/src/mongo/db/storage/sorted_data_interface_test_cursor_saverestore.cpp b/src/mongo/db/storage/sorted_data_interface_test_cursor_saverestore.cpp index aa2eb8231ca..5f21fab1efa 100644 --- a/src/mongo/db/storage/sorted_data_interface_test_cursor_saverestore.cpp +++ b/src/mongo/db/storage/sorted_data_interface_test_cursor_saverestore.cpp @@ -59,7 +59,8 @@ TEST(SortedDataInterface, SaveAndRestorePositionWhileIterateCursor) { WriteUnitOfWork uow(opCtx.get()); BSONObj key = BSON("" << i); RecordId loc(42, i * 2); - ASSERT_OK(sorted->insert(opCtx.get(), key, loc, true)); + ASSERT_OK( + sorted->insert(opCtx.get(), makeKeyString(sorted.get(), key, loc), loc, true)); uow.commit(); } } @@ -105,7 +106,8 @@ TEST(SortedDataInterface, SaveAndRestorePositionWhileIterateCursorReversed) { WriteUnitOfWork uow(opCtx.get()); BSONObj key = BSON("" << i); RecordId loc(42, i * 2); - ASSERT_OK(sorted->insert(opCtx.get(), key, loc, true)); + ASSERT_OK( + sorted->insert(opCtx.get(), makeKeyString(sorted.get(), key, loc), loc, true)); uow.commit(); } } @@ -244,7 +246,10 @@ TEST(SortedDataInterface, SaveAndRestorePositionWhileIterateCursorWithDupKeys) { { WriteUnitOfWork uow(opCtx.get()); RecordId loc(42, i * 2); - ASSERT_OK(sorted->insert(opCtx.get(), key1, loc, true /* allow duplicates */)); + ASSERT_OK(sorted->insert(opCtx.get(), + makeKeyString(sorted.get(), key1, loc), + loc, + true /* allow duplicates */)); uow.commit(); } } @@ -290,7 +295,10 @@ TEST(SortedDataInterface, SaveAndRestorePositionWhileIterateCursorWithDupKeysRev { WriteUnitOfWork uow(opCtx.get()); RecordId loc(42, i * 2); - ASSERT_OK(sorted->insert(opCtx.get(), key1, loc, true /* allow duplicates */)); + ASSERT_OK(sorted->insert(opCtx.get(), + makeKeyString(sorted.get(), key1, loc), + loc, + true /* allow duplicates */)); uow.commit(); } } @@ -333,7 +341,8 @@ TEST(SortedDataInterface, SavePositionWithoutRestore) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - ASSERT_OK(sorted->insert(opCtx.get(), key1, loc1, false)); + ASSERT_OK( + sorted->insert(opCtx.get(), makeKeyString(sorted.get(), key1, loc1), loc1, false)); uow.commit(); } } @@ -366,7 +375,8 @@ TEST(SortedDataInterface, SavePositionWithoutRestoreReversed) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - ASSERT_OK(sorted->insert(opCtx.get(), key1, loc1, true)); + ASSERT_OK( + sorted->insert(opCtx.get(), makeKeyString(sorted.get(), key1, loc1), loc1, true)); uow.commit(); } } diff --git a/src/mongo/db/storage/sorted_data_interface_test_dupkeycheck.cpp b/src/mongo/db/storage/sorted_data_interface_test_dupkeycheck.cpp index 33bb4c0c018..43d88e1081b 100644 --- a/src/mongo/db/storage/sorted_data_interface_test_dupkeycheck.cpp +++ b/src/mongo/db/storage/sorted_data_interface_test_dupkeycheck.cpp @@ -54,7 +54,8 @@ TEST(SortedDataInterface, DupKeyCheckAfterInsert) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - ASSERT_OK(sorted->insert(opCtx.get(), key1, loc1, false)); + ASSERT_OK( + sorted->insert(opCtx.get(), makeKeyString(sorted.get(), key1, loc1), loc1, false)); uow.commit(); } } @@ -82,9 +83,8 @@ TEST(SortedDataInterface, DupKeyCheckAfterInsertKeyString) { const std::unique_ptr<SortedDataInterface> sorted( harnessHelper->newSortedDataInterface(/*unique=*/true, /*partial=*/false)); - KeyString::Builder keyString1(sorted->getKeyStringVersion(), key1, sorted->getOrdering(), loc1); - KeyString::Builder keyString1WithoutRecordId( - sorted->getKeyStringVersion(), key1, sorted->getOrdering()); + auto keyString1 = makeKeyString(sorted.get(), key1, loc1); + auto keyString1WithoutRecordId = makeKeyString(sorted.get(), key1); { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); @@ -95,7 +95,7 @@ TEST(SortedDataInterface, DupKeyCheckAfterInsertKeyString) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - ASSERT_OK(sorted->insert(opCtx.get(), keyString1.getValueCopy(), loc1, false)); + ASSERT_OK(sorted->insert(opCtx.get(), keyString1, loc1, false)); uow.commit(); } } @@ -107,7 +107,7 @@ TEST(SortedDataInterface, DupKeyCheckAfterInsertKeyString) { { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); - ASSERT_OK(sorted->dupKeyCheck(opCtx.get(), keyString1WithoutRecordId.getValueCopy())); + ASSERT_OK(sorted->dupKeyCheck(opCtx.get(), keyString1WithoutRecordId)); } } @@ -136,8 +136,7 @@ TEST(SortedDataInterface, DupKeyCheckEmptyKeyString) { const std::unique_ptr<SortedDataInterface> sorted( harnessHelper->newSortedDataInterface(/*unique=*/true, /*partial=*/false)); - KeyString::Builder keyString1WithoutRecordId( - sorted->getKeyStringVersion(), key1, sorted->getOrdering()); + auto keyString1WithoutRecordId = makeKeyString(sorted.get(), key1); { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); @@ -146,7 +145,7 @@ TEST(SortedDataInterface, DupKeyCheckEmptyKeyString) { { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); - ASSERT_OK(sorted->dupKeyCheck(opCtx.get(), keyString1WithoutRecordId.getValueCopy())); + ASSERT_OK(sorted->dupKeyCheck(opCtx.get(), keyString1WithoutRecordId)); } } @@ -166,7 +165,8 @@ TEST(SortedDataInterface, DupKeyCheckWhenDiskLocBefore) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - ASSERT_OK(sorted->insert(opCtx.get(), key1, loc1, true)); + ASSERT_OK( + sorted->insert(opCtx.get(), makeKeyString(sorted.get(), key1, loc1), loc1, true)); uow.commit(); } } @@ -202,7 +202,8 @@ TEST(SortedDataInterface, DupKeyCheckWhenDiskLocAfter) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - ASSERT_OK(sorted->insert(opCtx.get(), key1, loc1, true)); + ASSERT_OK( + sorted->insert(opCtx.get(), makeKeyString(sorted.get(), key1, loc1), loc1, true)); uow.commit(); } } @@ -232,8 +233,8 @@ TEST(SortedDataInterface, DupKeyCheckWithDuplicates) { ASSERT(sorted->isEmpty(opCtx.get())); WriteUnitOfWork uow(opCtx.get()); - ASSERT_OK(sorted->insert(opCtx.get(), key1, loc1, true)); - ASSERT_OK(sorted->insert(opCtx.get(), key1, loc2, true)); + ASSERT_OK(sorted->insert(opCtx.get(), makeKeyString(sorted.get(), key1, loc1), loc1, true)); + ASSERT_OK(sorted->insert(opCtx.get(), makeKeyString(sorted.get(), key1, loc2), loc2, true)); uow.commit(); } @@ -249,25 +250,24 @@ TEST(SortedDataInterface, DupKeyCheckWithDuplicateKeyStrings) { const std::unique_ptr<SortedDataInterface> sorted( harnessHelper->newSortedDataInterface(/*unique=*/true, /*partial=*/false)); - KeyString::Builder keyString1(sorted->getKeyStringVersion(), key1, sorted->getOrdering(), loc1); - KeyString::Builder keyString2(sorted->getKeyStringVersion(), key1, sorted->getOrdering(), loc2); - KeyString::Builder keyString1WithoutRecordId( - sorted->getKeyStringVersion(), key1, sorted->getOrdering()); + auto keyString1 = makeKeyString(sorted.get(), key1, loc1); + auto keyString2 = makeKeyString(sorted.get(), key1, loc2); + auto keyString1WithoutRecordId = makeKeyString(sorted.get(), key1); { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); ASSERT(sorted->isEmpty(opCtx.get())); WriteUnitOfWork uow(opCtx.get()); - ASSERT_OK(sorted->insert(opCtx.get(), keyString1.getValueCopy(), loc1, true)); - ASSERT_OK(sorted->insert(opCtx.get(), keyString2.getValueCopy(), loc2, true)); + ASSERT_OK(sorted->insert(opCtx.get(), keyString1, loc1, true)); + ASSERT_OK(sorted->insert(opCtx.get(), keyString2, loc2, true)); uow.commit(); } { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); ASSERT_EQUALS(2, sorted->numEntries(opCtx.get())); - ASSERT_NOT_OK(sorted->dupKeyCheck(opCtx.get(), keyString1WithoutRecordId.getValueCopy())); + ASSERT_NOT_OK(sorted->dupKeyCheck(opCtx.get(), keyString1WithoutRecordId)); } } @@ -281,15 +281,15 @@ TEST(SortedDataInterface, DupKeyCheckWithDeletedFirstEntry) { ASSERT(sorted->isEmpty(opCtx.get())); WriteUnitOfWork uow(opCtx.get()); - ASSERT_OK(sorted->insert(opCtx.get(), key1, loc1, true)); - ASSERT_OK(sorted->insert(opCtx.get(), key1, loc2, true)); + ASSERT_OK(sorted->insert(opCtx.get(), makeKeyString(sorted.get(), key1, loc1), loc1, true)); + ASSERT_OK(sorted->insert(opCtx.get(), makeKeyString(sorted.get(), key1, loc2), loc2, true)); uow.commit(); } { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); WriteUnitOfWork uow(opCtx.get()); - sorted->unindex(opCtx.get(), key1, loc1, true); + sorted->unindex(opCtx.get(), makeKeyString(sorted.get(), key1, loc1), loc1, true); uow.commit(); } @@ -310,15 +310,15 @@ TEST(SortedDataInterface, DupKeyCheckWithDeletedSecondEntry) { ASSERT(sorted->isEmpty(opCtx.get())); WriteUnitOfWork uow(opCtx.get()); - ASSERT_OK(sorted->insert(opCtx.get(), key1, loc1, true)); - ASSERT_OK(sorted->insert(opCtx.get(), key1, loc2, true)); + ASSERT_OK(sorted->insert(opCtx.get(), makeKeyString(sorted.get(), key1, loc1), loc1, true)); + ASSERT_OK(sorted->insert(opCtx.get(), makeKeyString(sorted.get(), key1, loc2), loc2, true)); uow.commit(); } { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); WriteUnitOfWork uow(opCtx.get()); - sorted->unindex(opCtx.get(), key1, loc2, true); + sorted->unindex(opCtx.get(), makeKeyString(sorted.get(), key1, loc2), loc2, true); uow.commit(); } { diff --git a/src/mongo/db/storage/sorted_data_interface_test_fullvalidate.cpp b/src/mongo/db/storage/sorted_data_interface_test_fullvalidate.cpp index e396052e9fa..ea8a161a3a7 100644 --- a/src/mongo/db/storage/sorted_data_interface_test_fullvalidate.cpp +++ b/src/mongo/db/storage/sorted_data_interface_test_fullvalidate.cpp @@ -56,7 +56,8 @@ TEST(SortedDataInterface, FullValidate) { WriteUnitOfWork uow(opCtx.get()); BSONObj key = BSON("" << i); RecordId loc(42, i * 2); - ASSERT_OK(sorted->insert(opCtx.get(), key, loc, true)); + ASSERT_OK( + sorted->insert(opCtx.get(), makeKeyString(sorted.get(), key, loc), loc, true)); uow.commit(); } } diff --git a/src/mongo/db/storage/sorted_data_interface_test_harness.cpp b/src/mongo/db/storage/sorted_data_interface_test_harness.cpp index 43bb6df5c4a..09e44da851d 100644 --- a/src/mongo/db/storage/sorted_data_interface_test_harness.cpp +++ b/src/mongo/db/storage/sorted_data_interface_test_harness.cpp @@ -51,7 +51,8 @@ void mongo::insertToIndex(unowned_ptr<OperationContext> opCtx, std::initializer_list<IndexKeyEntry> toInsert) { WriteUnitOfWork wuow(opCtx); for (auto&& entry : toInsert) { - ASSERT_OK(index->insert(opCtx, entry.key, entry.loc, true)); + ASSERT_OK(index->insert( + opCtx, makeKeyString(index.get(), entry.key, entry.loc), entry.loc, true)); } wuow.commit(); } @@ -61,11 +62,21 @@ void mongo::removeFromIndex(unowned_ptr<OperationContext> opCtx, std::initializer_list<IndexKeyEntry> toRemove) { WriteUnitOfWork wuow(opCtx); for (auto&& entry : toRemove) { - index->unindex(opCtx, entry.key, entry.loc, true); + index->unindex(opCtx, makeKeyString(index.get(), entry.key, entry.loc), entry.loc, true); } wuow.commit(); } +mongo::KeyString::Value mongo::makeKeyString(SortedDataInterface* sorted, + BSONObj bsonKey, + boost::optional<RecordId> rid) { + KeyString::Builder builder(sorted->getKeyStringVersion(), bsonKey, sorted->getOrdering()); + if (rid) { + builder.appendRecordId(*rid); + } + return builder.getValueCopy(); +} + namespace mongo { namespace { @@ -78,7 +89,10 @@ TEST(SortedDataInterface, InsertWithDups1) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - ASSERT_OK(sorted->insert(opCtx.get(), BSON("" << 1), RecordId(5, 2), true)); + ASSERT_OK(sorted->insert(opCtx.get(), + makeKeyString(sorted.get(), BSON("" << 1), RecordId(5, 2)), + RecordId(5, 2), + true)); uow.commit(); } } @@ -87,7 +101,10 @@ TEST(SortedDataInterface, InsertWithDups1) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - ASSERT_OK(sorted->insert(opCtx.get(), BSON("" << 1), RecordId(6, 2), true)); + ASSERT_OK(sorted->insert(opCtx.get(), + makeKeyString(sorted.get(), BSON("" << 1), RecordId(6, 2)), + RecordId(6, 2), + true)); uow.commit(); } } @@ -111,7 +128,10 @@ TEST(SortedDataInterface, InsertWithDups2) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - ASSERT_OK(sorted->insert(opCtx.get(), BSON("" << 1), RecordId(5, 18), true)); + ASSERT_OK(sorted->insert(opCtx.get(), + makeKeyString(sorted.get(), BSON("" << 1), RecordId(5, 18)), + RecordId(5, 18), + true)); uow.commit(); } } @@ -120,7 +140,10 @@ TEST(SortedDataInterface, InsertWithDups2) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - ASSERT_OK(sorted->insert(opCtx.get(), BSON("" << 1), RecordId(5, 20), true)); + ASSERT_OK(sorted->insert(opCtx.get(), + makeKeyString(sorted.get(), BSON("" << 1), RecordId(5, 20)), + RecordId(5, 20), + true)); uow.commit(); } } @@ -140,7 +163,10 @@ TEST(SortedDataInterface, InsertWithDups3AndRollback) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - ASSERT_OK(sorted->insert(opCtx.get(), BSON("" << 1), RecordId(5, 18), true)); + ASSERT_OK(sorted->insert(opCtx.get(), + makeKeyString(sorted.get(), BSON("" << 1), RecordId(5, 18)), + RecordId(5, 18), + true)); uow.commit(); } } @@ -149,7 +175,10 @@ TEST(SortedDataInterface, InsertWithDups3AndRollback) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - ASSERT_OK(sorted->insert(opCtx.get(), BSON("" << 1), RecordId(5, 20), true)); + ASSERT_OK(sorted->insert(opCtx.get(), + makeKeyString(sorted.get(), BSON("" << 1), RecordId(5, 20)), + RecordId(5, 20), + true)); // no commit } } @@ -169,7 +198,10 @@ TEST(SortedDataInterface, InsertNoDups1) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - ASSERT_OK(sorted->insert(opCtx.get(), BSON("" << 1), RecordId(5, 18), false)); + ASSERT_OK(sorted->insert(opCtx.get(), + makeKeyString(sorted.get(), BSON("" << 1), RecordId(5, 18)), + RecordId(5, 18), + false)); uow.commit(); } } @@ -178,7 +210,10 @@ TEST(SortedDataInterface, InsertNoDups1) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - ASSERT_OK(sorted->insert(opCtx.get(), BSON("" << 2), RecordId(5, 20), false)); + ASSERT_OK(sorted->insert(opCtx.get(), + makeKeyString(sorted.get(), BSON("" << 2), RecordId(5, 20)), + RecordId(5, 20), + false)); uow.commit(); } } @@ -198,7 +233,10 @@ TEST(SortedDataInterface, InsertNoDups2) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - ASSERT_OK(sorted->insert(opCtx.get(), BSON("" << 1), RecordId(5, 2), false)); + ASSERT_OK(sorted->insert(opCtx.get(), + makeKeyString(sorted.get(), BSON("" << 1), RecordId(5, 2)), + RecordId(5, 2), + false)); uow.commit(); } } @@ -207,7 +245,10 @@ TEST(SortedDataInterface, InsertNoDups2) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - ASSERT_NOT_OK(sorted->insert(opCtx.get(), BSON("" << 1), RecordId(5, 4), false)); + ASSERT_NOT_OK(sorted->insert(opCtx.get(), + makeKeyString(sorted.get(), BSON("" << 1), RecordId(5, 4)), + RecordId(5, 4), + false)); uow.commit(); } } @@ -227,7 +268,10 @@ TEST(SortedDataInterface, Unindex1) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - ASSERT_OK(sorted->insert(opCtx.get(), BSON("" << 1), RecordId(5, 18), true)); + ASSERT_OK(sorted->insert(opCtx.get(), + makeKeyString(sorted.get(), BSON("" << 1), RecordId(5, 18)), + RecordId(5, 18), + true)); uow.commit(); } } @@ -241,7 +285,10 @@ TEST(SortedDataInterface, Unindex1) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - sorted->unindex(opCtx.get(), BSON("" << 1), RecordId(5, 20), true); + sorted->unindex(opCtx.get(), + makeKeyString(sorted.get(), BSON("" << 1), RecordId(5, 20)), + RecordId(5, 20), + true); ASSERT_EQUALS(1, sorted->numEntries(opCtx.get())); uow.commit(); } @@ -256,7 +303,10 @@ TEST(SortedDataInterface, Unindex1) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - sorted->unindex(opCtx.get(), BSON("" << 2), RecordId(5, 18), true); + sorted->unindex(opCtx.get(), + makeKeyString(sorted.get(), BSON("" << 2), RecordId(5, 18)), + RecordId(5, 18), + true); ASSERT_EQUALS(1, sorted->numEntries(opCtx.get())); uow.commit(); } @@ -272,7 +322,10 @@ TEST(SortedDataInterface, Unindex1) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - sorted->unindex(opCtx.get(), BSON("" << 1), RecordId(5, 18), true); + sorted->unindex(opCtx.get(), + makeKeyString(sorted.get(), BSON("" << 1), RecordId(5, 18)), + RecordId(5, 18), + true); ASSERT(sorted->isEmpty(opCtx.get())); uow.commit(); } @@ -293,7 +346,10 @@ TEST(SortedDataInterface, Unindex2Rollback) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - ASSERT_OK(sorted->insert(opCtx.get(), BSON("" << 1), RecordId(5, 18), true)); + ASSERT_OK(sorted->insert(opCtx.get(), + makeKeyString(sorted.get(), BSON("" << 1), RecordId(5, 18)), + RecordId(5, 18), + true)); uow.commit(); } } @@ -307,7 +363,10 @@ TEST(SortedDataInterface, Unindex2Rollback) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - sorted->unindex(opCtx.get(), BSON("" << 1), RecordId(5, 18), true); + sorted->unindex(opCtx.get(), + makeKeyString(sorted.get(), BSON("" << 1), RecordId(5, 18)), + RecordId(5, 18), + true); ASSERT(sorted->isEmpty(opCtx.get())); // no commit } @@ -330,7 +389,10 @@ TEST(SortedDataInterface, CursorIterate1) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - ASSERT_OK(sorted->insert(opCtx.get(), BSON("" << i), RecordId(5, i * 2), true)); + ASSERT_OK(sorted->insert(opCtx.get(), + makeKeyString(sorted.get(), BSON("" << i), RecordId(5, i * 2)), + RecordId(5, i * 2), + true)); uow.commit(); } } @@ -357,7 +419,10 @@ TEST(SortedDataInterface, CursorIterate1WithSaveRestore) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - ASSERT_OK(sorted->insert(opCtx.get(), BSON("" << i), RecordId(5, i * 2), true)); + ASSERT_OK(sorted->insert(opCtx.get(), + makeKeyString(sorted.get(), BSON("" << i), RecordId(5, i * 2)), + RecordId(5, i * 2), + true)); uow.commit(); } } @@ -387,7 +452,10 @@ TEST(SortedDataInterface, CursorIterateAllDupKeysWithSaveRestore) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - ASSERT_OK(sorted->insert(opCtx.get(), BSON("" << 5), RecordId(5, i * 2), true)); + ASSERT_OK(sorted->insert(opCtx.get(), + makeKeyString(sorted.get(), BSON("" << 5), RecordId(5, i * 2)), + RecordId(5, i * 2), + true)); uow.commit(); } } @@ -425,7 +493,8 @@ TEST(SortedDataInterface, Locate1) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - ASSERT_OK(sorted->insert(opCtx.get(), key, loc, true)); + ASSERT_OK( + sorted->insert(opCtx.get(), makeKeyString(sorted.get(), key, loc), loc, true)); uow.commit(); } } @@ -447,9 +516,18 @@ TEST(SortedDataInterface, Locate2) { { WriteUnitOfWork uow(opCtx.get()); - ASSERT_OK(sorted->insert(opCtx.get(), BSON("" << 1), RecordId(1, 2), true)); - ASSERT_OK(sorted->insert(opCtx.get(), BSON("" << 2), RecordId(1, 4), true)); - ASSERT_OK(sorted->insert(opCtx.get(), BSON("" << 3), RecordId(1, 6), true)); + ASSERT_OK(sorted->insert(opCtx.get(), + makeKeyString(sorted.get(), BSON("" << 1), RecordId(1, 2)), + RecordId(1, 2), + true)); + ASSERT_OK(sorted->insert(opCtx.get(), + makeKeyString(sorted.get(), BSON("" << 2), RecordId(1, 4)), + RecordId(1, 4), + true)); + ASSERT_OK(sorted->insert(opCtx.get(), + makeKeyString(sorted.get(), BSON("" << 3), RecordId(1, 6)), + RecordId(1, 6), + true)); uow.commit(); } } @@ -474,9 +552,18 @@ TEST(SortedDataInterface, Locate2Empty) { { WriteUnitOfWork uow(opCtx.get()); - ASSERT_OK(sorted->insert(opCtx.get(), BSON("" << 1), RecordId(1, 2), true)); - ASSERT_OK(sorted->insert(opCtx.get(), BSON("" << 2), RecordId(1, 4), true)); - ASSERT_OK(sorted->insert(opCtx.get(), BSON("" << 3), RecordId(1, 6), true)); + ASSERT_OK(sorted->insert(opCtx.get(), + makeKeyString(sorted.get(), BSON("" << 1), RecordId(1, 2)), + RecordId(1, 2), + true)); + ASSERT_OK(sorted->insert(opCtx.get(), + makeKeyString(sorted.get(), BSON("" << 2), RecordId(1, 4)), + RecordId(1, 4), + true)); + ASSERT_OK(sorted->insert(opCtx.get(), + makeKeyString(sorted.get(), BSON("" << 3), RecordId(1, 6)), + RecordId(1, 6), + true)); uow.commit(); } } @@ -510,7 +597,8 @@ TEST(SortedDataInterface, Locate3Descending) { continue; WriteUnitOfWork uow(opCtx.get()); auto entry = buildEntry(i); - ASSERT_OK(sorted->insert(opCtx.get(), entry.key, entry.loc, true)); + ASSERT_OK(sorted->insert( + opCtx.get(), makeKeyString(sorted.get(), entry.key, entry.loc), entry.loc, true)); uow.commit(); } } diff --git a/src/mongo/db/storage/sorted_data_interface_test_harness.h b/src/mongo/db/storage/sorted_data_interface_test_harness.h index b907e926101..067143d9c40 100644 --- a/src/mongo/db/storage/sorted_data_interface_test_harness.h +++ b/src/mongo/db/storage/sorted_data_interface_test_harness.h @@ -51,6 +51,7 @@ const BSONObj key5 = BSON("" << 5); const BSONObj key6 = BSON("" << 6); const BSONObj key7 = BSON("" << "\x00"); + const BSONObj key8 = BSON("" << "\xff"); @@ -101,6 +102,10 @@ public: bool unique, bool partial, std::initializer_list<IndexKeyEntry> toInsert); }; +KeyString::Value makeKeyString(SortedDataInterface* sorted, + BSONObj bsonKey, + boost::optional<RecordId> rid = boost::none); + /** * Inserts all entries in toInsert into index. * ASSERT_OKs the inserts. diff --git a/src/mongo/db/storage/sorted_data_interface_test_insert.cpp b/src/mongo/db/storage/sorted_data_interface_test_insert.cpp index efd183aef93..49ebc79d238 100644 --- a/src/mongo/db/storage/sorted_data_interface_test_insert.cpp +++ b/src/mongo/db/storage/sorted_data_interface_test_insert.cpp @@ -53,7 +53,8 @@ TEST(SortedDataInterface, Insert) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - ASSERT_OK(sorted->insert(opCtx.get(), key1, loc1, true)); + ASSERT_OK( + sorted->insert(opCtx.get(), makeKeyString(sorted.get(), key1, loc1), loc1, true)); uow.commit(); } } @@ -73,7 +74,7 @@ TEST(SortedDataInterface, InsertKeyString) { const std::unique_ptr<SortedDataInterface> sorted( harnessHelper->newSortedDataInterface(/*unique=*/false, /*partial=*/false)); - KeyString::Builder keyString1(sorted->getKeyStringVersion(), key1, sorted->getOrdering(), loc1); + auto keyString1 = makeKeyString(sorted.get(), key1, loc1); { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); @@ -84,7 +85,7 @@ TEST(SortedDataInterface, InsertKeyString) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - ASSERT_OK(sorted->insert(opCtx.get(), keyString1.getValueCopy(), loc1, true)); + ASSERT_OK(sorted->insert(opCtx.get(), keyString1, loc1, true)); uow.commit(); } } @@ -113,7 +114,8 @@ TEST(SortedDataInterface, InsertCompoundKey) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - ASSERT_OK(sorted->insert(opCtx.get(), compoundKey1a, loc1, true)); + ASSERT_OK(sorted->insert( + opCtx.get(), makeKeyString(sorted.get(), compoundKey1a, loc1), loc1, true)); uow.commit(); } } @@ -141,8 +143,10 @@ TEST(SortedDataInterface, InsertSameDiskLoc) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - ASSERT_OK(sorted->insert(opCtx.get(), key1, loc1, true)); - ASSERT_OK(sorted->insert(opCtx.get(), key2, loc1, true)); + ASSERT_OK( + sorted->insert(opCtx.get(), makeKeyString(sorted.get(), key1, loc1), loc1, true)); + ASSERT_OK( + sorted->insert(opCtx.get(), makeKeyString(sorted.get(), key2, loc1), loc1, true)); uow.commit(); } } @@ -156,7 +160,8 @@ TEST(SortedDataInterface, InsertSameDiskLoc) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - ASSERT_OK(sorted->insert(opCtx.get(), key3, loc1, true)); + ASSERT_OK( + sorted->insert(opCtx.get(), makeKeyString(sorted.get(), key3, loc1), loc1, true)); uow.commit(); } } @@ -184,8 +189,12 @@ TEST(SortedDataInterface, InsertSameDiskLocWithDupsAllowed) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - ASSERT_OK(sorted->insert(opCtx.get(), key1, loc1, false)); - ASSERT_OK(sorted->insert(opCtx.get(), key2, loc1, true /* allow duplicates */)); + ASSERT_OK( + sorted->insert(opCtx.get(), makeKeyString(sorted.get(), key1, loc1), loc1, false)); + ASSERT_OK(sorted->insert(opCtx.get(), + makeKeyString(sorted.get(), key2, loc1), + loc1, + true /* allow duplicates */)); uow.commit(); } } @@ -199,7 +208,10 @@ TEST(SortedDataInterface, InsertSameDiskLocWithDupsAllowed) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - ASSERT_OK(sorted->insert(opCtx.get(), key3, loc1, true /* allow duplicates */)); + ASSERT_OK(sorted->insert(opCtx.get(), + makeKeyString(sorted.get(), key3, loc1), + loc1, + true /* allow duplicates */)); uow.commit(); } } @@ -226,8 +238,10 @@ TEST(SortedDataInterface, InsertSameKey) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - ASSERT_OK(sorted->insert(opCtx.get(), key1, loc1, false)); - ASSERT_NOT_OK(sorted->insert(opCtx.get(), key1, loc2, false)); + ASSERT_OK( + sorted->insert(opCtx.get(), makeKeyString(sorted.get(), key1, loc1), loc1, false)); + ASSERT_NOT_OK( + sorted->insert(opCtx.get(), makeKeyString(sorted.get(), key1, loc2), loc2, false)); uow.commit(); } } @@ -244,7 +258,8 @@ TEST(SortedDataInterface, InsertSameKey) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - ASSERT_NOT_OK(sorted->insert(opCtx.get(), key1, loc2, false)); + ASSERT_NOT_OK( + sorted->insert(opCtx.get(), makeKeyString(sorted.get(), key1, loc2), loc2, false)); uow.commit(); } } @@ -336,9 +351,12 @@ void _testInsertSameKeyWithDupsAllowed(const RecordId locs[3]) { harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - ASSERT_OK(sorted->insert(opCtx.get(), key1, locs[0], false)); - ASSERT_OK(sorted->insert(opCtx.get(), key1, locs[1], true)); - ASSERT_OK(sorted->insert(opCtx.get(), key1, locs[2], true)); + ASSERT_OK(sorted->insert( + opCtx.get(), makeKeyString(sorted.get(), key1, locs[0]), locs[0], false)); + ASSERT_OK(sorted->insert( + opCtx.get(), makeKeyString(sorted.get(), key1, locs[1]), locs[1], true)); + ASSERT_OK(sorted->insert( + opCtx.get(), makeKeyString(sorted.get(), key1, locs[2]), locs[2], true)); uow.commit(); } } @@ -350,7 +368,8 @@ void _testInsertSameKeyWithDupsAllowed(const RecordId locs[3]) { WriteUnitOfWork uow(opCtx.get()); for (int i = 0; i < 3; i++) { if (i != keeper) { - sorted->unindex(opCtx.get(), key1, locs[i], true); + sorted->unindex( + opCtx.get(), makeKeyString(sorted.get(), key1, locs[i]), locs[i], true); } } uow.commit(); @@ -397,8 +416,10 @@ TEST(SortedDataInterface, InsertMultiple) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - ASSERT_OK(sorted->insert(opCtx.get(), key1, loc1, false)); - ASSERT_OK(sorted->insert(opCtx.get(), key2, loc2, false)); + ASSERT_OK( + sorted->insert(opCtx.get(), makeKeyString(sorted.get(), key1, loc1), loc1, false)); + ASSERT_OK( + sorted->insert(opCtx.get(), makeKeyString(sorted.get(), key2, loc2), loc2, false)); uow.commit(); } } @@ -416,7 +437,8 @@ TEST(SortedDataInterface, InsertMultiple) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - ASSERT_OK(sorted->insert(opCtx.get(), key3, loc3, false)); + ASSERT_OK( + sorted->insert(opCtx.get(), makeKeyString(sorted.get(), key3, loc3), loc3, false)); uow.commit(); } } @@ -441,9 +463,9 @@ TEST(SortedDataInterface, InsertMultipleKeyStrings) { const std::unique_ptr<SortedDataInterface> sorted( harnessHelper->newSortedDataInterface(/*unique=*/true, /*partial=*/false)); - KeyString::Builder keyString1(sorted->getKeyStringVersion(), key1, sorted->getOrdering(), loc1); - KeyString::Builder keyString2(sorted->getKeyStringVersion(), key2, sorted->getOrdering(), loc2); - KeyString::Builder keyString3(sorted->getKeyStringVersion(), key3, sorted->getOrdering(), loc3); + auto keyString1 = makeKeyString(sorted.get(), key1, loc1); + auto keyString2 = makeKeyString(sorted.get(), key2, loc2); + auto keyString3 = makeKeyString(sorted.get(), key3, loc3); { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); @@ -454,8 +476,8 @@ TEST(SortedDataInterface, InsertMultipleKeyStrings) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - ASSERT_OK(sorted->insert(opCtx.get(), keyString1.getValueCopy(), loc1, false)); - ASSERT_OK(sorted->insert(opCtx.get(), keyString2.getValueCopy(), loc2, false)); + ASSERT_OK(sorted->insert(opCtx.get(), keyString1, loc1, false)); + ASSERT_OK(sorted->insert(opCtx.get(), keyString2, loc2, false)); uow.commit(); } } @@ -473,7 +495,7 @@ TEST(SortedDataInterface, InsertMultipleKeyStrings) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - ASSERT_OK(sorted->insert(opCtx.get(), keyString3.getValueCopy(), loc3, false)); + ASSERT_OK(sorted->insert(opCtx.get(), keyString3, loc3, false)); uow.commit(); } } @@ -497,13 +519,11 @@ TEST(SortedDataInterface, InsertAndSeekKeyString) { const std::unique_ptr<SortedDataInterface> sorted( harnessHelper->newSortedDataInterface(/*unique=*/true, /*partial=*/false)); - KeyString::Builder keyString1(sorted->getKeyStringVersion(), key1, sorted->getOrdering(), loc1); - KeyString::Builder keyString2(sorted->getKeyStringVersion(), key2, sorted->getOrdering(), loc2); + auto keyString1 = makeKeyString(sorted.get(), key1, loc1); + auto keyString2 = makeKeyString(sorted.get(), key2, loc2); - KeyString::Builder keyString1WithoutRecordId( - sorted->getKeyStringVersion(), key1, sorted->getOrdering()); - KeyString::Builder keyString2WithoutRecordId( - sorted->getKeyStringVersion(), key2, sorted->getOrdering()); + auto keyString1WithoutRecordId = makeKeyString(sorted.get(), key1); + auto keyString2WithoutRecordId = makeKeyString(sorted.get(), key2); { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); @@ -514,8 +534,8 @@ TEST(SortedDataInterface, InsertAndSeekKeyString) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - ASSERT_OK(sorted->insert(opCtx.get(), keyString1.getValueCopy(), loc1, false)); - ASSERT_OK(sorted->insert(opCtx.get(), keyString2.getValueCopy(), loc2, false)); + ASSERT_OK(sorted->insert(opCtx.get(), keyString1, loc1, false)); + ASSERT_OK(sorted->insert(opCtx.get(), keyString2, loc2, false)); uow.commit(); } } @@ -526,13 +546,13 @@ TEST(SortedDataInterface, InsertAndSeekKeyString) { const std::unique_ptr<SortedDataInterface::Cursor> cursor(sorted->newCursor(opCtx.get())); - auto ksEntry1 = cursor->seek(keyString1WithoutRecordId.getValueCopy(), true); - ASSERT_EQUALS(ksEntry1->keyString.compare(keyString1.getValueCopy()), 0); - ASSERT_EQUALS(ksEntry1->keyString.compare(keyString2.getValueCopy()), -1); + auto ksEntry1 = cursor->seek(keyString1WithoutRecordId, true); + ASSERT_EQUALS(ksEntry1->keyString.compare(keyString1), 0); + ASSERT_EQUALS(ksEntry1->keyString.compare(keyString2), -1); - auto ksEntry2 = cursor->seek(keyString2WithoutRecordId.getValueCopy(), true); - ASSERT_EQUALS(ksEntry2->keyString.compare(keyString2.getValueCopy()), 0); - ASSERT_EQUALS(ksEntry2->keyString.compare(keyString1.getValueCopy()), 1); + auto ksEntry2 = cursor->seek(keyString2WithoutRecordId, true); + ASSERT_EQUALS(ksEntry2->keyString.compare(keyString2), 0); + ASSERT_EQUALS(ksEntry2->keyString.compare(keyString1), 1); } } @@ -544,13 +564,11 @@ TEST(SortedDataInterface, InsertAndSeekExactKeyString) { const std::unique_ptr<SortedDataInterface> sorted( harnessHelper->newSortedDataInterface(/*unique=*/true, /*partial=*/false)); - KeyString::Builder keyString1(sorted->getKeyStringVersion(), key1, sorted->getOrdering(), loc1); - KeyString::Builder keyString2(sorted->getKeyStringVersion(), key2, sorted->getOrdering(), loc2); + auto keyString1 = makeKeyString(sorted.get(), key1, loc1); + auto keyString2 = makeKeyString(sorted.get(), key2, loc2); - KeyString::Builder keyString1WithoutRecordId( - sorted->getKeyStringVersion(), key1, sorted->getOrdering()); - KeyString::Builder keyString2WithoutRecordId( - sorted->getKeyStringVersion(), key2, sorted->getOrdering()); + auto keyString1WithoutRecordId = makeKeyString(sorted.get(), key1); + auto keyString2WithoutRecordId = makeKeyString(sorted.get(), key2); { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); @@ -561,8 +579,8 @@ TEST(SortedDataInterface, InsertAndSeekExactKeyString) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - ASSERT_OK(sorted->insert(opCtx.get(), keyString1.getValueCopy(), loc1, false)); - ASSERT_OK(sorted->insert(opCtx.get(), keyString2.getValueCopy(), loc2, false)); + ASSERT_OK(sorted->insert(opCtx.get(), keyString1, loc1, false)); + ASSERT_OK(sorted->insert(opCtx.get(), keyString2, loc2, false)); uow.commit(); } } @@ -573,13 +591,13 @@ TEST(SortedDataInterface, InsertAndSeekExactKeyString) { const std::unique_ptr<SortedDataInterface::Cursor> cursor(sorted->newCursor(opCtx.get())); - auto ksEntry1 = cursor->seekExact(keyString1WithoutRecordId.getValueCopy()); - ASSERT_EQUALS(ksEntry1->keyString.compare(keyString1.getValueCopy()), 0); - ASSERT_EQUALS(ksEntry1->keyString.compare(keyString2.getValueCopy()), -1); + auto ksEntry1 = cursor->seekExact(keyString1WithoutRecordId); + ASSERT_EQUALS(ksEntry1->keyString.compare(keyString1), 0); + ASSERT_EQUALS(ksEntry1->keyString.compare(keyString2), -1); - auto ksEntry2 = cursor->seekExact(keyString2WithoutRecordId.getValueCopy()); - ASSERT_EQUALS(ksEntry2->keyString.compare(keyString2.getValueCopy()), 0); - ASSERT_EQUALS(ksEntry2->keyString.compare(keyString1.getValueCopy()), 1); + auto ksEntry2 = cursor->seekExact(keyString2WithoutRecordId); + ASSERT_EQUALS(ksEntry2->keyString.compare(keyString2), 0); + ASSERT_EQUALS(ksEntry2->keyString.compare(keyString1), 1); } } @@ -599,9 +617,12 @@ TEST(SortedDataInterface, InsertMultipleCompoundKeys) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - ASSERT_OK(sorted->insert(opCtx.get(), compoundKey1a, loc1, false)); - ASSERT_OK(sorted->insert(opCtx.get(), compoundKey1b, loc2, false)); - ASSERT_OK(sorted->insert(opCtx.get(), compoundKey2b, loc3, false)); + ASSERT_OK(sorted->insert( + opCtx.get(), makeKeyString(sorted.get(), compoundKey1a, loc1), loc1, false)); + ASSERT_OK(sorted->insert( + opCtx.get(), makeKeyString(sorted.get(), compoundKey1b, loc2), loc2, false)); + ASSERT_OK(sorted->insert( + opCtx.get(), makeKeyString(sorted.get(), compoundKey2b, loc3), loc3, false)); uow.commit(); } } @@ -615,8 +636,10 @@ TEST(SortedDataInterface, InsertMultipleCompoundKeys) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - ASSERT_OK(sorted->insert(opCtx.get(), compoundKey1c, loc4, false)); - ASSERT_OK(sorted->insert(opCtx.get(), compoundKey3a, loc5, false)); + ASSERT_OK(sorted->insert( + opCtx.get(), makeKeyString(sorted.get(), compoundKey1c, loc4), loc4, false)); + ASSERT_OK(sorted->insert( + opCtx.get(), makeKeyString(sorted.get(), compoundKey3a, loc5), loc5, false)); uow.commit(); } } @@ -636,7 +659,10 @@ TEST(SortedDataInterface, InsertReservedRecordId) { WriteUnitOfWork uow(opCtx.get()); RecordId reservedLoc(RecordId::ReservedId::kWildcardMultikeyMetadataId); ASSERT(reservedLoc.isReserved()); - ASSERT_OK(sorted->insert(opCtx.get(), key1, reservedLoc, /*dupsAllowed*/ true)); + ASSERT_OK(sorted->insert(opCtx.get(), + makeKeyString(sorted.get(), key1, reservedLoc), + reservedLoc, + /*dupsAllowed*/ true)); uow.commit(); ASSERT_EQUALS(1, sorted->numEntries(opCtx.get())); } diff --git a/src/mongo/db/storage/sorted_data_interface_test_isempty.cpp b/src/mongo/db/storage/sorted_data_interface_test_isempty.cpp index 4263b251e97..1e707b94003 100644 --- a/src/mongo/db/storage/sorted_data_interface_test_isempty.cpp +++ b/src/mongo/db/storage/sorted_data_interface_test_isempty.cpp @@ -54,7 +54,8 @@ TEST(SortedDataInterface, IsEmpty) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - ASSERT_OK(sorted->insert(opCtx.get(), key1, loc1, false)); + ASSERT_OK( + sorted->insert(opCtx.get(), makeKeyString(sorted.get(), key1, loc1), loc1, false)); uow.commit(); } } @@ -68,7 +69,7 @@ TEST(SortedDataInterface, IsEmpty) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - sorted->unindex(opCtx.get(), key1, loc1, false); + sorted->unindex(opCtx.get(), makeKeyString(sorted.get(), key1, loc1), loc1, false); ASSERT(sorted->isEmpty(opCtx.get())); uow.commit(); } diff --git a/src/mongo/db/storage/sorted_data_interface_test_rollback.cpp b/src/mongo/db/storage/sorted_data_interface_test_rollback.cpp index 16ec6127486..1bf15ceb744 100644 --- a/src/mongo/db/storage/sorted_data_interface_test_rollback.cpp +++ b/src/mongo/db/storage/sorted_data_interface_test_rollback.cpp @@ -53,7 +53,8 @@ TEST(SortedDataInterface, InsertWithoutCommit) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - ASSERT_OK(sorted->insert(opCtx.get(), key1, loc1, false)); + ASSERT_OK( + sorted->insert(opCtx.get(), makeKeyString(sorted.get(), key1, loc1), loc1, false)); // no commit } } @@ -67,8 +68,10 @@ TEST(SortedDataInterface, InsertWithoutCommit) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - ASSERT_OK(sorted->insert(opCtx.get(), key2, loc1, false)); - ASSERT_OK(sorted->insert(opCtx.get(), key3, loc2, false)); + ASSERT_OK( + sorted->insert(opCtx.get(), makeKeyString(sorted.get(), key2, loc1), loc1, false)); + ASSERT_OK( + sorted->insert(opCtx.get(), makeKeyString(sorted.get(), key3, loc2), loc2, false)); // no commit } } @@ -96,8 +99,10 @@ TEST(SortedDataInterface, UnindexWithoutCommit) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - ASSERT_OK(sorted->insert(opCtx.get(), key1, loc1, true)); - ASSERT_OK(sorted->insert(opCtx.get(), key2, loc2, true)); + ASSERT_OK( + sorted->insert(opCtx.get(), makeKeyString(sorted.get(), key1, loc1), loc1, true)); + ASSERT_OK( + sorted->insert(opCtx.get(), makeKeyString(sorted.get(), key2, loc2), loc2, true)); uow.commit(); } } @@ -111,7 +116,7 @@ TEST(SortedDataInterface, UnindexWithoutCommit) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - sorted->unindex(opCtx.get(), key2, loc2, true); + sorted->unindex(opCtx.get(), makeKeyString(sorted.get(), key2, loc2), loc2, true); ASSERT_EQUALS(1, sorted->numEntries(opCtx.get())); // no commit } @@ -126,7 +131,8 @@ TEST(SortedDataInterface, UnindexWithoutCommit) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - ASSERT_OK(sorted->insert(opCtx.get(), key3, loc3, true)); + ASSERT_OK( + sorted->insert(opCtx.get(), makeKeyString(sorted.get(), key3, loc3), loc3, true)); uow.commit(); } } @@ -140,9 +146,9 @@ TEST(SortedDataInterface, UnindexWithoutCommit) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - sorted->unindex(opCtx.get(), key1, loc1, true); + sorted->unindex(opCtx.get(), makeKeyString(sorted.get(), key1, loc1), loc1, true); ASSERT_EQUALS(2, sorted->numEntries(opCtx.get())); - sorted->unindex(opCtx.get(), key3, loc3, true); + sorted->unindex(opCtx.get(), makeKeyString(sorted.get(), key3, loc3), loc3, true); ASSERT_EQUALS(1, sorted->numEntries(opCtx.get())); // no commit } diff --git a/src/mongo/db/storage/sorted_data_interface_test_spaceused.cpp b/src/mongo/db/storage/sorted_data_interface_test_spaceused.cpp index 80a1ed3e2e6..505ac0c7c53 100644 --- a/src/mongo/db/storage/sorted_data_interface_test_spaceused.cpp +++ b/src/mongo/db/storage/sorted_data_interface_test_spaceused.cpp @@ -47,14 +47,6 @@ TEST(SortedDataInterface, GetSpaceUsedBytesEmpty) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); ASSERT(sorted->isEmpty(opCtx.get())); } - - // SERVER-15416 mmapv1 test harness does not use SimpleRecordStoreV1 as its record store - // and HeapRecordStoreBtree::dataSize does not have an actual implementation - // { - // const ServiceContext::UniqueOperationContext opCtx( harnessHelper->newOperationContext() - // ); - // ASSERT( sorted->getSpaceUsedBytes( opCtx.get() ) == 0 ); - // } } // Verify that a nonempty index takes up some space. @@ -75,7 +67,8 @@ TEST(SortedDataInterface, GetSpaceUsedBytesNonEmpty) { WriteUnitOfWork uow(opCtx.get()); BSONObj key = BSON("" << i); RecordId loc(42, i * 2); - ASSERT_OK(sorted->insert(opCtx.get(), key, loc, true)); + ASSERT_OK( + sorted->insert(opCtx.get(), makeKeyString(sorted.get(), key, loc), loc, true)); uow.commit(); } } @@ -84,25 +77,6 @@ TEST(SortedDataInterface, GetSpaceUsedBytesNonEmpty) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); ASSERT_EQUALS(nToInsert, sorted->numEntries(opCtx.get())); } - - // SERVER-15416 mmapv1 test harness does not use SimpleRecordStoreV1 as its record store - // and HeapRecordStoreBtree::dataSize does not have an actual implementation - // long long spaceUsedBytes; - // { - // const ServiceContext::UniqueOperationContext opCtx( harnessHelper->newOperationContext() - // ); - // spaceUsedBytes = sorted->getSpaceUsedBytes( opCtx.get() ); - // ASSERT( spaceUsedBytes > 0 ); - // } - - // { - // // getSpaceUsedBytes() returns the same value when called multiple times - // // and there were not interleaved write operations. - // const ServiceContext::UniqueOperationContext opCtx( harnessHelper->newOperationContext() - // ); - // ASSERT_EQUALS( spaceUsedBytes, sorted->getSpaceUsedBytes( opCtx.get() ) ); - // ASSERT_EQUALS( spaceUsedBytes, sorted->getSpaceUsedBytes( opCtx.get() ) ); - // } } } // namespace diff --git a/src/mongo/db/storage/sorted_data_interface_test_touch.cpp b/src/mongo/db/storage/sorted_data_interface_test_touch.cpp index 5b516b6776a..3eacc8fb745 100644 --- a/src/mongo/db/storage/sorted_data_interface_test_touch.cpp +++ b/src/mongo/db/storage/sorted_data_interface_test_touch.cpp @@ -65,9 +65,12 @@ TEST(SortedDataInterface, TouchNonEmpty) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - ASSERT_OK(sorted->insert(opCtx.get(), key1, loc1, false)); - ASSERT_OK(sorted->insert(opCtx.get(), key2, loc2, false)); - ASSERT_OK(sorted->insert(opCtx.get(), key3, loc3, false)); + ASSERT_OK( + sorted->insert(opCtx.get(), makeKeyString(sorted.get(), key1, loc1), loc1, false)); + ASSERT_OK( + sorted->insert(opCtx.get(), makeKeyString(sorted.get(), key2, loc2), loc2, false)); + ASSERT_OK( + sorted->insert(opCtx.get(), makeKeyString(sorted.get(), key3, loc3), loc3, false)); uow.commit(); } } diff --git a/src/mongo/db/storage/sorted_data_interface_test_unindex.cpp b/src/mongo/db/storage/sorted_data_interface_test_unindex.cpp index ff1956110ca..9da2eb2f265 100644 --- a/src/mongo/db/storage/sorted_data_interface_test_unindex.cpp +++ b/src/mongo/db/storage/sorted_data_interface_test_unindex.cpp @@ -52,7 +52,8 @@ void unindex(bool partial) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - ASSERT_OK(sorted->insert(opCtx.get(), key1, loc1, true)); + ASSERT_OK( + sorted->insert(opCtx.get(), makeKeyString(sorted.get(), key1, loc1), loc1, true)); uow.commit(); } } @@ -66,7 +67,7 @@ void unindex(bool partial) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - sorted->unindex(opCtx.get(), key1, loc1, true); + sorted->unindex(opCtx.get(), makeKeyString(sorted.get(), key1, loc1), loc1, true); ASSERT(sorted->isEmpty(opCtx.get())); uow.commit(); } @@ -94,7 +95,7 @@ void unindexKeyString(bool partial) { const std::unique_ptr<SortedDataInterface> sorted( harnessHelper->newSortedDataInterface(/*unique=*/false, partial)); - KeyString::Builder keyString1(sorted->getKeyStringVersion(), key1, sorted->getOrdering(), loc1); + auto keyString1 = makeKeyString(sorted.get(), key1, loc1); { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); @@ -105,7 +106,7 @@ void unindexKeyString(bool partial) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - ASSERT_OK(sorted->insert(opCtx.get(), keyString1.getValueCopy(), loc1, true)); + ASSERT_OK(sorted->insert(opCtx.get(), keyString1, loc1, true)); uow.commit(); } } @@ -119,7 +120,7 @@ void unindexKeyString(bool partial) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - sorted->unindex(opCtx.get(), keyString1.getValueCopy(), loc1, true); + sorted->unindex(opCtx.get(), keyString1, loc1, true); ASSERT(sorted->isEmpty(opCtx.get())); uow.commit(); } @@ -154,7 +155,8 @@ void unindexCompoundKey(bool partial) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - ASSERT_OK(sorted->insert(opCtx.get(), compoundKey1a, loc1, true)); + ASSERT_OK(sorted->insert( + opCtx.get(), makeKeyString(sorted.get(), compoundKey1a, loc1), loc1, true)); uow.commit(); } } @@ -168,7 +170,8 @@ void unindexCompoundKey(bool partial) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - sorted->unindex(opCtx.get(), compoundKey1a, loc1, true); + sorted->unindex( + opCtx.get(), makeKeyString(sorted.get(), compoundKey1a, loc1), loc1, true); ASSERT(sorted->isEmpty(opCtx.get())); uow.commit(); } @@ -203,8 +206,10 @@ void unindexMultipleDistinct(bool partial) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - ASSERT_OK(sorted->insert(opCtx.get(), key1, loc1, true)); - ASSERT_OK(sorted->insert(opCtx.get(), key2, loc2, true)); + ASSERT_OK( + sorted->insert(opCtx.get(), makeKeyString(sorted.get(), key1, loc1), loc1, true)); + ASSERT_OK( + sorted->insert(opCtx.get(), makeKeyString(sorted.get(), key2, loc2), loc2, true)); uow.commit(); } } @@ -218,7 +223,7 @@ void unindexMultipleDistinct(bool partial) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - sorted->unindex(opCtx.get(), key2, loc2, true); + sorted->unindex(opCtx.get(), makeKeyString(sorted.get(), key2, loc2), loc2, true); ASSERT_EQUALS(1, sorted->numEntries(opCtx.get())); uow.commit(); } @@ -233,7 +238,8 @@ void unindexMultipleDistinct(bool partial) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - ASSERT_OK(sorted->insert(opCtx.get(), key3, loc3, true)); + ASSERT_OK( + sorted->insert(opCtx.get(), makeKeyString(sorted.get(), key3, loc3), loc3, true)); uow.commit(); } } @@ -247,9 +253,9 @@ void unindexMultipleDistinct(bool partial) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - sorted->unindex(opCtx.get(), key1, loc1, true); + sorted->unindex(opCtx.get(), makeKeyString(sorted.get(), key1, loc1), loc1, true); ASSERT_EQUALS(1, sorted->numEntries(opCtx.get())); - sorted->unindex(opCtx.get(), key3, loc3, true); + sorted->unindex(opCtx.get(), makeKeyString(sorted.get(), key3, loc3), loc3, true); ASSERT(sorted->isEmpty(opCtx.get())); uow.commit(); } @@ -284,8 +290,12 @@ void unindexMultipleSameKey(bool partial) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - ASSERT_OK(sorted->insert(opCtx.get(), key1, loc1, true)); - ASSERT_OK(sorted->insert(opCtx.get(), key1, loc2, true /* allow duplicates */)); + ASSERT_OK( + sorted->insert(opCtx.get(), makeKeyString(sorted.get(), key1, loc1), loc1, true)); + ASSERT_OK(sorted->insert(opCtx.get(), + makeKeyString(sorted.get(), key1, loc2), + loc2, + true /* allow duplicates */)); uow.commit(); } } @@ -299,7 +309,7 @@ void unindexMultipleSameKey(bool partial) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - sorted->unindex(opCtx.get(), key1, loc2, true); + sorted->unindex(opCtx.get(), makeKeyString(sorted.get(), key1, loc2), loc2, true); ASSERT_EQUALS(1, sorted->numEntries(opCtx.get())); uow.commit(); } @@ -314,7 +324,10 @@ void unindexMultipleSameKey(bool partial) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - ASSERT_OK(sorted->insert(opCtx.get(), key1, loc3, true /* allow duplicates */)); + ASSERT_OK(sorted->insert(opCtx.get(), + makeKeyString(sorted.get(), key1, loc3), + loc3, + true /* allow duplicates */)); uow.commit(); } } @@ -328,9 +341,9 @@ void unindexMultipleSameKey(bool partial) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - sorted->unindex(opCtx.get(), key1, loc1, true); + sorted->unindex(opCtx.get(), makeKeyString(sorted.get(), key1, loc1), loc1, true); ASSERT_EQUALS(1, sorted->numEntries(opCtx.get())); - sorted->unindex(opCtx.get(), key1, loc3, true); + sorted->unindex(opCtx.get(), makeKeyString(sorted.get(), key1, loc3), loc3, true); ASSERT(sorted->isEmpty(opCtx.get())); uow.commit(); } @@ -359,12 +372,9 @@ void unindexMultipleSameKeyString(bool partial) { const std::unique_ptr<SortedDataInterface> sorted( harnessHelper->newSortedDataInterface(/*unique=*/false, partial)); - KeyString::Builder keyStringLoc1( - sorted->getKeyStringVersion(), key1, sorted->getOrdering(), loc1); - KeyString::Builder keyStringLoc2( - sorted->getKeyStringVersion(), key1, sorted->getOrdering(), loc2); - KeyString::Builder keyStringLoc3( - sorted->getKeyStringVersion(), key1, sorted->getOrdering(), loc3); + auto keyStringLoc1 = makeKeyString(sorted.get(), key1, loc1); + auto keyStringLoc2 = makeKeyString(sorted.get(), key1, loc2); + auto keyStringLoc3 = makeKeyString(sorted.get(), key1, loc3); { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); @@ -375,9 +385,9 @@ void unindexMultipleSameKeyString(bool partial) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - ASSERT_OK(sorted->insert(opCtx.get(), keyStringLoc1.getValueCopy(), loc1, true)); - ASSERT_OK(sorted->insert( - opCtx.get(), keyStringLoc2.getValueCopy(), loc2, true /* allow duplicates */)); + ASSERT_OK(sorted->insert(opCtx.get(), keyStringLoc1, loc1, true)); + ASSERT_OK( + sorted->insert(opCtx.get(), keyStringLoc2, loc2, true /* allow duplicates */)); uow.commit(); } } @@ -391,7 +401,7 @@ void unindexMultipleSameKeyString(bool partial) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - sorted->unindex(opCtx.get(), keyStringLoc2.getValueCopy(), loc2, true); + sorted->unindex(opCtx.get(), keyStringLoc2, loc2, true); ASSERT_EQUALS(1, sorted->numEntries(opCtx.get())); uow.commit(); } @@ -406,8 +416,8 @@ void unindexMultipleSameKeyString(bool partial) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - ASSERT_OK(sorted->insert( - opCtx.get(), keyStringLoc3.getValueCopy(), loc3, true /* allow duplicates */)); + ASSERT_OK( + sorted->insert(opCtx.get(), keyStringLoc3, loc3, true /* allow duplicates */)); uow.commit(); } } @@ -421,9 +431,9 @@ void unindexMultipleSameKeyString(bool partial) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - sorted->unindex(opCtx.get(), keyStringLoc1.getValueCopy(), loc1, true); + sorted->unindex(opCtx.get(), keyStringLoc1, loc1, true); ASSERT_EQUALS(1, sorted->numEntries(opCtx.get())); - sorted->unindex(opCtx.get(), keyStringLoc3.getValueCopy(), loc3, true); + sorted->unindex(opCtx.get(), keyStringLoc3, loc3, true); ASSERT(sorted->isEmpty(opCtx.get())); uow.commit(); } @@ -459,7 +469,7 @@ void unindexEmpty(bool partial) { const ServiceContext::UniqueOperationContext opCtx(harnessHelper->newOperationContext()); { WriteUnitOfWork uow(opCtx.get()); - sorted->unindex(opCtx.get(), key1, loc1, true); + sorted->unindex(opCtx.get(), makeKeyString(sorted.get(), key1, loc1), loc1, true); ASSERT(sorted->isEmpty(opCtx.get())); uow.commit(); } @@ -490,7 +500,8 @@ TEST(SortedDataInterface, PartialIndex) { { { WriteUnitOfWork uow(opCtx.get()); - ASSERT_OK(sorted->insert(opCtx.get(), key1, loc1, true)); + ASSERT_OK(sorted->insert( + opCtx.get(), makeKeyString(sorted.get(), key1, loc1), loc1, true)); // Assume key1 with loc2 was never indexed due to the partial index. ASSERT_EQUALS(1, sorted->numEntries(opCtx.get())); uow.commit(); @@ -499,14 +510,14 @@ TEST(SortedDataInterface, PartialIndex) { { WriteUnitOfWork uow(opCtx.get()); // Shouldn't unindex anything as key1 with loc2 wasn't indexed in the first place. - sorted->unindex(opCtx.get(), key1, loc2, true); + sorted->unindex(opCtx.get(), makeKeyString(sorted.get(), key1, loc2), loc2, true); ASSERT_EQUALS(1, sorted->numEntries(opCtx.get())); uow.commit(); } { WriteUnitOfWork uow(opCtx.get()); - sorted->unindex(opCtx.get(), key1, loc1, true); + sorted->unindex(opCtx.get(), makeKeyString(sorted.get(), key1, loc1), loc1, true); ASSERT(sorted->isEmpty(opCtx.get())); uow.commit(); } diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_index.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_index.cpp index af7509fe5c7..b44af768b5c 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_index.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_index.cpp @@ -245,21 +245,6 @@ WiredTigerIndex::WiredTigerIndex(OperationContext* ctx, _isIdIndex(desc->isIdIndex()) {} Status WiredTigerIndex::insert(OperationContext* opCtx, - const BSONObj& key, - const RecordId& id, - bool dupsAllowed) { - dassert(opCtx->lockState()->isWriteLocked()); - invariant(id.isValid()); - dassert(!key.hasFieldNames()); - - TRACE_INDEX << " key: " << key << " id: " << id; - - KeyString::HeapBuilder keyString(getKeyStringVersion(), key, _ordering, id); - - return insert(opCtx, std::move(keyString.release()), id, dupsAllowed); -} - -Status WiredTigerIndex::insert(OperationContext* opCtx, const KeyString::Value& keyString, const RecordId& id, bool dupsAllowed) { @@ -276,20 +261,10 @@ Status WiredTigerIndex::insert(OperationContext* opCtx, } void WiredTigerIndex::unindex(OperationContext* opCtx, - const BSONObj& key, - const RecordId& id, - bool dupsAllowed) { - invariant(id.isValid()); - dassert(!key.hasFieldNames()); - KeyString::HeapBuilder keyString(getKeyStringVersion(), key, _ordering, id); - - unindex(opCtx, std::move(keyString.release()), id, dupsAllowed); -} - -void WiredTigerIndex::unindex(OperationContext* opCtx, const KeyString::Value& keyString, const RecordId& id, bool dupsAllowed) { + invariant(id.isValid()); dassert(opCtx->lockState()->isWriteLocked()); dassert(id == KeyString::decodeRecordIdAtEnd(keyString.getBuffer(), keyString.getSize())); diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_index.h b/src/mongo/db/storage/wiredtiger/wiredtiger_index.h index e3b42807a3c..e291f48c0ab 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_index.h +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_index.h @@ -92,21 +92,11 @@ public: bool readOnly); virtual Status insert(OperationContext* opCtx, - const BSONObj& key, - const RecordId& id, - bool dupsAllowed); - - virtual Status insert(OperationContext* opCtx, const KeyString::Value& keyString, const RecordId& id, bool dupsAllowed); virtual void unindex(OperationContext* opCtx, - const BSONObj& key, - const RecordId& id, - bool dupsAllowed); - - virtual void unindex(OperationContext* opCtx, const KeyString::Value& keyString, const RecordId& id, bool dupsAllowed); diff --git a/src/mongo/dbtests/validate_tests.cpp b/src/mongo/dbtests/validate_tests.cpp index e813b21cef2..3dc69fe840a 100644 --- a/src/mongo/dbtests/validate_tests.cpp +++ b/src/mongo/dbtests/validate_tests.cpp @@ -982,8 +982,13 @@ public: auto sortedDataInterface = accessMethod->getSortedDataInterface(); { WriteUnitOfWork wunit(&_opCtx); - const BSONObj indexKey = BSON("" << 1 << "" - << "non_existent_path"); + const KeyString::Value indexKey = + KeyString::HeapBuilder(sortedDataInterface->getKeyStringVersion(), + BSON("" << 1 << "" + << "non_existent_path"), + sortedDataInterface->getOrdering(), + recordId) + .release(); auto insertStatus = sortedDataInterface->insert(&_opCtx, indexKey, recordId, true /* dupsAllowed */); ASSERT_OK(insertStatus); @@ -999,8 +1004,13 @@ public: lockDb(MODE_X); { WriteUnitOfWork wunit(&_opCtx); - const BSONObj indexKey = BSON("" << 1 << "" - << "mk_1"); + const KeyString::Value indexKey = + KeyString::HeapBuilder(sortedDataInterface->getKeyStringVersion(), + BSON("" << 1 << "" + << "mk_1"), + sortedDataInterface->getOrdering(), + recordId) + .release(); sortedDataInterface->unindex(&_opCtx, indexKey, recordId, true /* dupsAllowed */); wunit.commit(); } @@ -1092,9 +1102,14 @@ public: lockDb(MODE_X); { WriteUnitOfWork wunit(&_opCtx); - const BSONObj indexKey = BSON("" << 1 << "" - << "a"); RecordId recordId(RecordId::ReservedId::kWildcardMultikeyMetadataId); + const KeyString::Value indexKey = + KeyString::HeapBuilder(sortedDataInterface->getKeyStringVersion(), + BSON("" << 1 << "" + << "a"), + sortedDataInterface->getOrdering(), + recordId) + .release(); sortedDataInterface->unindex(&_opCtx, indexKey, recordId, true /* dupsAllowed */); wunit.commit(); } |