summaryrefslogtreecommitdiff
path: root/src/mongo/db/s
diff options
context:
space:
mode:
authorKaloian Manassiev <kaloian.manassiev@mongodb.com>2021-04-20 18:51:28 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-04-28 07:10:59 +0000
commitcc69d699417c64335942cbadcbdd3c2b886debd8 (patch)
tree9b3839849843325f035fb044308663a9a8cdb1ab /src/mongo/db/s
parent0464f0b7bcb2eee8dafbf108447013b4d586a16a (diff)
downloadmongo-cc69d699417c64335942cbadcbdd3c2b886debd8.tar.gz
SERVER-56353 Cleanup incomplete chunks from a failed pre-5.0 shard/dropCollection
Diffstat (limited to 'src/mongo/db/s')
-rw-r--r--src/mongo/db/s/config/sharding_catalog_manager.cpp21
-rw-r--r--src/mongo/db/s/sharding_mongod_test_fixture.cpp1
2 files changed, 21 insertions, 1 deletions
diff --git a/src/mongo/db/s/config/sharding_catalog_manager.cpp b/src/mongo/db/s/config/sharding_catalog_manager.cpp
index cf1c9466748..813c6f3d0d3 100644
--- a/src/mongo/db/s/config/sharding_catalog_manager.cpp
+++ b/src/mongo/db/s/config/sharding_catalog_manager.cpp
@@ -280,6 +280,23 @@ Status createUuidIndexesForConfigChunks(OperationContext* opCtx) {
return Status::OK();
}
+/**
+ * This step runs on FCV switch between 4.4 <-> 5.0, right after the shards have been told to enter
+ * Phase 1 and after all the local chunks' format has been changed to contain both UUID and
+ * Namespace.
+ *
+ * If isOnUpgrade is true, it will remove any config.chunks entries, which do not have UUID and if
+ * it is false, it will remove those which do not have Namespace.
+ */
+void removeIncompleteChunks(OperationContext* opCtx, bool isOnUpgrade) {
+ const auto catalogClient = Grid::get(opCtx)->catalogClient();
+
+ auto query = isOnUpgrade ? BSON(ChunkType::collectionUUID << BSON("$exists" << false))
+ : BSON(ChunkType::ns << BSON("$exists" << false));
+ uassertStatusOK(catalogClient->removeConfigDocuments(
+ opCtx, ChunkType::ConfigNS, query, ShardingCatalogClient::kLocalWriteConcern));
+}
+
} // namespace
void ShardingCatalogManager::create(ServiceContext* serviceContext,
@@ -795,6 +812,8 @@ void ShardingCatalogManager::_upgradeCollectionsAndChunksEntriesTo50Phase1(
true /* multi */);
}
+ removeIncompleteChunks(opCtx, true /* isOnUpgrade */);
+
// Create uuid_* indexes for config.chunks
uassertStatusOK(createUuidIndexesForConfigChunks(opCtx));
@@ -938,6 +957,8 @@ void ShardingCatalogManager::_downgradeCollectionsAndChunksEntriesToPre50Phase1(
true /* multi */);
}
+ removeIncompleteChunks(opCtx, false /* isOnUpgrade */);
+
// Create ns_* indexes for config.chunks
uassertStatusOK(createNsIndexesForConfigChunks(opCtx));
diff --git a/src/mongo/db/s/sharding_mongod_test_fixture.cpp b/src/mongo/db/s/sharding_mongod_test_fixture.cpp
index e65baf54fb6..3760b7e0661 100644
--- a/src/mongo/db/s/sharding_mongod_test_fixture.cpp
+++ b/src/mongo/db/s/sharding_mongod_test_fixture.cpp
@@ -51,7 +51,6 @@
#include "mongo/db/repl/replication_process.h"
#include "mongo/db/repl/replication_recovery_mock.h"
#include "mongo/db/repl/storage_interface_mock.h"
-#include "mongo/db/s/collection_sharding_state_factory_shard.h"
#include "mongo/db/s/config_server_op_observer.h"
#include "mongo/db/s/op_observer_sharding_impl.h"
#include "mongo/db/s/shard_local.h"