From 249f411a79fd11559830658d45b1ebca4d6c9865 Mon Sep 17 00:00:00 2001 From: Mihai Andrei Date: Wed, 4 Sep 2019 21:05:25 +0000 Subject: SERVER-35050 Don't abort collection clone due to negative document count (cherry picked from commit 5ed5b857aaf2e2fbf443588e9b4cbb359fbd1f4d) --- src/mongo/db/repl/collection_cloner.cpp | 12 ++++++------ 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 { -- cgit v1.2.1