diff options
author | ADAM David Alan Martin <adam.martin@10gen.com> | 2019-01-24 18:53:00 -0500 |
---|---|---|
committer | ADAM David Alan Martin <adam.martin@10gen.com> | 2019-01-25 11:55:34 -0500 |
commit | c741da0edb4952f58441a5e61b29bc93a0ee596c (patch) | |
tree | efc2988fff5e4b267f11c121bc514bc0f700f31a /src | |
parent | 677a65ba43fecf7cf20b7a2c34b5ec2bed413edd (diff) | |
download | mongo-c741da0edb4952f58441a5e61b29bc93a0ee596c.tar.gz |
SERVER-38891 Fix some `collection_cloner_test` races.
The mocks in these tests hold pointers to items on the stack. The
mocks are held in background threads, such as executors. If the
executor accesses one of those mocks after the stack frame of its
creator leaves, the pointer to the stack frame is now invalid.
Diffstat (limited to 'src')
-rw-r--r-- | src/mongo/base/status_with.h | 9 | ||||
-rw-r--r-- | src/mongo/db/repl/collection_cloner_test.cpp | 164 | ||||
-rw-r--r-- | src/mongo/db/repl/database_cloner_test.cpp | 45 | ||||
-rw-r--r-- | src/mongo/db/repl/databases_cloner_test.cpp | 19 | ||||
-rw-r--r-- | src/mongo/db/repl/initial_syncer_test.cpp | 18 | ||||
-rw-r--r-- | src/mongo/db/repl/storage_interface_mock.h | 98 | ||||
-rw-r--r-- | src/mongo/db/s/config/sharding_catalog_manager.h | 1 |
7 files changed, 184 insertions, 170 deletions
diff --git a/src/mongo/base/status_with.h b/src/mongo/base/status_with.h index d14f75f8c59..a0e6a257754 100644 --- a/src/mongo/base/status_with.h +++ b/src/mongo/base/status_with.h @@ -137,6 +137,15 @@ public: typename std::enable_if_t<!std::is_same<Alien, T>::value, TagType> = makeTag()) : StatusWith(static_cast<T>(std::forward<Alien>(alien))) {} + template <typename Alien> + StatusWith(StatusWith<Alien> alien, + typename std::enable_if_t<std::is_convertible<Alien, T>::value, TagType> = makeTag(), + typename std::enable_if_t<!std::is_same<Alien, T>::value, TagType> = makeTag()) + : _status(std::move(alien.getStatus())) { + if (alien.isOK()) + this->_t = std::move(alien.getValue()); + } + const T& getValue() const { dassert(isOK()); return *_t; diff --git a/src/mongo/db/repl/collection_cloner_test.cpp b/src/mongo/db/repl/collection_cloner_test.cpp index 3908a8d8501..466bd80a4ce 100644 --- a/src/mongo/db/repl/collection_cloner_test.cpp +++ b/src/mongo/db/repl/collection_cloner_test.cpp @@ -1,4 +1,3 @@ - /** * Copyright (C) 2018-present MongoDB, Inc. * @@ -235,8 +234,8 @@ protected: CollectionOptions options; std::unique_ptr<CollectionCloner> collectionCloner; - CollectionMockStats collectionStats; // Used by the _loader. - CollectionBulkLoaderMock* _loader; // Owned by CollectionCloner. + std::shared_ptr<CollectionMockStats> collectionStats; // Used by the _loader. + CollectionBulkLoaderMock* _loader; // Owned by CollectionCloner. bool _clientCreated = false; FailableMockDBClientConnection* _client; // owned by the CollectionCloner once created. std::unique_ptr<MockRemoteDBServer> _server; @@ -246,28 +245,31 @@ void CollectionClonerTest::setUp() { BaseClonerTest::setUp(); options = getCollectionOptions(); collectionCloner.reset(nullptr); - collectionCloner = stdx::make_unique<CollectionCloner>(&getExecutor(), - dbWorkThreadPool.get(), - target, - getStartupNss(), - options, - setStatusCallback(), - storageInterface.get(), - defaultBatchSize); - collectionStats = CollectionMockStats(); + collectionCloner = std::make_unique<CollectionCloner>(&getExecutor(), + dbWorkThreadPool.get(), + target, + getStartupNss(), + options, + setStatusCallback(), + storageInterface.get(), + defaultBatchSize); + collectionStats = std::make_shared<CollectionMockStats>(); storageInterface->createCollectionForBulkFn = [this](const NamespaceString& nss, const CollectionOptions& options, const BSONObj idIndexSpec, - const std::vector<BSONObj>& nonIdIndexSpecs) { - (_loader = new CollectionBulkLoaderMock(&collectionStats)) - ->init(nonIdIndexSpecs) - .transitional_ignore(); + const std::vector<BSONObj>& nonIdIndexSpecs) + -> StatusWith<std::unique_ptr<CollectionBulkLoaderMock>> { + auto localLoader = std::make_unique<CollectionBulkLoaderMock>(collectionStats); + Status result = localLoader->init(nonIdIndexSpecs); + if (!result.isOK()) + return result; + + _loader = localLoader.get(); - return StatusWith<std::unique_ptr<CollectionBulkLoader>>( - std::unique_ptr<CollectionBulkLoader>(_loader)); + return std::move(localLoader); }; - _server = stdx::make_unique<MockRemoteDBServer>(target.toString()); + _server = std::make_unique<MockRemoteDBServer>(target.toString()); _server->assignCollectionUuid(nss.ns(), *options.uuid); _client = new FailableMockDBClientConnection(_server.get(), getNet()); collectionCloner->setCreateClientFn_forTest([this]() { @@ -564,12 +566,14 @@ TEST_F(CollectionClonerNoAutoIndexTest, DoNotCreateIDIndexIfAutoIndexIdUsed) { const BSONObj idIndexSpec, const std::vector<BSONObj>& theIndexSpecs) -> StatusWith<std::unique_ptr<CollectionBulkLoader>> { - CollectionBulkLoaderMock* loader = new CollectionBulkLoaderMock(&collectionStats); + auto loader = std::make_unique<CollectionBulkLoaderMock>(collectionStats); collNss = theNss; collOptions = theOptions; collIndexSpecs = theIndexSpecs; - loader->init(theIndexSpecs).transitional_ignore(); - return std::unique_ptr<CollectionBulkLoader>(loader); + const auto status = loader->init(theIndexSpecs); + if (!status.isOK()) + return status; + return std::move(loader); }; const BSONObj doc = BSON("_id" << 1); @@ -587,12 +591,12 @@ TEST_F(CollectionClonerNoAutoIndexTest, DoNotCreateIDIndexIfAutoIndexIdUsed) { _client->waitForPausedQuery(); ASSERT_TRUE(collectionCloner->isActive()); - ASSERT_TRUE(collectionStats.initCalled); + ASSERT_TRUE(collectionStats->initCalled); pauser.resume(); collectionCloner->join(); - ASSERT_EQUALS(1, collectionStats.insertCount); - ASSERT_TRUE(collectionStats.commitCalled); + ASSERT_EQUALS(1, collectionStats->insertCount); + ASSERT_TRUE(collectionStats->commitCalled); ASSERT_OK(getStatus()); ASSERT_FALSE(collectionCloner->isActive()); @@ -789,21 +793,21 @@ TEST_F(CollectionClonerTest, BeginCollection) { MockClientPauser pauser(_client); ASSERT_OK(collectionCloner->startup()); - CollectionMockStats stats; - CollectionBulkLoaderMock* loader = new CollectionBulkLoaderMock(&stats); + auto stats = std::make_shared<CollectionMockStats>(); + auto loader = std::make_unique<CollectionBulkLoaderMock>(stats); NamespaceString collNss; CollectionOptions collOptions; std::vector<BSONObj> collIndexSpecs; - storageInterface->createCollectionForBulkFn = [&](const NamespaceString& theNss, - const CollectionOptions& theOptions, - const BSONObj idIndexSpec, - const std::vector<BSONObj>& theIndexSpecs) - -> StatusWith<std::unique_ptr<CollectionBulkLoader>> { - collNss = theNss; - collOptions = theOptions; - collIndexSpecs = theIndexSpecs; - return std::unique_ptr<CollectionBulkLoader>(loader); - }; + storageInterface->createCollectionForBulkFn = + [&](const NamespaceString& theNss, + const CollectionOptions& theOptions, + const BSONObj idIndexSpec, + const std::vector<BSONObj>& theIndexSpecs) -> std::unique_ptr<CollectionBulkLoader> { + collNss = theNss; + collOptions = theOptions; + collIndexSpecs = theIndexSpecs; + return std::move(loader); + }; // Split listIndexes response into 2 batches: first batch contains idIndexSpec and // second batch contains specs @@ -848,18 +852,18 @@ TEST_F(CollectionClonerTest, FindFetcherScheduleFailed) { // Shut down executor while in beginCollection callback. // This will cause the fetcher to fail to schedule the find command. - CollectionMockStats stats; - CollectionBulkLoaderMock* loader = new CollectionBulkLoaderMock(&stats); + auto stats = std::make_shared<CollectionMockStats>(); + auto loader = std::make_unique<CollectionBulkLoaderMock>(stats); bool collectionCreated = false; - storageInterface->createCollectionForBulkFn = [&](const NamespaceString& theNss, - const CollectionOptions& theOptions, - const BSONObj idIndexSpec, - const std::vector<BSONObj>& theIndexSpecs) - -> StatusWith<std::unique_ptr<CollectionBulkLoader>> { - collectionCreated = true; - getExecutor().shutdown(); - return std::unique_ptr<CollectionBulkLoader>(loader); - }; + storageInterface->createCollectionForBulkFn = + [&](const NamespaceString& theNss, + const CollectionOptions& theOptions, + const BSONObj idIndexSpec, + const std::vector<BSONObj>& theIndexSpecs) -> std::unique_ptr<CollectionBulkLoader> { + collectionCreated = true; + getExecutor().shutdown(); + return std::move(loader); + }; { executor::NetworkInterfaceMock::InNetworkGuard guard(getNet()); @@ -880,17 +884,17 @@ TEST_F(CollectionClonerTest, QueryAfterCreateCollection) { MockClientPauser pauser(_client); ASSERT_OK(collectionCloner->startup()); - CollectionMockStats stats; - CollectionBulkLoaderMock* loader = new CollectionBulkLoaderMock(&stats); + auto stats = std::make_shared<CollectionMockStats>(); + auto loader = std::make_unique<CollectionBulkLoaderMock>(stats); bool collectionCreated = false; - storageInterface->createCollectionForBulkFn = [&](const NamespaceString& theNss, - const CollectionOptions& theOptions, - const BSONObj idIndexSpec, - const std::vector<BSONObj>& theIndexSpecs) - -> StatusWith<std::unique_ptr<CollectionBulkLoader>> { - collectionCreated = true; - return std::unique_ptr<CollectionBulkLoader>(loader); - }; + storageInterface->createCollectionForBulkFn = + [&](const NamespaceString& theNss, + const CollectionOptions& theOptions, + const BSONObj idIndexSpec, + const std::vector<BSONObj>& theIndexSpecs) -> std::unique_ptr<CollectionBulkLoader> { + collectionCreated = true; + return std::move(loader); + }; { executor::NetworkInterfaceMock::InNetworkGuard guard(getNet()); @@ -1005,7 +1009,7 @@ TEST_F(CollectionClonerTest, InsertDocumentsFailed) { _client->waitForPausedQuery(); ASSERT_TRUE(collectionCloner->isActive()); - ASSERT_TRUE(collectionStats.initCalled); + ASSERT_TRUE(collectionStats->initCalled); ASSERT(_loader != nullptr); _loader->insertDocsFn = [](const std::vector<BSONObj>::const_iterator begin, @@ -1017,7 +1021,7 @@ TEST_F(CollectionClonerTest, InsertDocumentsFailed) { collectionCloner->join(); ASSERT_FALSE(collectionCloner->isActive()); - ASSERT_EQUALS(0, collectionStats.insertCount); + ASSERT_EQUALS(0, collectionStats->insertCount); ASSERT_EQUALS(ErrorCodes::OperationFailed, getStatus().code()); } @@ -1038,10 +1042,10 @@ TEST_F(CollectionClonerTest, InsertDocumentsSingleBatch) { collectionCloner->join(); // TODO: record the documents during insert and compare them // -- maybe better done using a real storage engine, like ephemeral for test. - ASSERT_EQUALS(2, collectionStats.insertCount); + ASSERT_EQUALS(2, collectionStats->insertCount); auto stats = collectionCloner->getStats(); ASSERT_EQUALS(1u, stats.receivedBatches); - ASSERT_TRUE(collectionStats.commitCalled); + ASSERT_TRUE(collectionStats->commitCalled); ASSERT_OK(getStatus()); ASSERT_FALSE(collectionCloner->isActive()); @@ -1065,8 +1069,8 @@ TEST_F(CollectionClonerTest, InsertDocumentsMultipleBatches) { collectionCloner->join(); // TODO: record the documents during insert and compare them // -- maybe better done using a real storage engine, like ephemeral for test. - ASSERT_EQUALS(3, collectionStats.insertCount); - ASSERT_TRUE(collectionStats.commitCalled); + ASSERT_EQUALS(3, collectionStats->insertCount); + ASSERT_TRUE(collectionStats->commitCalled); auto stats = collectionCloner->getStats(); ASSERT_EQUALS(2u, stats.receivedBatches); @@ -1107,7 +1111,7 @@ TEST_F(CollectionClonerTest, CollectionClonerCannotBeRestartedAfterPreviousFailu // Second cloning attempt - run to completion. unittest::log() << "Starting second collection cloning attempt - startup() should fail"; - collectionStats = CollectionMockStats(); + *collectionStats = CollectionMockStats(); setStatus(getDetectableErrorStatus()); ASSERT_EQUALS(ErrorCodes::ShutdownInProgress, collectionCloner->startup()); @@ -1185,7 +1189,7 @@ TEST_F(CollectionClonerTest, _client->waitForPausedQuery(); ASSERT_TRUE(collectionCloner->isActive()); - ASSERT_TRUE(collectionStats.initCalled); + ASSERT_TRUE(collectionStats->initCalled); // At this point, the CollectionCloner is waiting for the query to complete. // We want to return the first batch of documents for the collection from the network so that @@ -1264,7 +1268,7 @@ protected: ASSERT_TRUE(collectionCloner->isActive()); _client->waitForPausedQuery(); - ASSERT_TRUE(collectionStats.initCalled); + ASSERT_TRUE(collectionStats->initCalled); pauser.resumeAndWaitForResumedQuery(); } @@ -1337,23 +1341,23 @@ TEST_F(CollectionClonerRenamedBeforeStartTest, FirstRemoteCommandWithRenamedColl } TEST_F(CollectionClonerRenamedBeforeStartTest, BeginCollectionWithUUID) { - CollectionMockStats stats; - CollectionBulkLoaderMock* loader = new CollectionBulkLoaderMock(&stats); + auto stats = std::make_shared<CollectionMockStats>(); + auto loader = std::make_unique<CollectionBulkLoaderMock>(stats); NamespaceString collNss; CollectionOptions collOptions; BSONObj collIdIndexSpec; std::vector<BSONObj> collSecondaryIndexSpecs; - storageInterface->createCollectionForBulkFn = [&](const NamespaceString& theNss, - const CollectionOptions& theOptions, - const BSONObj idIndexSpec, - const std::vector<BSONObj>& nonIdIndexSpecs) - -> StatusWith<std::unique_ptr<CollectionBulkLoader>> { - collNss = theNss; - collOptions = theOptions; - collIdIndexSpec = idIndexSpec; - collSecondaryIndexSpecs = nonIdIndexSpecs; - return std::unique_ptr<CollectionBulkLoader>(loader); - }; + storageInterface->createCollectionForBulkFn = + [&](const NamespaceString& theNss, + const CollectionOptions& theOptions, + const BSONObj idIndexSpec, + const std::vector<BSONObj>& nonIdIndexSpecs) -> std::unique_ptr<CollectionBulkLoader> { + collNss = theNss; + collOptions = theOptions; + collIdIndexSpec = idIndexSpec; + collSecondaryIndexSpecs = nonIdIndexSpecs; + return std::move(loader); + }; // Pause the client so the cloner stops in the fetcher. MockClientPauser pauser(_client); diff --git a/src/mongo/db/repl/database_cloner_test.cpp b/src/mongo/db/repl/database_cloner_test.cpp index 7e594adbc59..af688a3b26f 100644 --- a/src/mongo/db/repl/database_cloner_test.cpp +++ b/src/mongo/db/repl/database_cloner_test.cpp @@ -1,4 +1,3 @@ - /** * Copyright (C) 2018-present MongoDB, Inc. * @@ -55,7 +54,7 @@ using namespace unittest; const std::string dbname("db"); struct CollectionCloneInfo { - CollectionMockStats stats; + std::shared_ptr<CollectionMockStats> stats = std::make_shared<CollectionMockStats>(); CollectionBulkLoaderMock* loader = nullptr; Status status{ErrorCodes::NotYetInitialized, ""}; }; @@ -125,14 +124,17 @@ void DatabaseClonerTest::setUp() { [this](const NamespaceString& nss, const CollectionOptions& options, const BSONObj& idIndexSpec, - const std::vector<BSONObj>& secondaryIndexSpecs) { + const std::vector<BSONObj>& secondaryIndexSpecs) + -> StatusWith<std::unique_ptr<CollectionBulkLoaderMock>> { const auto collInfo = &_collections[nss]; - (collInfo->loader = new CollectionBulkLoaderMock(&collInfo->stats)) - ->init(secondaryIndexSpecs) - .transitional_ignore(); - return StatusWith<std::unique_ptr<CollectionBulkLoader>>( - std::unique_ptr<CollectionBulkLoader>(collInfo->loader)); + auto localLoader = std::make_unique<CollectionBulkLoaderMock>(collInfo->stats); + auto status = localLoader->init(secondaryIndexSpecs); + if (!status.isOK()) + return status; + collInfo->loader = localLoader.get(); + + return std::move(localLoader); }; } @@ -653,16 +655,15 @@ TEST_F(DatabaseClonerTest, DatabaseClonerResendsListCollectionsRequestOnRetriabl } TEST_F(DatabaseClonerTest, ListCollectionsReturnsEmptyCollectionName) { - _databaseCloner = - stdx::make_unique<DatabaseCloner>(&getExecutor(), - dbWorkThreadPool.get(), - target, - dbname, - BSONObj(), - DatabaseCloner::ListCollectionsPredicateFn(), - storageInterface.get(), - makeCollectionWorkClosure(), - makeSetStatusClosure()); + _databaseCloner = std::make_unique<DatabaseCloner>(&getExecutor(), + dbWorkThreadPool.get(), + target, + dbname, + BSONObj(), + DatabaseCloner::ListCollectionsPredicateFn(), + storageInterface.get(), + makeCollectionWorkClosure(), + makeSetStatusClosure()); ASSERT_EQUALS(DatabaseCloner::State::kPreStart, _databaseCloner->getState_forTest()); ASSERT_OK(_databaseCloner->startup()); @@ -834,14 +835,14 @@ TEST_F(DatabaseClonerTest, FirstCollectionListIndexesFailed) { // We have attempted, and failed, to clone the first collection. auto collInfo = _collections[NamespaceString{"db.a"}]; ASSERT_EQUALS(ErrorCodes::CursorNotFound, collInfo.status.code()); - auto stats = collInfo.stats; + auto stats = *collInfo.stats; stats.insertCount = 0; stats.commitCalled = false; // We have not attempted to clone the second collection. collInfo = _collections[NamespaceString{"db.b"}]; ASSERT_EQUALS(ErrorCodes::NotYetInitialized, collInfo.status.code()); - stats = collInfo.stats; + stats = *collInfo.stats; stats.insertCount = 0; stats.commitCalled = true; } @@ -892,13 +893,13 @@ TEST_F(DatabaseClonerTest, CreateCollections) { auto collInfo = _collections[NamespaceString{"db.a"}]; ASSERT_OK(collInfo.status); - auto stats = collInfo.stats; + auto stats = *collInfo.stats; stats.insertCount = 0; stats.commitCalled = true; collInfo = _collections[NamespaceString{"db.b"}]; ASSERT_OK(collInfo.status); - stats = collInfo.stats; + stats = *collInfo.stats; stats.insertCount = 0; stats.commitCalled = true; } diff --git a/src/mongo/db/repl/databases_cloner_test.cpp b/src/mongo/db/repl/databases_cloner_test.cpp index 4340c0a8d51..7463f93ab7c 100644 --- a/src/mongo/db/repl/databases_cloner_test.cpp +++ b/src/mongo/db/repl/databases_cloner_test.cpp @@ -1,4 +1,3 @@ - /** * Copyright (C) 2018-present MongoDB, Inc. * @@ -66,7 +65,7 @@ using namespace unittest; using Responses = std::vector<std::pair<std::string, BSONObj>>; struct CollectionCloneInfo { - CollectionMockStats stats; + std::shared_ptr<CollectionMockStats> stats = std::make_shared<CollectionMockStats>(); CollectionBulkLoaderMock* loader = nullptr; Status status{ErrorCodes::NotYetInitialized, ""}; }; @@ -176,18 +175,20 @@ protected: [this](const NamespaceString& nss, const CollectionOptions& options, const BSONObj idIndexSpec, - const std::vector<BSONObj>& secondaryIndexSpecs) { + const std::vector<BSONObj>& secondaryIndexSpecs) + -> StatusWith<std::unique_ptr<CollectionBulkLoaderMock>> { // Get collection info from map. const auto collInfo = &_collections[nss]; - if (collInfo->stats.initCalled) { + if (collInfo->stats->initCalled) { log() << "reusing collection during test which may cause problems, ns:" << nss; } - (collInfo->loader = new CollectionBulkLoaderMock(&collInfo->stats)) - ->init(secondaryIndexSpecs) - .transitional_ignore(); + auto localLoader = std::make_unique<CollectionBulkLoaderMock>(collInfo->stats); + auto status = localLoader->init(secondaryIndexSpecs); + if (!status.isOK()) + return status; + collInfo->loader = localLoader.get(); - return StatusWith<std::unique_ptr<CollectionBulkLoader>>( - std::unique_ptr<CollectionBulkLoader>(collInfo->loader)); + return std::move(localLoader); }; _dbWorkThreadPool.startup(); diff --git a/src/mongo/db/repl/initial_syncer_test.cpp b/src/mongo/db/repl/initial_syncer_test.cpp index cfd9b4bed4c..408557c823d 100644 --- a/src/mongo/db/repl/initial_syncer_test.cpp +++ b/src/mongo/db/repl/initial_syncer_test.cpp @@ -111,7 +111,7 @@ using NetworkGuard = executor::NetworkInterfaceMock::InNetworkGuard; using UniqueLock = stdx::unique_lock<stdx::mutex>; struct CollectionCloneInfo { - CollectionMockStats stats; + std::shared_ptr<CollectionMockStats> stats = std::make_shared<CollectionMockStats>(); CollectionBulkLoaderMock* loader = nullptr; Status status{ErrorCodes::NotYetInitialized, ""}; }; @@ -297,18 +297,20 @@ protected: [this](const NamespaceString& nss, const CollectionOptions& options, const BSONObj idIndexSpec, - const std::vector<BSONObj>& secondaryIndexSpecs) { + const std::vector<BSONObj>& secondaryIndexSpecs) + -> StatusWith<std::unique_ptr<CollectionBulkLoaderMock>> { // Get collection info from map. const auto collInfo = &_collections[nss]; - if (collInfo->stats.initCalled) { + if (collInfo->stats->initCalled) { log() << "reusing collection during test which may cause problems, ns:" << nss; } - (collInfo->loader = new CollectionBulkLoaderMock(&collInfo->stats)) - ->init(secondaryIndexSpecs) - .transitional_ignore(); + auto localLoader = std::make_unique<CollectionBulkLoaderMock>(collInfo->stats); + auto status = localLoader->init(secondaryIndexSpecs); + if (!status.isOK()) + return status; + collInfo->loader = localLoader.get(); - return StatusWith<std::unique_ptr<CollectionBulkLoader>>( - std::unique_ptr<CollectionBulkLoader>(collInfo->loader)); + return std::move(localLoader); }; _storageInterface->upgradeNonReplicatedUniqueIndexesFn = [this](OperationContext* opCtx) { LockGuard lock(_storageInterfaceWorkDoneMutex); diff --git a/src/mongo/db/repl/storage_interface_mock.h b/src/mongo/db/repl/storage_interface_mock.h index 5189a4303ff..0520cc5aa74 100644 --- a/src/mongo/db/repl/storage_interface_mock.h +++ b/src/mongo/db/repl/storage_interface_mock.h @@ -1,4 +1,3 @@ - /** * Copyright (C) 2018-present MongoDB, Inc. * @@ -31,6 +30,12 @@ #pragma once +#include <cstdlib> +#include <functional> +#include <memory> +#include <string> +#include <vector> + #include "mongo/base/disallow_copying.h" #include "mongo/base/status.h" #include "mongo/base/status_with.h" @@ -54,13 +59,14 @@ class CollectionBulkLoaderMock : public CollectionBulkLoader { MONGO_DISALLOW_COPYING(CollectionBulkLoaderMock); public: - CollectionBulkLoaderMock(CollectionMockStats* collStats) : stats(collStats){}; + explicit CollectionBulkLoaderMock(std::shared_ptr<CollectionMockStats> collStats) + : stats(std::move(collStats)){}; virtual ~CollectionBulkLoaderMock() = default; - virtual Status init(const std::vector<BSONObj>& secondaryIndexSpecs) override; + Status init(const std::vector<BSONObj>& secondaryIndexSpecs) override; - virtual Status insertDocuments(const std::vector<BSONObj>::const_iterator begin, - const std::vector<BSONObj>::const_iterator end) override; - virtual Status commit() override; + Status insertDocuments(const std::vector<BSONObj>::const_iterator begin, + const std::vector<BSONObj>::const_iterator end) override; + Status commit() override; std::string toString() const override { return toBSON().toString(); @@ -69,15 +75,15 @@ public: return BSONObj(); }; - CollectionMockStats* stats; + std::shared_ptr<CollectionMockStats> stats; // Override functions. - stdx::function<Status(const std::vector<BSONObj>::const_iterator begin, - const std::vector<BSONObj>::const_iterator end)> + std::function<Status(std::vector<BSONObj>::const_iterator, + std::vector<BSONObj>::const_iterator)> insertDocsFn = [](const std::vector<BSONObj>::const_iterator, const std::vector<BSONObj>::const_iterator) { return Status::OK(); }; - stdx::function<Status()> abortFn = []() { return Status::OK(); }; - stdx::function<Status()> commitFn = []() { return Status::OK(); }; + std::function<Status()> abortFn = []() { return Status::OK(); }; + std::function<Status()> commitFn = []() { return Status::OK(); }; }; class StorageInterfaceMock : public StorageInterface { @@ -86,48 +92,40 @@ class StorageInterfaceMock : public StorageInterface { public: // Used for testing. - using CreateCollectionForBulkFn = - stdx::function<StatusWith<std::unique_ptr<CollectionBulkLoader>>( - const NamespaceString& nss, - const CollectionOptions& options, - const BSONObj idIndexSpec, - const std::vector<BSONObj>& secondaryIndexSpecs)>; - using InsertDocumentFn = stdx::function<Status(OperationContext* opCtx, - const NamespaceStringOrUUID& nsOrUUID, - const TimestampedBSONObj& doc, - long long term)>; - using InsertDocumentsFn = stdx::function<Status(OperationContext* opCtx, - const NamespaceStringOrUUID& nsOrUUID, - const std::vector<InsertStatement>& docs)>; - using DropUserDatabasesFn = stdx::function<Status(OperationContext* opCtx)>; - using CreateOplogFn = - stdx::function<Status(OperationContext* opCtx, const NamespaceString& nss)>; - using CreateCollectionFn = stdx::function<Status( - OperationContext* opCtx, const NamespaceString& nss, const CollectionOptions& options)>; + using CreateCollectionForBulkFn = std::function<StatusWith< + std::unique_ptr<CollectionBulkLoader>>( + const NamespaceString&, const CollectionOptions&, BSONObj, const std::vector<BSONObj>&)>; + using InsertDocumentFn = std::function<Status( + OperationContext*, const NamespaceStringOrUUID&, const TimestampedBSONObj&, long long)>; + using InsertDocumentsFn = std::function<Status( + OperationContext*, const NamespaceStringOrUUID&, const std::vector<InsertStatement>&)>; + using DropUserDatabasesFn = std::function<Status(OperationContext*)>; + using CreateOplogFn = std::function<Status(OperationContext*, const NamespaceString&)>; + using CreateCollectionFn = + std::function<Status(OperationContext*, const NamespaceString&, const CollectionOptions&)>; using TruncateCollectionFn = - stdx::function<Status(OperationContext* opCtx, const NamespaceString& nss)>; - using DropCollectionFn = - stdx::function<Status(OperationContext* opCtx, const NamespaceString& nss)>; + std::function<Status(OperationContext*, const NamespaceString& nss)>; + using DropCollectionFn = std::function<Status(OperationContext*, const NamespaceString& nss)>; using FindDocumentsFn = - stdx::function<StatusWith<std::vector<BSONObj>>(OperationContext* opCtx, - const NamespaceString& nss, - boost::optional<StringData> indexName, - ScanDirection scanDirection, - const BSONObj& startKey, - BoundInclusion boundInclusion, - std::size_t limit)>; + std::function<StatusWith<std::vector<BSONObj>>(OperationContext*, + const NamespaceString&, + boost::optional<StringData>, + ScanDirection, + const BSONObj&, + BoundInclusion, + std::size_t)>; using DeleteDocumentsFn = - stdx::function<StatusWith<std::vector<BSONObj>>(OperationContext* opCtx, - const NamespaceString& nss, - boost::optional<StringData> indexName, - ScanDirection scanDirection, - const BSONObj& startKey, - BoundInclusion boundInclusion, - std::size_t limit)>; - using IsAdminDbValidFn = stdx::function<Status(OperationContext* opCtx)>; - using GetCollectionUUIDFn = stdx::function<StatusWith<OptionalCollectionUUID>( - OperationContext* opCtx, const NamespaceString& nss)>; - using UpgradeNonReplicatedUniqueIndexesFn = stdx::function<Status(OperationContext* opCtx)>; + std::function<StatusWith<std::vector<BSONObj>>(OperationContext*, + const NamespaceString&, + boost::optional<StringData>, + ScanDirection, + const BSONObj&, + BoundInclusion, + std::size_t)>; + using IsAdminDbValidFn = std::function<Status(OperationContext*)>; + using GetCollectionUUIDFn = std::function<StatusWith<OptionalCollectionUUID>( + OperationContext*, const NamespaceString&)>; + using UpgradeNonReplicatedUniqueIndexesFn = std::function<Status(OperationContext*)>; StorageInterfaceMock() = default; diff --git a/src/mongo/db/s/config/sharding_catalog_manager.h b/src/mongo/db/s/config/sharding_catalog_manager.h index 6dd272a5517..309f5eaa386 100644 --- a/src/mongo/db/s/config/sharding_catalog_manager.h +++ b/src/mongo/db/s/config/sharding_catalog_manager.h @@ -1,4 +1,3 @@ - /** * Copyright (C) 2018-present MongoDB, Inc. * |