summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergi Mateo Bellido <sergi.mateo-bellido@mongodb.com>2022-02-10 09:14:16 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-02-10 09:42:30 +0000
commit20d836242f5b0187776a2e690ce9bfa4ddc4d476 (patch)
treeba920960df8a23f810150dc9548b93fe19efaee4
parent91dfc731f52bd93627a711e1686146821613f443 (diff)
downloadmongo-20d836242f5b0187776a2e690ce9bfa4ddc4d476.tar.gz
SERVER-63430 Compute the isStandaloneOrPrimary flag once
-rw-r--r--src/mongo/db/exec/write_stage_common.cpp15
-rw-r--r--src/mongo/db/exec/write_stage_common.h4
2 files changed, 10 insertions, 9 deletions
diff --git a/src/mongo/db/exec/write_stage_common.cpp b/src/mongo/db/exec/write_stage_common.cpp
index 2c04a1d3351..e341a158cba 100644
--- a/src/mongo/db/exec/write_stage_common.cpp
+++ b/src/mongo/db/exec/write_stage_common.cpp
@@ -57,12 +57,14 @@ bool computeIsStandaloneOrPrimary(OperationContext* opCtx) {
namespace write_stage_common {
PreWriteFilter::PreWriteFilter(OperationContext* opCtx, NamespaceString nss)
- : _opCtx(opCtx), _nss(std::move(nss)) {
- _isStandaloneOrPrimary = computeIsStandaloneOrPrimary(_opCtx);
- auto& fcv = serverGlobalParams.featureCompatibility;
- _isEnabled = fcv.isVersionInitialized() &&
- feature_flags::gFeatureFlagNoChangeStreamEventsDueToOrphans.isEnabled(fcv);
-}
+ : _opCtx(opCtx),
+ _nss(std::move(nss)),
+ _isEnabled([] {
+ auto& fcv = serverGlobalParams.featureCompatibility;
+ return fcv.isVersionInitialized() &&
+ feature_flags::gFeatureFlagNoChangeStreamEventsDueToOrphans.isEnabled(fcv);
+ }()),
+ _isStandaloneOrPrimary(computeIsStandaloneOrPrimary(_opCtx)) {}
PreWriteFilter::Action PreWriteFilter::computeAction(const Document& doc) {
// Skip the checks if the Filter is not enabled.
@@ -109,7 +111,6 @@ bool PreWriteFilter::_documentBelongsToMe(const BSONObj& doc) {
}
void PreWriteFilter::restoreState() {
- _isStandaloneOrPrimary = computeIsStandaloneOrPrimary(_opCtx);
_shardFilterer.reset();
}
diff --git a/src/mongo/db/exec/write_stage_common.h b/src/mongo/db/exec/write_stage_common.h
index 99a3da7c3b8..3eff70da081 100644
--- a/src/mongo/db/exec/write_stage_common.h
+++ b/src/mongo/db/exec/write_stage_common.h
@@ -79,8 +79,8 @@ private:
OperationContext* _opCtx;
NamespaceString _nss;
- bool _isEnabled;
- bool _isStandaloneOrPrimary;
+ const bool _isEnabled;
+ const bool _isStandaloneOrPrimary;
std::unique_ptr<ShardFilterer> _shardFilterer;
};