summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mongo/db/repl/collection_cloner.cpp12
-rw-r--r--src/mongo/db/repl/collection_cloner_test.cpp5
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 0cfb0eb46c0..ee3b0c78a9f 100644
--- a/src/mongo/db/repl/collection_cloner.cpp
+++ b/src/mongo/db/repl/collection_cloner.cpp
@@ -352,13 +352,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 23a15426583..246e9f44d21 100644
--- a/src/mongo/db/repl/collection_cloner_test.cpp
+++ b/src/mongo/db/repl/collection_cloner_test.cpp
@@ -326,15 +326,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 {