diff options
author | Mihai Andrei <mihai.andrei@mongodb.com> | 2019-09-04 21:05:25 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-02-27 20:22:50 +0000 |
commit | 249f411a79fd11559830658d45b1ebca4d6c9865 (patch) | |
tree | f19b20dbb5524050f3bf49c1fe088828e16b8a2f | |
parent | c278fcebdc161bc589fd4869a51019cfa1cdaf8c (diff) | |
download | mongo-249f411a79fd11559830658d45b1ebca4d6c9865.tar.gz |
SERVER-35050 Don't abort collection clone due to negative document count
(cherry picked from commit 5ed5b857aaf2e2fbf443588e9b4cbb359fbd1f4d)
-rw-r--r-- | src/mongo/db/repl/collection_cloner.cpp | 12 | ||||
-rw-r--r-- | src/mongo/db/repl/collection_cloner_test.cpp | 5 |
2 files changed, 9 insertions, 8 deletions
diff --git a/src/mongo/db/repl/collection_cloner.cpp b/src/mongo/db/repl/collection_cloner.cpp index fad3e712cdc..e6dac3b5f31 100644 --- a/src/mongo/db/repl/collection_cloner.cpp +++ b/src/mongo/db/repl/collection_cloner.cpp @@ -343,13 +343,13 @@ void CollectionCloner::_countCallback( } } + // The count command may return a negative value after an unclean shutdown, + // so we set it to zero here to avoid aborting the collection clone. + // Note that this count value is only used for reporting purposes. if (count < 0) { - _finishCallback({ErrorCodes::BadValue, - str::stream() << "Count call on collection " << _sourceNss.ns() << " from " - << _source.toString() - << " returned negative document count: " - << count}); - return; + warning() << "Count command returned negative value. Updating to 0 to allow progress " + "meter to function properly. "; + count = 0; } { diff --git a/src/mongo/db/repl/collection_cloner_test.cpp b/src/mongo/db/repl/collection_cloner_test.cpp index cd01d18067f..6092e64f04b 100644 --- a/src/mongo/db/repl/collection_cloner_test.cpp +++ b/src/mongo/db/repl/collection_cloner_test.cpp @@ -330,15 +330,16 @@ TEST_F(CollectionClonerTest, CollectionClonerReturnsNoSuchKeyOnMissingDocumentCo ASSERT_EQUALS(ErrorCodes::NoSuchKey, getStatus()); } -TEST_F(CollectionClonerTest, CollectionClonerReturnsBadValueOnNegativeDocumentCount) { +TEST_F(CollectionClonerTest, CollectionClonerDoesNotAbortOnNegativeDocumentCount) { ASSERT_OK(collectionCloner->startup()); { executor::NetworkInterfaceMock::InNetworkGuard guard(getNet()); processNetworkResponse(createCountResponse(-1)); } + getExecutor().shutdown(); collectionCloner->join(); - ASSERT_EQUALS(ErrorCodes::BadValue, getStatus()); + ASSERT_EQUALS(0U, collectionCloner->getStats().documentToCopy); } class TaskExecutorWithFailureInScheduleRemoteCommand : public unittest::TaskExecutorProxy { |