summaryrefslogtreecommitdiff
path: root/src/mongo/db/exec/write_stage_common.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/exec/write_stage_common.cpp')
-rw-r--r--src/mongo/db/exec/write_stage_common.cpp22
1 files changed, 11 insertions, 11 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;
}