diff options
author | Benety Goh <benety@mongodb.com> | 2017-01-12 14:17:59 -0500 |
---|---|---|
committer | Benety Goh <benety@mongodb.com> | 2017-01-21 07:45:06 -0500 |
commit | 921906a20d9f0337fc18f716da8849e00d908f68 (patch) | |
tree | 766aec679122e8f91736aea5ec4bdbbbe64323ae | |
parent | 23d8d6530a044494746c919aa6b73d5317b6b667 (diff) | |
download | mongo-921906a20d9f0337fc18f716da8849e00d908f68.tar.gz |
SERVER-27611 DatabaseCloner::shutdown() should shut down CollectionCloner
-rw-r--r-- | src/mongo/db/repl/database_cloner.cpp | 4 | ||||
-rw-r--r-- | src/mongo/db/repl/database_cloner_test.cpp | 40 |
2 files changed, 44 insertions, 0 deletions
diff --git a/src/mongo/db/repl/database_cloner.cpp b/src/mongo/db/repl/database_cloner.cpp index 4a2ed14d72b..224d6d15a08 100644 --- a/src/mongo/db/repl/database_cloner.cpp +++ b/src/mongo/db/repl/database_cloner.cpp @@ -191,6 +191,10 @@ void DatabaseCloner::shutdown() { if (!_active) { return; } + + for (auto&& collectionCloner : _collectionCloners) { + collectionCloner.shutdown(); + } } _listCollectionsFetcher.shutdown(); diff --git a/src/mongo/db/repl/database_cloner_test.cpp b/src/mongo/db/repl/database_cloner_test.cpp index c2e13b2e8a9..5eeca00cfcd 100644 --- a/src/mongo/db/repl/database_cloner_test.cpp +++ b/src/mongo/db/repl/database_cloner_test.cpp @@ -568,6 +568,46 @@ TEST_F(DatabaseClonerTest, StartSecondCollectionClonerFailed) { ASSERT_EQUALS(errStatus, getStatus()); } +TEST_F(DatabaseClonerTest, ShutdownCancelsCollectionCloning) { + ASSERT_OK(_databaseCloner->startup()); + auto net = getNet(); + { + executor::NetworkInterfaceMock::InNetworkGuard guard(net); + + assertRemoteCommandNameEquals("listCollections", + net->scheduleSuccessfulResponse(createListCollectionsResponse( + 0, + BSON_ARRAY(BSON("name" + << "a" + << "options" + << BSONObj()) + << BSON("name" + << "b" + << "options" + << BSONObj()))))); + net->runReadyNetworkOperations(); + + // CollectionCloner sends collection count request on startup. + // Blackhole count request to leave collection cloner active. + auto noi = net->getNextReadyRequest(); + assertRemoteCommandNameEquals("count", noi->getRequest()); + ASSERT_EQUALS("a", noi->getRequest().cmdObj.firstElement().String()); + net->blackHole(noi); + } + + _databaseCloner->shutdown(); + + // Deliver cancellation event to cloners. + executor::NetworkInterfaceMock::InNetworkGuard(net)->runReadyNetworkOperations(); + + _databaseCloner->join(); + ASSERT_FALSE(_databaseCloner->isActive()); + + // This is the error code from attempting to start up the last (of 2) collection cloner which + // was shut down before it was ever started. + ASSERT_EQUALS(ErrorCodes::ShutdownInProgress, getStatus()); +} + TEST_F(DatabaseClonerTest, FirstCollectionListIndexesFailed) { ASSERT_OK(_databaseCloner->startup()); |