summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergi Mateo Bellido <sergi.mateo-bellido@mongodb.com>2021-12-28 12:09:51 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-12-28 12:38:39 +0000
commit0465077ab52fbc4683b2633fec53b2153293bb07 (patch)
tree2b70945913b5b3d7eb7a7d4c7bd2da4e1bc3a3eb
parent5eab3ca8acaa0e8004c50112187b6809667157a2 (diff)
downloadmongo-0465077ab52fbc4683b2633fec53b2153293bb07.tar.gz
SERVER-62128 Do not assume FCV stability when filtering writes
-rw-r--r--src/mongo/db/exec/write_stage_common.cpp6
-rw-r--r--src/mongo/db/s/collection_sharding_runtime.cpp13
-rw-r--r--src/mongo/db/s/collection_sharding_runtime.h3
-rw-r--r--src/mongo/db/s/collection_sharding_state.h12
-rw-r--r--src/mongo/db/s/collection_sharding_state_factory_standalone.cpp3
5 files changed, 22 insertions, 15 deletions
diff --git a/src/mongo/db/exec/write_stage_common.cpp b/src/mongo/db/exec/write_stage_common.cpp
index c29e7d79a98..ffbf6ac0eca 100644
--- a/src/mongo/db/exec/write_stage_common.cpp
+++ b/src/mongo/db/exec/write_stage_common.cpp
@@ -96,8 +96,10 @@ bool skipWriteToOrphanDocument(OperationContext* opCtx,
}
const auto css{CollectionShardingState::get(opCtx, nss)};
- const auto collFilter{css->getOwnershipFilter(
- opCtx, CollectionShardingState::OrphanCleanupPolicy::kAllowOrphanCleanup)};
+ const auto collFilter{
+ css->getOwnershipFilter(opCtx,
+ CollectionShardingState::OrphanCleanupPolicy::kAllowOrphanCleanup,
+ true /* supportNonVersionedOperations */)};
if (!collFilter.isSharded()) {
// NOTE: Sharded collections queried by direct writes are identified by CSS as unsharded
diff --git a/src/mongo/db/s/collection_sharding_runtime.cpp b/src/mongo/db/s/collection_sharding_runtime.cpp
index a82d1c99c0e..5fbac2182ef 100644
--- a/src/mongo/db/s/collection_sharding_runtime.cpp
+++ b/src/mongo/db/s/collection_sharding_runtime.cpp
@@ -39,7 +39,6 @@
#include "mongo/db/s/sharding_runtime_d_params_gen.h"
#include "mongo/db/s/sharding_state.h"
#include "mongo/logv2/log.h"
-#include "mongo/s/pm2423_feature_flags_gen.h"
#include "mongo/s/type_collection_common_types_gen.h"
#include "mongo/util/duration.h"
@@ -97,13 +96,11 @@ CollectionShardingRuntime* CollectionShardingRuntime::get(CollectionShardingStat
}
ScopedCollectionFilter CollectionShardingRuntime::getOwnershipFilter(
- OperationContext* opCtx, OrphanCleanupPolicy orphanCleanupPolicy) {
- bool migrationRecipientCriticalSectionEnabled =
- feature_flags::gFeatureFlagMigrationRecipientCriticalSection.isEnabled(
- serverGlobalParams.featureCompatibility);
-
+ OperationContext* opCtx,
+ OrphanCleanupPolicy orphanCleanupPolicy,
+ bool supportNonVersionedOperations) {
boost::optional<ChunkVersion> optReceivedShardVersion = boost::none;
- if (!migrationRecipientCriticalSectionEnabled) {
+ if (!supportNonVersionedOperations) {
optReceivedShardVersion = getOperationReceivedVersion(opCtx, _nss);
// No operations should be calling getOwnershipFilter without a shard version
invariant(optReceivedShardVersion,
@@ -113,7 +110,7 @@ ScopedCollectionFilter CollectionShardingRuntime::getOwnershipFilter(
auto metadata = _getMetadataWithVersionCheckAt(
opCtx, repl::ReadConcernArgs::get(opCtx).getArgsAtClusterTime());
- if (!migrationRecipientCriticalSectionEnabled) {
+ if (!supportNonVersionedOperations) {
invariant(!ChunkVersion::isIgnoredVersion(*optReceivedShardVersion) ||
!metadata->get().allowMigrations() || !metadata->get().isSharded(),
"For sharded collections getOwnershipFilter cannot be relied on without a valid "
diff --git a/src/mongo/db/s/collection_sharding_runtime.h b/src/mongo/db/s/collection_sharding_runtime.h
index f5f47460ee2..09496b0ef33 100644
--- a/src/mongo/db/s/collection_sharding_runtime.h
+++ b/src/mongo/db/s/collection_sharding_runtime.h
@@ -73,7 +73,8 @@ public:
static CollectionShardingRuntime* get(CollectionShardingState* css);
ScopedCollectionFilter getOwnershipFilter(OperationContext* opCtx,
- OrphanCleanupPolicy orphanCleanupPolicy) override;
+ OrphanCleanupPolicy orphanCleanupPolicy,
+ bool supportNonVersionedOperations) override;
ScopedCollectionDescription getCollectionDescription(OperationContext* opCtx) override;
diff --git a/src/mongo/db/s/collection_sharding_state.h b/src/mongo/db/s/collection_sharding_state.h
index 25f43d507be..53adbe24fde 100644
--- a/src/mongo/db/s/collection_sharding_state.h
+++ b/src/mongo/db/s/collection_sharding_state.h
@@ -123,7 +123,11 @@ public:
* destroyed. The intended users of this mode are read operations, which need to yield the
* collection lock, but still perform filtering.
*
- * If the request doesn't have a shard version all collections will be treated as UNSHARDED.
+ * The 'supportNonVersionedOperations' parameter states whether this function should consider
+ * operations that don't have a shard version.
+ * If the request doesn't have a shard version:
+ * - this function will invariant if !supportNonVersionedOperations (default value)
+ * - the collection will be treated as UNSHARDED otherwise.
*
* Use 'getCollectionDescription' for other cases, like obtaining information about
* sharding-related properties of the collection are necessary that won't change under
@@ -132,8 +136,10 @@ public:
* The returned object *is safe* to access even after the collection lock has been dropped.
*/
enum class OrphanCleanupPolicy { kDisallowOrphanCleanup, kAllowOrphanCleanup };
- virtual ScopedCollectionFilter getOwnershipFilter(OperationContext* opCtx,
- OrphanCleanupPolicy orphanCleanupPolicy) = 0;
+ virtual ScopedCollectionFilter getOwnershipFilter(
+ OperationContext* opCtx,
+ OrphanCleanupPolicy orphanCleanupPolicy,
+ bool supportNonVersionedOperations = false) = 0;
/**
* Checks whether the shard version in the operation context is compatible with the shard
diff --git a/src/mongo/db/s/collection_sharding_state_factory_standalone.cpp b/src/mongo/db/s/collection_sharding_state_factory_standalone.cpp
index 3c0be93b3be..6422dc066f1 100644
--- a/src/mongo/db/s/collection_sharding_state_factory_standalone.cpp
+++ b/src/mongo/db/s/collection_sharding_state_factory_standalone.cpp
@@ -56,7 +56,8 @@ public:
return {kUnshardedCollection};
}
ScopedCollectionFilter getOwnershipFilter(OperationContext*,
- OrphanCleanupPolicy orphanCleanupPolicy) override {
+ OrphanCleanupPolicy orphanCleanupPolicy,
+ bool supportNonVersionedOperations) override {
return {kUnshardedCollection};
}
void checkShardVersionOrThrow(OperationContext*) override {}