summaryrefslogtreecommitdiff
path: root/src/mongo/db/s/shard_server_op_observer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/s/shard_server_op_observer.cpp')
-rw-r--r--src/mongo/db/s/shard_server_op_observer.cpp11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/mongo/db/s/shard_server_op_observer.cpp b/src/mongo/db/s/shard_server_op_observer.cpp
index a374159bc87..91aa5b9564b 100644
--- a/src/mongo/db/s/shard_server_op_observer.cpp
+++ b/src/mongo/db/s/shard_server_op_observer.cpp
@@ -587,9 +587,16 @@ void ShardServerOpObserver::onCreateCollection(OperationContext* opCtx,
const BSONObj& idIndex,
const OplogSlot& createOpTime,
bool fromMigrate) {
- // Only the shard primay nodes control the collection creation and secondaries just follow
- // Secondaries CSR will be the defaulted one (UNKNOWN in most of the cases)
+ // Only the shard primary nodes control the collection creation.
if (!opCtx->writesAreReplicated()) {
+ // On secondaries node of sharded cluster we force the cleanup of the filtering metadata in
+ // order to remove anything that was left from any previous collection instance. This could
+ // happen by first having an UNSHARDED version for a collection that didn't exist followed
+ // by a movePrimary to the current shard.
+ if (ShardingState::get(opCtx)->enabled()) {
+ CollectionShardingRuntime::get(opCtx, collectionName)->clearFilteringMetadata(opCtx);
+ }
+
return;
}