summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntonio Fuschetto <antonio.fuschetto@mongodb.com>2022-06-22 11:48:29 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-06-22 12:38:49 +0000
commite2d8053e518259c1df27211281a7cfa697dfaa12 (patch)
tree87a7726eec0fa9be5d887748e78606638082af8f
parenta182192a647b03bc91be48d94dd14f3bb2325bbf (diff)
downloadmongo-e2d8053e518259c1df27211281a7cfa697dfaa12.tar.gz
SERVER-67352 Skip identifying writes on orphaned documents in replica set deployments
-rw-r--r--src/mongo/db/exec/write_stage_common.cpp22
-rw-r--r--src/mongo/db/exec/write_stage_common.h2
2 files changed, 12 insertions, 12 deletions
diff --git a/src/mongo/db/exec/write_stage_common.cpp b/src/mongo/db/exec/write_stage_common.cpp
index 0a1ed4179aa..3d885d9d50e 100644
--- a/src/mongo/db/exec/write_stage_common.cpp
+++ b/src/mongo/db/exec/write_stage_common.cpp
@@ -46,15 +46,6 @@
namespace mongo {
-namespace {
-
-bool computeIsStandaloneOrPrimary(OperationContext* opCtx) {
- const auto replCoord{repl::ReplicationCoordinator::get(opCtx)};
- return replCoord->canAcceptWritesForDatabase(opCtx, "admin");
-}
-
-} // namespace
-
namespace write_stage_common {
PreWriteFilter::PreWriteFilter(OperationContext* opCtx, NamespaceString nss)
@@ -65,14 +56,23 @@ PreWriteFilter::PreWriteFilter(OperationContext* opCtx, NamespaceString nss)
return fcv.isVersionInitialized() &&
feature_flags::gFeatureFlagNoChangeStreamEventsDueToOrphans.isEnabled(fcv);
}()),
- _isStandaloneOrPrimary(computeIsStandaloneOrPrimary(_opCtx)) {}
+ _skipFiltering([&] {
+ // Always allow writes on replica sets.
+ if (serverGlobalParams.clusterRole == ClusterRole::None) {
+ return true;
+ }
+
+ // Always allow writes on standalone and secondary nodes.
+ const auto replCoord{repl::ReplicationCoordinator::get(opCtx)};
+ return !replCoord->canAcceptWritesForDatabase(opCtx, NamespaceString::kAdminDb);
+ }()) {}
PreWriteFilter::Action PreWriteFilter::computeAction(const Document& doc) {
// Skip the checks if the Filter is not enabled.
if (!_isEnabled)
return Action::kWrite;
- if (!_isStandaloneOrPrimary) {
+ if (_skipFiltering) {
// Secondaries do not apply any filtering logic as the primary already did.
return Action::kWrite;
}
diff --git a/src/mongo/db/exec/write_stage_common.h b/src/mongo/db/exec/write_stage_common.h
index 3eff70da081..5628822efff 100644
--- a/src/mongo/db/exec/write_stage_common.h
+++ b/src/mongo/db/exec/write_stage_common.h
@@ -80,7 +80,7 @@ private:
OperationContext* _opCtx;
NamespaceString _nss;
const bool _isEnabled;
- const bool _isStandaloneOrPrimary;
+ const bool _skipFiltering;
std::unique_ptr<ShardFilterer> _shardFilterer;
};