summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEsha Maharishi <esha.maharishi@mongodb.com>2019-09-09 14:32:15 +0000
committerEsha Maharishi <esha.maharishi@mongodb.com>2019-09-09 21:57:11 -0400
commit17174308e001e0ed3095a4599830636570f791e3 (patch)
treee1e250f831d8e52bfe0d9a512cbf1dc3218ebff7 /src
parentf58d1d66568ff054f72fc0bb718528bc2dbc39d8 (diff)
downloadmongo-17174308e001e0ed3095a4599830636570f791e3.tar.gz
SERVER-42842 Unable to drop collection in admin database of sharded cluster
(cherry picked from commit 02dbec04bad4a6b138a204a29644a0524e5c3123)
Diffstat (limited to 'src')
-rw-r--r--src/mongo/db/s/config/configsvr_drop_collection_command.cpp40
-rw-r--r--src/mongo/db/s/config/sharding_catalog_manager_collection_operations.cpp6
2 files changed, 39 insertions, 7 deletions
diff --git a/src/mongo/db/s/config/configsvr_drop_collection_command.cpp b/src/mongo/db/s/config/configsvr_drop_collection_command.cpp
index cfab7b50f56..66c2cb94653 100644
--- a/src/mongo/db/s/config/configsvr_drop_collection_command.cpp
+++ b/src/mongo/db/s/config/configsvr_drop_collection_command.cpp
@@ -144,7 +144,45 @@ private:
catalogClient->getCollection(opCtx, nss, repl::ReadConcernArgs::get(opCtx).getLevel());
if (collStatus == ErrorCodes::NamespaceNotFound) {
// We checked the sharding catalog and found that this collection doesn't exist. This
- // may be because it never existed, or because a drop command was sent previously.
+ // may be because it never existed, or because a drop command was sent previously. This
+ // data might not be majority committed though, so we will set the client's last optime
+ // to the system's last optime to ensure the client waits for the writeConcern to be
+ // satisfied.
+ repl::ReplClientInfo::forClient(opCtx->getClient()).setLastOpToSystemLastOpTime(opCtx);
+
+ // If the DB isn't in the sharding catalog either, consider the drop a success.
+ auto dbStatus = catalogClient->getDatabase(
+ opCtx, nss.db().toString(), repl::ReadConcernArgs::get(opCtx).getLevel());
+ if (dbStatus == ErrorCodes::NamespaceNotFound) {
+ return;
+ }
+ uassertStatusOK(dbStatus);
+
+ // If we found the DB but not the collection, and the primary shard for the database is
+ // the config server, run the drop only against the config server unless the collection
+ // is config.system.sessions, since no other collections whose primary shard is the
+ // config server can have been sharded.
+ const auto primaryShard = dbStatus.getValue().value.getPrimary();
+ if (primaryShard == "config" && nss != NamespaceString::kLogicalSessionsNamespace) {
+ auto cmdDropResult =
+ uassertStatusOK(Grid::get(opCtx)
+ ->shardRegistry()
+ ->getConfigShard()
+ ->runCommandWithFixedRetryAttempts(
+ opCtx,
+ ReadPreferenceSetting{ReadPreference::PrimaryOnly},
+ nss.db().toString(),
+ BSON("drop" << nss.coll()),
+ Shard::RetryPolicy::kIdempotent));
+
+ // If the collection doesn't exist, consider the drop a success.
+ if (cmdDropResult.commandStatus == ErrorCodes::NamespaceNotFound) {
+ return;
+ }
+ uassertStatusOK(cmdDropResult.commandStatus);
+ return;
+ }
+
ShardingCatalogManager::get(opCtx)->ensureDropCollectionCompleted(opCtx, nss);
} else {
uassertStatusOK(collStatus);
diff --git a/src/mongo/db/s/config/sharding_catalog_manager_collection_operations.cpp b/src/mongo/db/s/config/sharding_catalog_manager_collection_operations.cpp
index 13f2423e64f..54231dba85a 100644
--- a/src/mongo/db/s/config/sharding_catalog_manager_collection_operations.cpp
+++ b/src/mongo/db/s/config/sharding_catalog_manager_collection_operations.cpp
@@ -333,12 +333,6 @@ void ShardingCatalogManager::ensureDropCollectionCompleted(OperationContext* opC
LOG(1) << "Ensuring config entries for " << nss.ns()
<< " from previous dropCollection are cleared";
-
- // If there was a drop command already sent for this command, the command may not be majority
- // committed. We will set the client's last optime to the system's last optime to ensure the
- // client waits for the writeConcern to be satisfied.
- repl::ReplClientInfo::forClient(opCtx->getClient()).setLastOpToSystemLastOpTime(opCtx);
-
sendDropCollectionToAllShards(opCtx, nss);
removeChunksAndTagsForDroppedCollection(opCtx, nss);
sendSSVAndUnsetShardingToAllShards(opCtx, nss);