diff options
Diffstat (limited to 'src/mongo/db')
-rw-r--r-- | src/mongo/db/exec/fetch.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/exec/idhack.cpp | 3 | ||||
-rw-r--r-- | src/mongo/db/exec/text_or.cpp | 3 | ||||
-rw-r--r-- | src/mongo/db/exec/working_set_common.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/exec/working_set_common.h | 3 | ||||
-rw-r--r-- | src/mongo/db/exec/write_stage_common.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/sorter/sorter.cpp | 5 | ||||
-rw-r--r-- | src/mongo/db/sorter/sorter_test.cpp | 41 | ||||
-rw-r--r-- | src/mongo/db/storage/devnull/ephemeral_catalog_record_store.cpp | 1 | ||||
-rw-r--r-- | src/mongo/db/storage/sorted_data_interface_test_cursor_end_position.cpp | 24 | ||||
-rw-r--r-- | src/mongo/db/storage/sorted_data_interface_test_cursor_saverestore.cpp | 60 | ||||
-rw-r--r-- | src/mongo/db/storage/sorted_data_interface_test_harness.cpp | 14 | ||||
-rw-r--r-- | src/mongo/db/storage/sorted_data_interface_test_harness.h | 21 | ||||
-rw-r--r-- | src/mongo/db/storage/test_harness_helper.h | 1 |
14 files changed, 92 insertions, 90 deletions
diff --git a/src/mongo/db/exec/fetch.cpp b/src/mongo/db/exec/fetch.cpp index 166b4604f8b..4a64709505f 100644 --- a/src/mongo/db/exec/fetch.cpp +++ b/src/mongo/db/exec/fetch.cpp @@ -103,7 +103,7 @@ PlanStage::StageState FetchStage::doWork(WorkingSetID* out) { if (!_cursor) _cursor = collection()->getCursor(opCtx()); - if (!WorkingSetCommon::fetch(opCtx(), _ws, id, _cursor, collection()->ns())) { + if (!WorkingSetCommon::fetch(opCtx(), _ws, id, _cursor.get(), collection()->ns())) { _ws->free(id); return NEED_TIME; } diff --git a/src/mongo/db/exec/idhack.cpp b/src/mongo/db/exec/idhack.cpp index 304a18beb18..dedaf0ad30a 100644 --- a/src/mongo/db/exec/idhack.cpp +++ b/src/mongo/db/exec/idhack.cpp @@ -107,7 +107,8 @@ PlanStage::StageState IDHackStage::doWork(WorkingSetID* out) { _recordCursor = collection()->getCursor(opCtx()); // Find the document associated with 'id' in the collection's record store. - if (!WorkingSetCommon::fetch(opCtx(), _workingSet, id, _recordCursor, collection()->ns())) { + if (!WorkingSetCommon::fetch( + opCtx(), _workingSet, id, _recordCursor.get(), collection()->ns())) { // We didn't find a document with RecordId 'id'. _workingSet->free(id); _commonStats.isEOF = true; diff --git a/src/mongo/db/exec/text_or.cpp b/src/mongo/db/exec/text_or.cpp index f9f3d012358..d51316a51ee 100644 --- a/src/mongo/db/exec/text_or.cpp +++ b/src/mongo/db/exec/text_or.cpp @@ -255,7 +255,8 @@ PlanStage::StageState TextOrStage::addTerm(WorkingSetID wsid, WorkingSetID* out) // Our parent expects RID_AND_OBJ members, so we fetch the document here if we haven't // already. try { - if (!WorkingSetCommon::fetch(opCtx(), _ws, wsid, _recordCursor, collection()->ns())) { + if (!WorkingSetCommon::fetch( + opCtx(), _ws, wsid, _recordCursor.get(), collection()->ns())) { _ws->free(wsid); textRecordData->score = -1; return NEED_TIME; diff --git a/src/mongo/db/exec/working_set_common.cpp b/src/mongo/db/exec/working_set_common.cpp index 33a9f6074e7..a96bac88dfc 100644 --- a/src/mongo/db/exec/working_set_common.cpp +++ b/src/mongo/db/exec/working_set_common.cpp @@ -69,7 +69,7 @@ std::string indexKeyVectorDebugString(const std::vector<IndexKeyDatum>& keyData) bool WorkingSetCommon::fetch(OperationContext* opCtx, WorkingSet* workingSet, WorkingSetID id, - unowned_ptr<SeekableRecordCursor> cursor, + SeekableRecordCursor* cursor, const NamespaceString& ns) { WorkingSetMember* member = workingSet->get(id); diff --git a/src/mongo/db/exec/working_set_common.h b/src/mongo/db/exec/working_set_common.h index b03b29a9682..ccc64a4cc58 100644 --- a/src/mongo/db/exec/working_set_common.h +++ b/src/mongo/db/exec/working_set_common.h @@ -31,7 +31,6 @@ #include "mongo/db/exec/working_set.h" #include "mongo/db/namespace_string.h" -#include "mongo/util/unowned_ptr.h" namespace mongo { @@ -52,7 +51,7 @@ public: static bool fetch(OperationContext* opCtx, WorkingSet* workingSet, WorkingSetID id, - unowned_ptr<SeekableRecordCursor> cursor, + SeekableRecordCursor* cursor, const NamespaceString& ns); }; diff --git a/src/mongo/db/exec/write_stage_common.cpp b/src/mongo/db/exec/write_stage_common.cpp index b060d57ab45..ddd6ca80204 100644 --- a/src/mongo/db/exec/write_stage_common.cpp +++ b/src/mongo/db/exec/write_stage_common.cpp @@ -50,7 +50,7 @@ bool ensureStillMatches(const CollectionPtr& collection, if (opCtx->recoveryUnit()->getSnapshotId() != member->doc.snapshotId()) { std::unique_ptr<SeekableRecordCursor> cursor(collection->getCursor(opCtx)); - if (!WorkingSetCommon::fetch(opCtx, ws, id, cursor, collection->ns())) { + if (!WorkingSetCommon::fetch(opCtx, ws, id, cursor.get(), collection->ns())) { // Doc is already deleted. return false; } diff --git a/src/mongo/db/sorter/sorter.cpp b/src/mongo/db/sorter/sorter.cpp index 82900d849cd..4a0aa54156f 100644 --- a/src/mongo/db/sorter/sorter.cpp +++ b/src/mongo/db/sorter/sorter.cpp @@ -64,7 +64,6 @@ #include "mongo/util/assert_util.h" #include "mongo/util/destructor_guard.h" #include "mongo/util/str.h" -#include "mongo/util/unowned_ptr.h" namespace mongo { @@ -518,7 +517,9 @@ private: class STLComparator { // uses greater rather than less-than to maintain a MinHeap public: explicit STLComparator(const Comparator& comp) : _comp(comp) {} - bool operator()(unowned_ptr<const Stream> lhs, unowned_ptr<const Stream> rhs) const { + + template <typename Ptr> + bool operator()(const Ptr& lhs, const Ptr& rhs) const { // first compare data dassertCompIsSane(_comp, lhs->current(), rhs->current()); int ret = _comp(lhs->current(), rhs->current()); diff --git a/src/mongo/db/sorter/sorter_test.cpp b/src/mongo/db/sorter/sorter_test.cpp index 2b6d4a1d3e9..3eb3eff7023 100644 --- a/src/mongo/db/sorter/sorter_test.cpp +++ b/src/mongo/db/sorter/sorter_test.cpp @@ -372,22 +372,23 @@ public: const SortOptions opts = SortOptions().TempDir(tempDir.path()).ExtSortAllowed(); { // test empty (no limit) - ASSERT_ITERATORS_EQUIVALENT(done(makeSorter(opts)), std::make_shared<EmptyIterator>()); + ASSERT_ITERATORS_EQUIVALENT(done(makeSorter(opts).get()), + std::make_shared<EmptyIterator>()); } { // test empty (limit 1) - ASSERT_ITERATORS_EQUIVALENT(done(makeSorter(SortOptions(opts).Limit(1))), + ASSERT_ITERATORS_EQUIVALENT(done(makeSorter(SortOptions(opts).Limit(1)).get()), std::make_shared<EmptyIterator>()); } { // test empty (limit 10) - ASSERT_ITERATORS_EQUIVALENT(done(makeSorter(SortOptions(opts).Limit(10))), + ASSERT_ITERATORS_EQUIVALENT(done(makeSorter(SortOptions(opts).Limit(10)).get()), std::make_shared<EmptyIterator>()); } const auto runTests = [this, &opts](bool assertRanges) { { // test all data ASC std::shared_ptr<IWSorter> sorter = makeSorter(opts, IWComparator(ASC)); - addData(sorter); - ASSERT_ITERATORS_EQUIVALENT(done(sorter), correct()); + addData(sorter.get()); + ASSERT_ITERATORS_EQUIVALENT(done(sorter.get()), correct()); ASSERT_EQ(numAdded(), sorter->numSorted()); if (assertRanges) { assertRangeInfo(sorter, opts); @@ -395,8 +396,8 @@ public: } { // test all data DESC std::shared_ptr<IWSorter> sorter = makeSorter(opts, IWComparator(DESC)); - addData(sorter); - ASSERT_ITERATORS_EQUIVALENT(done(sorter), correctReverse()); + addData(sorter.get()); + ASSERT_ITERATORS_EQUIVALENT(done(sorter.get()), correctReverse()); ASSERT_EQ(numAdded(), sorter->numSorted()); if (assertRanges) { assertRangeInfo(sorter, opts); @@ -410,10 +411,11 @@ public: std::shared_ptr<IWSorter> sorters[] = {makeSorter(opts, IWComparator(ASC)), makeSorter(opts, IWComparator(ASC))}; - addData(sorters[0]); - addData(sorters[1]); + addData(sorters[0].get()); + addData(sorters[1].get()); - std::shared_ptr<IWIterator> iters1[] = {done(sorters[0]), done(sorters[1])}; + std::shared_ptr<IWIterator> iters1[] = {done(sorters[0].get()), + done(sorters[1].get())}; std::shared_ptr<IWIterator> iters2[] = {correct(), correct()}; ASSERT_ITERATORS_EQUIVALENT(mergeIterators(iters1, ASC), mergeIterators(iters2, ASC)); @@ -427,11 +429,12 @@ public: std::shared_ptr<IWSorter> sorters[] = {makeSorter(opts, IWComparator(DESC)), makeSorter(opts, IWComparator(DESC))}; - stdx::thread inBackground(&Basic::addData, this, sorters[0]); - addData(sorters[1]); + stdx::thread inBackground(&Basic::addData, this, sorters[0].get()); + addData(sorters[1].get()); inBackground.join(); - std::shared_ptr<IWIterator> iters1[] = {done(sorters[0]), done(sorters[1])}; + std::shared_ptr<IWIterator> iters1[] = {done(sorters[0].get()), + done(sorters[1].get())}; std::shared_ptr<IWIterator> iters2[] = {correctReverse(), correctReverse()}; ASSERT_ITERATORS_EQUIVALENT(mergeIterators(iters1, DESC), mergeIterators(iters2, DESC)); @@ -461,7 +464,7 @@ public: } // add data to the sorter - virtual void addData(unowned_ptr<IWSorter> sorter) { + virtual void addData(IWSorter* sorter) { sorter->add(2, -2); sorter->add(1, -1); sorter->add(0, 0); @@ -498,11 +501,11 @@ private: return std::shared_ptr<IWSorter>(IWSorter::make(adjustSortOptions(opts), comp)); } - std::shared_ptr<IWIterator> done(unowned_ptr<IWSorter> sorter) { + std::shared_ptr<IWIterator> done(IWSorter* sorter) { return std::shared_ptr<IWIterator>(sorter->done()); } - void assertRangeInfo(unowned_ptr<IWSorter> sorter, const SortOptions& opts) { + void assertRangeInfo(const std::shared_ptr<IWSorter>& sorter, const SortOptions& opts) { auto numRanges = correctNumRanges(); if (numRanges == 0) return; @@ -519,7 +522,7 @@ class Limit : public Basic { SortOptions adjustSortOptions(SortOptions opts) override { return opts.Limit(5); } - void addData(unowned_ptr<IWSorter> sorter) override { + void addData(IWSorter* sorter) override { sorter->add(0, 0); sorter->add(3, -3); sorter->add(4, -4); @@ -546,7 +549,7 @@ class LimitExtreme : public Basic { }; class Dupes : public Basic { - void addData(unowned_ptr<IWSorter> sorter) { + void addData(IWSorter* sorter) override { sorter->add(1, -1); sorter->add(-1, 1); sorter->add(1, -1); @@ -590,7 +593,7 @@ public: return opts.MaxMemoryUsageBytes(MEM_LIMIT).ExtSortAllowed(); } - void addData(unowned_ptr<IWSorter> sorter) override { + void addData(IWSorter* sorter) override { for (int i = 0; i < NUM_ITEMS; i++) sorter->add(_array[i], -_array[i]); } diff --git a/src/mongo/db/storage/devnull/ephemeral_catalog_record_store.cpp b/src/mongo/db/storage/devnull/ephemeral_catalog_record_store.cpp index 80f11d50aa8..a9a1f7f2776 100644 --- a/src/mongo/db/storage/devnull/ephemeral_catalog_record_store.cpp +++ b/src/mongo/db/storage/devnull/ephemeral_catalog_record_store.cpp @@ -40,7 +40,6 @@ #include "mongo/db/storage/recovery_unit.h" #include "mongo/logv2/log.h" #include "mongo/util/str.h" -#include "mongo/util/unowned_ptr.h" namespace mongo { diff --git a/src/mongo/db/storage/sorted_data_interface_test_cursor_end_position.cpp b/src/mongo/db/storage/sorted_data_interface_test_cursor_end_position.cpp index 61751d0a122..4df28d8e7d5 100644 --- a/src/mongo/db/storage/sorted_data_interface_test_cursor_end_position.cpp +++ b/src/mongo/db/storage/sorted_data_interface_test_cursor_end_position.cpp @@ -52,7 +52,7 @@ void testSetEndPosition_Next_Forward(bool unique, bool inclusive) { // Dup key on end point. Illegal for unique indexes. if (!unique) - insertToIndex(opCtx, sorted, {{key3, loc2}}); + insertToIndex(opCtx.get(), sorted.get(), {{key3, loc2}}); auto cursor = sorted->newCursor(opCtx.get()); cursor->setEndPosition(key3, inclusive); @@ -97,7 +97,7 @@ void testSetEndPosition_Next_Reverse(bool unique, bool inclusive) { // Dup key on end point. Illegal for unique indexes. if (!unique) - insertToIndex(opCtx, sorted, {{key3, loc2}}); + insertToIndex(opCtx.get(), sorted.get(), {{key3, loc2}}); auto cursor = sorted->newCursor(opCtx.get(), false); cursor->setEndPosition(key3, inclusive); @@ -158,7 +158,7 @@ void testSetEndPosition_Seek_Forward(bool unique, bool inclusive) { ASSERT_EQ(cursor->seek(makeKeyStringForSeek(sorted.get(), key2, true, inclusive)), maybeKey3); cursor->saveUnpositioned(); - removeFromIndex(opCtx, sorted, {{key3, loc1}}); + removeFromIndex(opCtx.get(), sorted.get(), {{key3, loc1}}); cursor->restore(); ASSERT_EQ(cursor->seek(makeKeyStringForSeek(sorted.get(), key2, true, inclusive)), boost::none); @@ -208,7 +208,7 @@ void testSetEndPosition_Seek_Reverse(bool unique, bool inclusive) { ASSERT_EQ(cursor->seek(makeKeyStringForSeek(sorted.get(), key3, false, true)), maybeKey2); cursor->saveUnpositioned(); - removeFromIndex(opCtx, sorted, {{key2, loc1}}); + removeFromIndex(opCtx.get(), sorted.get(), {{key2, loc1}}); cursor->restore(); ASSERT_EQ(cursor->seek(makeKeyStringForSeek(sorted.get(), key3, false, true)), boost::none); @@ -252,8 +252,8 @@ void testSetEndPosition_Restore_Forward(bool unique) { ASSERT_EQ(cursor->next(), IndexKeyEntry(key2, loc1)); cursor->save(); - removeFromIndex(opCtx, - sorted, + removeFromIndex(opCtx.get(), + sorted.get(), { {key2, loc1}, {key3, loc1}, @@ -293,8 +293,8 @@ void testSetEndPosition_Restore_Reverse(bool unique) { ASSERT_EQ(cursor->next(), IndexKeyEntry(key3, loc1)); cursor->save(); - removeFromIndex(opCtx, - sorted, + removeFromIndex(opCtx.get(), + sorted.get(), { {key2, loc1}, {key3, loc1}, @@ -333,8 +333,8 @@ void testSetEndPosition_RestoreEndCursor_Forward(bool unique) { // A potential source of bugs is not restoring end cursor with saveUnpositioned(). cursor->saveUnpositioned(); - insertToIndex(opCtx, - sorted, + insertToIndex(opCtx.get(), + sorted.get(), { {key2, loc1}, // in range {key3, loc1}, // out of range @@ -370,8 +370,8 @@ void testSetEndPosition_RestoreEndCursor_Reverse(bool unique) { IndexKeyEntry(key4, loc1)); cursor->saveUnpositioned(); - insertToIndex(opCtx, - sorted, + insertToIndex(opCtx.get(), + sorted.get(), { {key2, loc1}, // in range {key3, loc1}, // out of range 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 db45907fbe9..cd418b16917 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 @@ -421,7 +421,7 @@ void testSaveAndRestorePositionSeesNewInserts(bool forward, bool unique) { IndexKeyEntry(seekPoint, loc1)); cursor->save(); - insertToIndex(opCtx, sorted, {{key2, loc1}}); + insertToIndex(opCtx.get(), sorted.get(), {{key2, loc1}}); cursor->restore(); ASSERT_EQ(cursor->next(), IndexKeyEntry(key2, loc1)); @@ -458,12 +458,12 @@ void testSaveAndRestorePositionSeesNewInsertsAfterRemove(bool forward, bool uniq IndexKeyEntry(seekPoint, loc1)); cursor->save(); - removeFromIndex(opCtx, sorted, {{key1, loc1}}); + removeFromIndex(opCtx.get(), sorted.get(), {{key1, loc1}}); cursor->restore(); // The restore may have seeked since it can't return to the saved position. cursor->save(); // Should still save originally saved key as "current position". - insertToIndex(opCtx, sorted, {{key2, loc1}}); + insertToIndex(opCtx.get(), sorted.get(), {{key2, loc1}}); cursor->restore(); ASSERT_EQ(cursor->next(), IndexKeyEntry(key2, loc1)); @@ -500,13 +500,13 @@ void testSaveAndRestorePositionSeesNewInsertsAfterEOF(bool forward, bool unique) // next() would return EOF now. cursor->save(); - removeFromIndex(opCtx, sorted, {{key1, loc1}}); + removeFromIndex(opCtx.get(), sorted.get(), {{key1, loc1}}); cursor->restore(); // The restore may have seeked to EOF. auto insertPoint = forward ? key2 : key0; cursor->save(); // Should still save key1 as "current position". - insertToIndex(opCtx, sorted, {{insertPoint, loc1}}); + insertToIndex(opCtx.get(), sorted.get(), {{insertPoint, loc1}}); cursor->restore(); ASSERT_EQ(cursor->next(), IndexKeyEntry(insertPoint, loc1)); @@ -543,25 +543,25 @@ TEST(SortedDataInterface, SaveAndRestorePositionStandardIndexConsidersRecordId_F IndexKeyEntry(key1, loc1)); cursor->save(); - removeFromIndex(opCtx, sorted, {{key1, loc1}}); - insertToIndex(opCtx, sorted, {{key1, loc2}}); + removeFromIndex(opCtx.get(), sorted.get(), {{key1, loc1}}); + insertToIndex(opCtx.get(), sorted.get(), {{key1, loc2}}); cursor->restore(); // Lands on inserted key. ASSERT_EQ(cursor->next(), IndexKeyEntry(key1, loc2)); cursor->save(); - removeFromIndex(opCtx, sorted, {{key1, loc2}}); - insertToIndex(opCtx, sorted, {{key1, loc1}}); + removeFromIndex(opCtx.get(), sorted.get(), {{key1, loc2}}); + insertToIndex(opCtx.get(), sorted.get(), {{key1, loc1}}); cursor->restore(); // Lands after inserted. ASSERT_EQ(cursor->next(), IndexKeyEntry(key2, loc1)); cursor->save(); - removeFromIndex(opCtx, sorted, {{key2, loc1}}); + removeFromIndex(opCtx.get(), sorted.get(), {{key2, loc1}}); cursor->restore(); cursor->save(); - insertToIndex(opCtx, sorted, {{key2, loc1}}); + insertToIndex(opCtx.get(), sorted.get(), {{key2, loc1}}); cursor->restore(); // Lands at same point as initial save. // Advances from restore point since restore didn't move position. @@ -583,16 +583,16 @@ TEST(SortedDataInterface, SaveAndRestorePositionUniqueIndexWontReturnDupKeys_For IndexKeyEntry(key1, loc1)); cursor->save(); - removeFromIndex(opCtx, sorted, {{key1, loc1}}); - insertToIndex(opCtx, sorted, {{key1, loc2}}); + removeFromIndex(opCtx.get(), sorted.get(), {{key1, loc1}}); + insertToIndex(opCtx.get(), sorted.get(), {{key1, loc2}}); cursor->restore(); // We should skip over (key1, loc2) since we already returned (key1, loc1). ASSERT_EQ(cursor->next(), IndexKeyEntry(key2, loc2)); cursor->save(); - removeFromIndex(opCtx, sorted, {{key2, loc2}}); - insertToIndex(opCtx, sorted, {{key2, loc1}}); + removeFromIndex(opCtx.get(), sorted.get(), {{key2, loc2}}); + insertToIndex(opCtx.get(), sorted.get(), {{key2, loc1}}); cursor->restore(); // We should skip over (key2, loc1) since we already returned (key2, loc2). @@ -600,13 +600,13 @@ TEST(SortedDataInterface, SaveAndRestorePositionUniqueIndexWontReturnDupKeys_For // If the key we just returned is removed, we should simply return the next key after restoring. cursor->save(); - removeFromIndex(opCtx, sorted, {{key3, loc2}}); + removeFromIndex(opCtx.get(), sorted.get(), {{key3, loc2}}); cursor->restore(); ASSERT_EQ(cursor->next(), IndexKeyEntry(key4, loc2)); // If a key is inserted just ahead of our position, we should return it after restoring. cursor->save(); - insertToIndex(opCtx, sorted, {{key5, loc2}}); + insertToIndex(opCtx.get(), sorted.get(), {{key5, loc2}}); cursor->restore(); ASSERT_EQ(cursor->next(), IndexKeyEntry(key5, loc2)); } @@ -629,25 +629,25 @@ TEST(SortedDataInterface, SaveAndRestorePositionStandardIndexConsidersRecordId_R IndexKeyEntry(key2, loc2)); cursor->save(); - removeFromIndex(opCtx, sorted, {{key2, loc2}}); - insertToIndex(opCtx, sorted, {{key2, loc1}}); + removeFromIndex(opCtx.get(), sorted.get(), {{key2, loc2}}); + insertToIndex(opCtx.get(), sorted.get(), {{key2, loc1}}); cursor->restore(); ASSERT_EQ(cursor->next(), IndexKeyEntry(key2, loc1)); cursor->save(); - removeFromIndex(opCtx, sorted, {{key2, loc1}}); - insertToIndex(opCtx, sorted, {{key2, loc2}}); + removeFromIndex(opCtx.get(), sorted.get(), {{key2, loc1}}); + insertToIndex(opCtx.get(), sorted.get(), {{key2, loc2}}); cursor->restore(); ASSERT_EQ(cursor->next(), IndexKeyEntry(key1, loc1)); cursor->save(); - removeFromIndex(opCtx, sorted, {{key1, loc1}}); + removeFromIndex(opCtx.get(), sorted.get(), {{key1, loc1}}); cursor->restore(); cursor->save(); - insertToIndex(opCtx, sorted, {{key1, loc1}}); + insertToIndex(opCtx.get(), sorted.get(), {{key1, loc1}}); cursor->restore(); // Lands at same point as initial save. // Advances from restore point since restore didn't move position. @@ -669,16 +669,16 @@ TEST(SortedDataInterface, SaveAndRestorePositionUniqueIndexWontReturnDupKeys_Rev IndexKeyEntry(key4, loc2)); cursor->save(); - removeFromIndex(opCtx, sorted, {{key4, loc2}}); - insertToIndex(opCtx, sorted, {{key4, loc1}}); + removeFromIndex(opCtx.get(), sorted.get(), {{key4, loc2}}); + insertToIndex(opCtx.get(), sorted.get(), {{key4, loc1}}); cursor->restore(); // We should skip over (key4, loc1) since we already returned (key4, loc2). ASSERT_EQ(cursor->next(), IndexKeyEntry(key3, loc1)); cursor->save(); - removeFromIndex(opCtx, sorted, {{key3, loc1}}); - insertToIndex(opCtx, sorted, {{key3, loc2}}); + removeFromIndex(opCtx.get(), sorted.get(), {{key3, loc1}}); + insertToIndex(opCtx.get(), sorted.get(), {{key3, loc2}}); cursor->restore(); // We should skip over (key3, loc2) since we already returned (key3, loc1). @@ -686,13 +686,13 @@ TEST(SortedDataInterface, SaveAndRestorePositionUniqueIndexWontReturnDupKeys_Rev // If the key we just returned is removed, we should simply return the next key after restoring. cursor->save(); - removeFromIndex(opCtx, sorted, {{key2, loc1}}); + removeFromIndex(opCtx.get(), sorted.get(), {{key2, loc1}}); cursor->restore(); ASSERT_EQ(cursor->next(), IndexKeyEntry(key1, loc1)); // If a key is inserted just ahead of our position, we should return it after restoring. cursor->save(); - insertToIndex(opCtx, sorted, {{key0, loc1}}); + insertToIndex(opCtx.get(), sorted.get(), {{key0, loc1}}); cursor->restore(); ASSERT_EQ(cursor->next(), IndexKeyEntry(key0, loc1)); } @@ -715,7 +715,7 @@ TEST(SortedDataInterface, SaveUnpositionedAndRestore) { IndexKeyEntry(key2, loc1)); cursor->saveUnpositioned(); - removeFromIndex(opCtx, sorted, {{key2, loc1}}); + removeFromIndex(opCtx.get(), sorted.get(), {{key2, loc1}}); cursor->restore(); ASSERT_EQ(cursor->seek(makeKeyStringForSeek(sorted.get(), key1, true, true)), 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 a99857e646c..5a9f5a52d9a 100644 --- a/src/mongo/db/storage/sorted_data_interface_test_harness.cpp +++ b/src/mongo/db/storage/sorted_data_interface_test_harness.cpp @@ -42,26 +42,26 @@ auto mongo::SortedDataInterfaceHarnessHelper::newSortedDataInterface( toInsert.begin(), toInsert.end(), IndexEntryComparison(Ordering::make(BSONObj())))); auto index = newSortedDataInterface(unique, partial); - insertToIndex(this, index, toInsert); + insertToIndex(this, index.get(), toInsert); return index; } -void mongo::insertToIndex(unowned_ptr<OperationContext> opCtx, - unowned_ptr<SortedDataInterface> index, +void mongo::insertToIndex(OperationContext* opCtx, + SortedDataInterface* index, std::initializer_list<IndexKeyEntry> toInsert) { WriteUnitOfWork wuow(opCtx); for (auto&& entry : toInsert) { - ASSERT_OK(index->insert(opCtx, makeKeyString(index.get(), entry.key, entry.loc), true)); + ASSERT_OK(index->insert(opCtx, makeKeyString(index, entry.key, entry.loc), true)); } wuow.commit(); } -void mongo::removeFromIndex(unowned_ptr<OperationContext> opCtx, - unowned_ptr<SortedDataInterface> index, +void mongo::removeFromIndex(OperationContext* opCtx, + SortedDataInterface* index, std::initializer_list<IndexKeyEntry> toRemove) { WriteUnitOfWork wuow(opCtx); for (auto&& entry : toRemove) { - index->unindex(opCtx, makeKeyString(index.get(), entry.key, entry.loc), true); + index->unindex(opCtx, makeKeyString(index, entry.key, entry.loc), true); } wuow.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 7e5b7a06790..1e62e6df981 100644 --- a/src/mongo/db/storage/sorted_data_interface_test_harness.h +++ b/src/mongo/db/storage/sorted_data_interface_test_harness.h @@ -38,7 +38,6 @@ #include "mongo/db/service_context.h" #include "mongo/db/storage/sorted_data_interface.h" #include "mongo/db/storage/test_harness_helper.h" -#include "mongo/util/unowned_ptr.h" namespace mongo { @@ -128,15 +127,15 @@ KeyString::Value makeKeyStringForSeek(SortedDataInterface* sorted, * * Should be used for declaring and changing conditions, not for testing inserts. */ -void insertToIndex(unowned_ptr<OperationContext> opCtx, - unowned_ptr<SortedDataInterface> index, +void insertToIndex(OperationContext* opCtx, + SortedDataInterface* index, std::initializer_list<IndexKeyEntry> toInsert); -inline void insertToIndex(unowned_ptr<HarnessHelper> harness, - unowned_ptr<SortedDataInterface> index, +inline void insertToIndex(HarnessHelper* harness, + SortedDataInterface* index, std::initializer_list<IndexKeyEntry> toInsert) { auto client = harness->serviceContext()->makeClient("insertToIndex"); - insertToIndex(harness->newOperationContext(client.get()), index, toInsert); + insertToIndex(harness->newOperationContext(client.get()).get(), index, toInsert); } /** @@ -145,15 +144,15 @@ inline void insertToIndex(unowned_ptr<HarnessHelper> harness, * * Should be used for declaring and changing conditions, not for testing removes. */ -void removeFromIndex(unowned_ptr<OperationContext> opCtx, - unowned_ptr<SortedDataInterface> index, +void removeFromIndex(OperationContext* opCtx, + SortedDataInterface* index, std::initializer_list<IndexKeyEntry> toRemove); -inline void removeFromIndex(unowned_ptr<HarnessHelper> harness, - unowned_ptr<SortedDataInterface> index, +inline void removeFromIndex(HarnessHelper* harness, + SortedDataInterface* index, std::initializer_list<IndexKeyEntry> toRemove) { auto client = harness->serviceContext()->makeClient("removeFromIndex"); - removeFromIndex(harness->newOperationContext(client.get()), index, toRemove); + removeFromIndex(harness->newOperationContext(client.get()).get(), index, toRemove); } } // namespace mongo diff --git a/src/mongo/db/storage/test_harness_helper.h b/src/mongo/db/storage/test_harness_helper.h index 3627f528cbe..6ccd812df9c 100644 --- a/src/mongo/db/storage/test_harness_helper.h +++ b/src/mongo/db/storage/test_harness_helper.h @@ -40,7 +40,6 @@ #include "mongo/db/service_context.h" #include "mongo/db/service_context_test_fixture.h" #include "mongo/db/storage/sorted_data_interface.h" -#include "mongo/util/unowned_ptr.h" namespace mongo { |