summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierlauro Sciarelli <pierlauro.sciarelli@mongodb.com>2021-10-27 16:00:28 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-10-28 09:47:37 +0000
commit1a192eb1ed4dc0f3c2be3afb2cc79e50eae81ebc (patch)
tree475cd4c440256199a180102630b67aae7d574991
parent8def1746e85ab88314e4b2af3c2850ce580db1a7 (diff)
downloadmongo-1a192eb1ed4dc0f3c2be3afb2cc79e50eae81ebc.tar.gz
SERVER-61026 Invert order of shards receiving drop collection participant command
-rw-r--r--src/mongo/db/s/drop_collection_coordinator.cpp8
-rw-r--r--src/mongo/db/s/drop_database_coordinator.cpp11
2 files changed, 12 insertions, 7 deletions
diff --git a/src/mongo/db/s/drop_collection_coordinator.cpp b/src/mongo/db/s/drop_collection_coordinator.cpp
index fd5fb691b02..5caf5edca7f 100644
--- a/src/mongo/db/s/drop_collection_coordinator.cpp
+++ b/src/mongo/db/s/drop_collection_coordinator.cpp
@@ -198,8 +198,6 @@ ExecutorFuture<void> DropCollectionCoordinator::_runImpl(
_doc = _updateSession(opCtx, _doc);
const auto primaryShardId = ShardingState::get(opCtx)->shardId();
- sharding_ddl_util::sendDropCollectionParticipantCommandToShards(
- opCtx, nss(), {primaryShardId}, **executor, getCurrentSession(_doc));
// We need to send the drop to all the shards because both movePrimary and
// moveChunk leave garbage behind for sharded collections.
@@ -212,6 +210,12 @@ ExecutorFuture<void> DropCollectionCoordinator::_runImpl(
sharding_ddl_util::sendDropCollectionParticipantCommandToShards(
opCtx, nss(), participants, **executor, getCurrentSession(_doc));
+ // The sharded collection must be dropped on the primary shard after it has been
+ // dropped on all of the other shards to ensure it can only be re-created as
+ // unsharded with a higher optime than all of the drops.
+ sharding_ddl_util::sendDropCollectionParticipantCommandToShards(
+ opCtx, nss(), {primaryShardId}, **executor, getCurrentSession(_doc));
+
ShardingLogging::get(opCtx)->logChange(opCtx, "dropCollection", nss().ns());
LOGV2(5390503, "Collection dropped", "namespace"_attr = nss());
}))
diff --git a/src/mongo/db/s/drop_database_coordinator.cpp b/src/mongo/db/s/drop_database_coordinator.cpp
index 26fba5a99f0..70a79970fe2 100644
--- a/src/mongo/db/s/drop_database_coordinator.cpp
+++ b/src/mongo/db/s/drop_database_coordinator.cpp
@@ -138,11 +138,6 @@ void DropDatabaseCoordinator::_dropShardedCollection(
const auto primaryShardId = ShardingState::get(opCtx)->shardId();
_doc = _updateSession(opCtx, _doc);
- // The collection needs to be dropped first on the db primary shard
- // because otherwise changestreams won't receive the drop event.
- sharding_ddl_util::sendDropCollectionParticipantCommandToShards(
- opCtx, nss, {primaryShardId}, **executor, getCurrentSession(_doc));
-
// We need to send the drop to all the shards because both movePrimary and
// moveChunk leave garbage behind for sharded collections.
auto participants = Grid::get(opCtx)->shardRegistry()->getAllShardIds(opCtx);
@@ -151,6 +146,12 @@ void DropDatabaseCoordinator::_dropShardedCollection(
participants.end());
sharding_ddl_util::sendDropCollectionParticipantCommandToShards(
opCtx, nss, participants, **executor, getCurrentSession(_doc));
+
+ // The sharded collection must be dropped on the primary shard after it has been dropped on all
+ // of the other shards to ensure it can only be re-created as unsharded with a higher optime
+ // than all of the drops.
+ sharding_ddl_util::sendDropCollectionParticipantCommandToShards(
+ opCtx, nss, {primaryShardId}, **executor, getCurrentSession(_doc));
}
DropDatabaseCoordinator::DropDatabaseCoordinator(ShardingDDLCoordinatorService* service,