diff options
author | Huayu Ouyang <huayu.ouyang@mongodb.com> | 2021-05-19 16:49:27 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-05-21 00:22:43 +0000 |
commit | 50f99d96af30d061ff2a664c49e3953293fb9ffe (patch) | |
tree | a2a345032523038d25f46073f4afa75778e29ac4 /src/mongo | |
parent | 9434716bca785e0a0abce212272f27fdceb73054 (diff) | |
download | mongo-50f99d96af30d061ff2a664c49e3953293fb9ffe.tar.gz |
SERVER-57042 Don't store defaultWriteConcernSource on disk
Diffstat (limited to 'src/mongo')
-rw-r--r-- | src/mongo/db/read_write_concern_defaults.cpp | 65 | ||||
-rw-r--r-- | src/mongo/db/read_write_concern_defaults.h | 3 | ||||
-rw-r--r-- | src/mongo/db/read_write_concern_defaults_test.cpp | 203 |
3 files changed, 180 insertions, 91 deletions
diff --git a/src/mongo/db/read_write_concern_defaults.cpp b/src/mongo/db/read_write_concern_defaults.cpp index debf69a43f6..2822f620688 100644 --- a/src/mongo/db/read_write_concern_defaults.cpp +++ b/src/mongo/db/read_write_concern_defaults.cpp @@ -110,11 +110,6 @@ RWConcernDefault ReadWriteConcernDefaults::generateNewCWRWCToBeSavedOnDisk( rc || wc); RWConcernDefault rwc; - const bool isDefaultWCMajorityFeatureFlagEnabled = - repl::feature_flags::gDefaultWCMajority.isEnabled(serverGlobalParams.featureCompatibility); - if (isDefaultWCMajorityFeatureFlagEnabled) { - rwc.setDefaultWriteConcernSource(DefaultWriteConcernSourceEnum::kImplicit); - } if (rc && !rc->isEmpty()) { checkSuitabilityAsDefault(*rc); @@ -123,9 +118,6 @@ RWConcernDefault ReadWriteConcernDefaults::generateNewCWRWCToBeSavedOnDisk( if (wc && !wc->usedDefault) { checkSuitabilityAsDefault(*wc); rwc.setDefaultWriteConcern(wc); - if (isDefaultWCMajorityFeatureFlagEnabled) { - rwc.setDefaultWriteConcernSource(DefaultWriteConcernSourceEnum::kGlobal); - } } auto* const serviceContext = opCtx->getServiceContext(); @@ -139,10 +131,6 @@ RWConcernDefault ReadWriteConcernDefaults::generateNewCWRWCToBeSavedOnDisk( } if (!wc && current) { rwc.setDefaultWriteConcern(current->getDefaultWriteConcern()); - if (isDefaultWCMajorityFeatureFlagEnabled && current->getDefaultWriteConcern() && - !current->getDefaultWriteConcern().get().usedDefault) { - rwc.setDefaultWriteConcernSource(DefaultWriteConcernSourceEnum::kGlobal); - } } // If the setDefaultRWConcern command tries to unset the global default write concern when it // has already been set, throw an error. @@ -162,20 +150,11 @@ RWConcernDefault ReadWriteConcernDefaults::generateNewCWRWCToBeSavedOnDisk( } bool ReadWriteConcernDefaults::isCWWCSet(OperationContext* opCtx) { - // TODO (SERVER-57042): Call getDefault() instead and return writeConcernSource == KGlobal. - auto cached = _getDefaultCWRWCFromDisk(opCtx); - if (!cached) { - return false; - } - - auto wc = cached.get().getDefaultWriteConcern(); - if (!wc) { - return false; - } - - // CWWC should have "usedDefault" flag set to false, as this flag only set to true if the - // default constructed WC is used. - return !wc.get().usedDefault; + // This function is only valid if the gDefaultWCMajority feature flag is enabled. It only + // returns true if the gDefaultWCMajority feature flag is enabled, and the cluster-wide write + // concern has been set. It will return false otherwise. + auto rwcd = getDefault(opCtx); + return rwcd.getDefaultWriteConcernSource() == DefaultWriteConcernSourceEnum::kGlobal; } void ReadWriteConcernDefaults::observeDirectWriteToConfigSettings(OperationContext* opCtx, @@ -269,30 +248,32 @@ ReadWriteConcernDefaults::RWConcernDefaultAndTime ReadWriteConcernDefaults::getD } } - const bool isDefaultWCMajorityFeatureFlagEnabled = - serverGlobalParams.featureCompatibility.isVersionInitialized() && - repl::feature_flags::gDefaultWCMajority.isEnabled(serverGlobalParams.featureCompatibility); - if (isDefaultWCMajorityFeatureFlagEnabled && !cached.getDefaultWriteConcernSource()) { - cached.setDefaultWriteConcernSource(DefaultWriteConcernSourceEnum::kImplicit); - } - // The implicit default write concern will be w:1 if the feature compatibility version is not // yet initialized. Similarly, if the config hasn't yet been loaded on the node, the default // will be w:1, since we have no way of calculating the implicit default. This means that after // we have loaded our config, nodes could change their implicit write concern default. This is // safe since we shouldn't be accepting writes that need a write concern before we have loaded // our config. - if (!isDefaultWCMajorityFeatureFlagEnabled || !_implicitDefaultWriteConcernMajority) { - return cached; - } + const bool isDefaultWCMajorityFeatureFlagEnabled = + serverGlobalParams.featureCompatibility.isVersionInitialized() && + repl::feature_flags::gDefaultWCMajority.isEnabled(serverGlobalParams.featureCompatibility); - if ((!cached.getDefaultWriteConcern() || cached.getDefaultWriteConcern().get().usedDefault) && - _implicitDefaultWriteConcernMajority.get()) { - cached.setDefaultWriteConcern(WriteConcernOptions(WriteConcernOptions::kMajority, - WriteConcernOptions::SyncMode::UNSET, - WriteConcernOptions::kNoTimeout)); - if (isDefaultWCMajorityFeatureFlagEnabled) { + // This prevents overriding the default write concern and its source on mongos if it has + // already been set through the config server. + if (isDefaultWCMajorityFeatureFlagEnabled && !cached.getDefaultWriteConcernSource()) { + const bool isCWWCSet = + cached.getDefaultWriteConcern() && !cached.getDefaultWriteConcern().get().usedDefault; + if (isCWWCSet) { + cached.setDefaultWriteConcernSource(DefaultWriteConcernSourceEnum::kGlobal); + } else { cached.setDefaultWriteConcernSource(DefaultWriteConcernSourceEnum::kImplicit); + if (_implicitDefaultWriteConcernMajority && + _implicitDefaultWriteConcernMajority.get()) { + cached.setDefaultWriteConcern( + WriteConcernOptions(WriteConcernOptions::kMajority, + WriteConcernOptions::SyncMode::UNSET, + WriteConcernOptions::kNoTimeout)); + } } } diff --git a/src/mongo/db/read_write_concern_defaults.h b/src/mongo/db/read_write_concern_defaults.h index cf061d9122d..ccb0b9cdef0 100644 --- a/src/mongo/db/read_write_concern_defaults.h +++ b/src/mongo/db/read_write_concern_defaults.h @@ -135,7 +135,8 @@ public: const boost::optional<WriteConcern>& wc); /** - * Returns true if cluster-wide write concern is set and false otherwise. + * Returns true if cluster-wide write concern is set and the gDefaultWCMajority feature flag + * is enabled, and false otherwise. */ bool isCWWCSet(OperationContext* opCtx); diff --git a/src/mongo/db/read_write_concern_defaults_test.cpp b/src/mongo/db/read_write_concern_defaults_test.cpp index 1d28f29ab57..e4168dd107b 100644 --- a/src/mongo/db/read_write_concern_defaults_test.cpp +++ b/src/mongo/db/read_write_concern_defaults_test.cpp @@ -250,9 +250,31 @@ TEST_F(ReadWriteConcernDefaultsTest, TestGetDefaultWithUnsetCWRWCWithImplicitWCM ASSERT(defaults.getDefaultWriteConcernSource() == DefaultWriteConcernSourceEnum::kImplicit); } -TEST_F(ReadWriteConcernDefaultsTest, TestGetDefaultWithSetCWRWCWithImplicitWCW1) { +TEST_F(ReadWriteConcernDefaultsTest, TestGetDefaultWithCWRWCNotSetThenSetWithImplicitWCW1) { createDefaults(false /* isImplicitWCMajority */); + // _defaults.lookup() returning default constructed RWConcern not boost::none. + _lookupMock.setLookupCallReturnValue({}); + ASSERT(!isCWWCSet()); + auto oldDefaults = getDefault(); + if (_isDefaultRCLocalEnabled) { + ASSERT(oldDefaults.getDefaultReadConcern()->getLevel() == + repl::ReadConcernLevel::kLocalReadConcern); + ASSERT(oldDefaults.getDefaultReadConcernSource()); + ASSERT(oldDefaults.getDefaultReadConcernSource() == + DefaultReadConcernSourceEnum::kImplicit); + } else { + ASSERT(!oldDefaults.getDefaultReadConcernSource()); + } + ASSERT(!oldDefaults.getDefaultWriteConcern()); + ASSERT(!oldDefaults.getUpdateOpTime()); + ASSERT(!oldDefaults.getUpdateWallClockTime()); + ASSERT_GT(oldDefaults.localUpdateWallClockTime(), Date_t()); + if (_isDefaultWCMajorityEnabled) { + ASSERT(oldDefaults.getDefaultWriteConcernSource() == + DefaultWriteConcernSourceEnum::kImplicit); + } + RWConcernDefault newDefaults; newDefaults.setDefaultReadConcern( repl::ReadConcernArgs(repl::ReadConcernLevel::kLocalReadConcern)); @@ -263,11 +285,71 @@ TEST_F(ReadWriteConcernDefaultsTest, TestGetDefaultWithSetCWRWCWithImplicitWCW1) newDefaults.setDefaultWriteConcern(wc); newDefaults.setUpdateOpTime(Timestamp(1, 2)); newDefaults.setUpdateWallClockTime(Date_t::fromMillisSinceEpoch(1234)); + _lookupMock.setLookupCallReturnValue(std::move(newDefaults)); + + ReadWriteConcernDefaults::get(getServiceContext()).invalidate(); if (_isDefaultWCMajorityEnabled) { - newDefaults.setDefaultWriteConcernSource(DefaultWriteConcernSourceEnum::kGlobal); + ASSERT(isCWWCSet()); + } + auto defaults = getDefault(); + ASSERT(defaults.getDefaultReadConcern()->getLevel() == + repl::ReadConcernLevel::kLocalReadConcern); + if (_isDefaultRCLocalEnabled) { + ASSERT(defaults.getDefaultReadConcernSource()); + ASSERT(defaults.getDefaultReadConcernSource() == DefaultReadConcernSourceEnum::kGlobal); + } else { + ASSERT(!defaults.getDefaultReadConcernSource()); + } + ASSERT_EQ(4, defaults.getDefaultWriteConcern()->wNumNodes); + ASSERT_EQ(Timestamp(1, 2), *defaults.getUpdateOpTime()); + ASSERT_EQ(1234, defaults.getUpdateWallClockTime()->toMillisSinceEpoch()); + ASSERT_GT(defaults.localUpdateWallClockTime(), Date_t()); + if (_isDefaultWCMajorityEnabled) { + ASSERT(defaults.getDefaultWriteConcernSource()); + ASSERT(defaults.getDefaultWriteConcernSource() == DefaultWriteConcernSourceEnum::kGlobal); } +} + +TEST_F(ReadWriteConcernDefaultsTest, TestGetDefaultWithCWRWCNotSetThenSetWithImplicitWCMajority) { + if (!_isDefaultWCMajorityEnabled) { + return; + } + + createDefaults(true /* isImplicitWCMajority */); + + // _defaults.lookup() returning default constructed RWConcern not boost::none. + _lookupMock.setLookupCallReturnValue({}); + ASSERT(!isCWWCSet()); + auto oldDefaults = getDefault(); + if (_isDefaultRCLocalEnabled) { + ASSERT(oldDefaults.getDefaultReadConcern()->getLevel() == + repl::ReadConcernLevel::kLocalReadConcern); + ASSERT(oldDefaults.getDefaultReadConcernSource()); + ASSERT(oldDefaults.getDefaultReadConcernSource() == + DefaultReadConcernSourceEnum::kImplicit); + } else { + ASSERT(!oldDefaults.getDefaultReadConcernSource()); + } + ASSERT(oldDefaults.getDefaultWriteConcern()); + ASSERT_EQ(WriteConcernOptions::kMajority, oldDefaults.getDefaultWriteConcern().get().wMode); + ASSERT(!oldDefaults.getUpdateOpTime()); + ASSERT(!oldDefaults.getUpdateWallClockTime()); + ASSERT_GT(oldDefaults.localUpdateWallClockTime(), Date_t()); + ASSERT(oldDefaults.getDefaultWriteConcernSource() == DefaultWriteConcernSourceEnum::kImplicit); + + RWConcernDefault newDefaults; + newDefaults.setDefaultReadConcern( + repl::ReadConcernArgs(repl::ReadConcernLevel::kLocalReadConcern)); + WriteConcernOptions wc; + wc.wNumNodes = 4; + wc.usedDefault = false; + wc.usedDefaultW = false; + newDefaults.setDefaultWriteConcern(wc); + newDefaults.setUpdateOpTime(Timestamp(1, 2)); + newDefaults.setUpdateWallClockTime(Date_t::fromMillisSinceEpoch(1234)); _lookupMock.setLookupCallReturnValue(std::move(newDefaults)); + ReadWriteConcernDefaults::get(getServiceContext()).invalidate(); ASSERT(isCWWCSet()); auto defaults = getDefault(); ASSERT(defaults.getDefaultReadConcern()->getLevel() == @@ -283,6 +365,41 @@ TEST_F(ReadWriteConcernDefaultsTest, TestGetDefaultWithSetCWRWCWithImplicitWCW1) ASSERT_EQ(Timestamp(1, 2), *defaults.getUpdateOpTime()); ASSERT_EQ(1234, defaults.getUpdateWallClockTime()->toMillisSinceEpoch()); ASSERT_GT(defaults.localUpdateWallClockTime(), Date_t()); + ASSERT(defaults.getDefaultWriteConcernSource()); + ASSERT(defaults.getDefaultWriteConcernSource() == DefaultWriteConcernSourceEnum::kGlobal); +} + +TEST_F(ReadWriteConcernDefaultsTest, TestGetDefaultWithSetCWRWCWithImplicitWCW1) { + createDefaults(false /* isImplicitWCMajority */); + + RWConcernDefault newDefaults; + newDefaults.setDefaultReadConcern( + repl::ReadConcernArgs(repl::ReadConcernLevel::kLocalReadConcern)); + WriteConcernOptions wc; + wc.wNumNodes = 4; + wc.usedDefault = false; + wc.usedDefaultW = false; + newDefaults.setDefaultWriteConcern(wc); + newDefaults.setUpdateOpTime(Timestamp(1, 2)); + newDefaults.setUpdateWallClockTime(Date_t::fromMillisSinceEpoch(1234)); + _lookupMock.setLookupCallReturnValue(std::move(newDefaults)); + + if (_isDefaultWCMajorityEnabled) { + ASSERT(isCWWCSet()); + } + auto defaults = getDefault(); + ASSERT(defaults.getDefaultReadConcern()->getLevel() == + repl::ReadConcernLevel::kLocalReadConcern); + if (_isDefaultRCLocalEnabled) { + ASSERT(defaults.getDefaultReadConcernSource()); + ASSERT(defaults.getDefaultReadConcernSource() == DefaultReadConcernSourceEnum::kGlobal); + } else { + ASSERT(!defaults.getDefaultReadConcernSource()); + } + ASSERT_EQ(4, defaults.getDefaultWriteConcern()->wNumNodes); + ASSERT_EQ(Timestamp(1, 2), *defaults.getUpdateOpTime()); + ASSERT_EQ(1234, defaults.getUpdateWallClockTime()->toMillisSinceEpoch()); + ASSERT_GT(defaults.localUpdateWallClockTime(), Date_t()); if (_isDefaultWCMajorityEnabled) { ASSERT(defaults.getDefaultWriteConcernSource() == DefaultWriteConcernSourceEnum::kGlobal); } @@ -305,9 +422,6 @@ TEST_F(ReadWriteConcernDefaultsTest, TestGetDefaultWithSetCWRWCWithImplicitWCMaj newDefaults.setDefaultWriteConcern(wc); newDefaults.setUpdateOpTime(Timestamp(1, 2)); newDefaults.setUpdateWallClockTime(Date_t::fromMillisSinceEpoch(1234)); - if (_isDefaultWCMajorityEnabled) { - newDefaults.setDefaultWriteConcernSource(DefaultWriteConcernSourceEnum::kGlobal); - } _lookupMock.setLookupCallReturnValue(std::move(newDefaults)); ASSERT(isCWWCSet()); @@ -323,9 +437,7 @@ TEST_F(ReadWriteConcernDefaultsTest, TestGetDefaultWithSetCWRWCWithImplicitWCMaj ASSERT_EQ(Timestamp(1, 2), *defaults.getUpdateOpTime()); ASSERT_EQ(1234, defaults.getUpdateWallClockTime()->toMillisSinceEpoch()); ASSERT_GT(defaults.localUpdateWallClockTime(), Date_t()); - if (_isDefaultWCMajorityEnabled) { - ASSERT(defaults.getDefaultWriteConcernSource() == DefaultWriteConcernSourceEnum::kGlobal); - } + ASSERT(defaults.getDefaultWriteConcernSource() == DefaultWriteConcernSourceEnum::kGlobal); } TEST_F(ReadWriteConcernDefaultsTest, TestGetDefaultWriteConcernSourceImplicitWithUsedDefaultWC) { @@ -339,7 +451,6 @@ TEST_F(ReadWriteConcernDefaultsTest, TestGetDefaultWriteConcernSourceImplicitWit newDefaults.setDefaultWriteConcern(WriteConcernOptions()); newDefaults.setUpdateOpTime(Timestamp(1, 2)); newDefaults.setUpdateWallClockTime(Date_t::fromMillisSinceEpoch(1234)); - newDefaults.setDefaultWriteConcernSource(DefaultWriteConcernSourceEnum::kGlobal); _lookupMock.setLookupCallReturnValue(std::move(newDefaults)); @@ -591,13 +702,12 @@ TEST_F(ReadWriteConcernDefaultsTest, TestInvalidate) { newDefaults2.setDefaultWriteConcern(wc); newDefaults2.setUpdateOpTime(Timestamp(3, 4)); newDefaults2.setUpdateWallClockTime(Date_t::fromMillisSinceEpoch(5678)); - if (_isDefaultWCMajorityEnabled) { - newDefaults2.setDefaultWriteConcernSource(DefaultWriteConcernSourceEnum::kGlobal); - } _lookupMock.setLookupCallReturnValue(std::move(newDefaults2)); ReadWriteConcernDefaults::get(getServiceContext()).invalidate(); - ASSERT(isCWWCSet()); + if (_isDefaultWCMajorityEnabled) { + ASSERT(isCWWCSet()); + } auto defaults2 = getDefault(); ASSERT(defaults2.getDefaultReadConcern()->getLevel() == repl::ReadConcernLevel::kAvailableReadConcern); @@ -750,10 +860,8 @@ protected: ASSERT_EQ(4, defaults.getDefaultWriteConcern()->wNumNodes); ASSERT(defaults.getUpdateOpTime()); ASSERT(defaults.getUpdateWallClockTime()); - if (_isDefaultWCMajorityEnabled) { - ASSERT(defaults.getDefaultWriteConcernSource() == - DefaultWriteConcernSourceEnum::kGlobal); - } + // Default write concern source is not saved on disk. + ASSERT(!defaults.getDefaultWriteConcernSource()); _lookupMock.setLookupCallReturnValue(std::move(defaults)); auto oldDefaults = _rwcd.getDefault(operationContext()); @@ -859,15 +967,15 @@ TEST_F(ReadWriteConcernDefaultsTestWithClusterTime, ASSERT_EQ(5, defaults.getDefaultWriteConcern()->wNumNodes); ASSERT_LT(*oldDefaults.getUpdateOpTime(), *defaults.getUpdateOpTime()); ASSERT_LT(*oldDefaults.getUpdateWallClockTime(), *defaults.getUpdateWallClockTime()); - if (_isDefaultWCMajorityEnabled) { - ASSERT(defaults.getDefaultWriteConcernSource() == DefaultWriteConcernSourceEnum::kGlobal); - } + // Default write concern source is not saved on disk. + ASSERT(!defaults.getDefaultWriteConcernSource()); _lookupMock.setLookupCallReturnValue(std::move(defaults)); _rwcd.refreshIfNecessary(operationContext()); auto newDefaults = _rwcd.getDefault(operationContext()); ASSERT_LT(oldDefaults.localUpdateWallClockTime(), newDefaults.localUpdateWallClockTime()); if (_isDefaultWCMajorityEnabled) { + // Default write concern source is calculated through 'getDefault'. ASSERT(newDefaults.getDefaultWriteConcernSource() == DefaultWriteConcernSourceEnum::kGlobal); } @@ -888,15 +996,15 @@ TEST_F(ReadWriteConcernDefaultsTestWithClusterTime, defaults.getDefaultWriteConcern()->wNumNodes); ASSERT_LT(*oldDefaults.getUpdateOpTime(), *defaults.getUpdateOpTime()); ASSERT_LT(*oldDefaults.getUpdateWallClockTime(), *defaults.getUpdateWallClockTime()); - if (_isDefaultWCMajorityEnabled) { - ASSERT(defaults.getDefaultWriteConcernSource() == DefaultWriteConcernSourceEnum::kGlobal); - } + // Default write concern source is not saved on disk. + ASSERT(!defaults.getDefaultWriteConcernSource()); _lookupMock.setLookupCallReturnValue(std::move(defaults)); _rwcd.refreshIfNecessary(operationContext()); auto newDefaults = _rwcd.getDefault(operationContext()); ASSERT_LT(oldDefaults.localUpdateWallClockTime(), newDefaults.localUpdateWallClockTime()); if (_isDefaultWCMajorityEnabled) { + // Default write concern source is calculated through 'getDefault'. ASSERT(newDefaults.getDefaultWriteConcernSource() == DefaultWriteConcernSourceEnum::kGlobal); } @@ -911,14 +1019,14 @@ TEST_F(ReadWriteConcernDefaultsTestWithClusterTime, ASSERT(defaults.getDefaultReadConcern()->getLevel() == repl::ReadConcernLevel::kMajorityReadConcern); ASSERT(!defaults.getDefaultWriteConcern()); - if (_isDefaultWCMajorityEnabled) { - ASSERT(defaults.getDefaultWriteConcernSource() == DefaultWriteConcernSourceEnum::kImplicit); - } + // Default write concern source is not saved on disk. + ASSERT(!defaults.getDefaultWriteConcernSource()); _lookupMock.setLookupCallReturnValue(std::move(defaults)); _rwcd.refreshIfNecessary(operationContext()); auto newDefaults = _rwcd.getDefault(operationContext()); if (_isDefaultWCMajorityEnabled) { + // Default write concern source is calculated through 'getDefault'. ASSERT(newDefaults.getDefaultWriteConcernSource() == DefaultWriteConcernSourceEnum::kImplicit); } @@ -938,15 +1046,15 @@ TEST_F(ReadWriteConcernDefaultsTestWithClusterTime, ASSERT_EQ(5, defaults.getDefaultWriteConcern()->wNumNodes); ASSERT_LT(*oldDefaults.getUpdateOpTime(), *defaults.getUpdateOpTime()); ASSERT_LT(*oldDefaults.getUpdateWallClockTime(), *defaults.getUpdateWallClockTime()); - if (_isDefaultWCMajorityEnabled) { - ASSERT(defaults.getDefaultWriteConcernSource() == DefaultWriteConcernSourceEnum::kGlobal); - } + // Default write concern source is not saved on disk. + ASSERT(!defaults.getDefaultWriteConcernSource()); _lookupMock.setLookupCallReturnValue(std::move(defaults)); _rwcd.refreshIfNecessary(operationContext()); auto newDefaults = _rwcd.getDefault(operationContext()); ASSERT_LT(oldDefaults.localUpdateWallClockTime(), newDefaults.localUpdateWallClockTime()); if (_isDefaultWCMajorityEnabled) { + // Default write concern source is calculated through 'getDefault'. ASSERT(newDefaults.getDefaultWriteConcernSource() == DefaultWriteConcernSourceEnum::kGlobal); } @@ -961,15 +1069,14 @@ TEST_F(ReadWriteConcernDefaultsTestWithClusterTime, ASSERT(oldDefaults.getDefaultReadConcern()->getLevel() == repl::ReadConcernLevel::kMajorityReadConcern); ASSERT(!oldDefaults.getDefaultWriteConcern()); - if (_isDefaultWCMajorityEnabled) { - ASSERT(oldDefaults.getDefaultWriteConcernSource() == - DefaultWriteConcernSourceEnum::kImplicit); - } + // Default write concern source is not saved on disk. + ASSERT(!oldDefaults.getDefaultWriteConcernSource()); _lookupMock.setLookupCallReturnValue(std::move(oldDefaults)); _rwcd.refreshIfNecessary(operationContext()); auto newDefaults = _rwcd.getDefault(operationContext()); if (_isDefaultWCMajorityEnabled) { + // Default write concern source is calculated through 'getDefault'. ASSERT(newDefaults.getDefaultWriteConcernSource() == DefaultWriteConcernSourceEnum::kImplicit); } @@ -984,9 +1091,8 @@ TEST_F(ReadWriteConcernDefaultsTestWithClusterTime, ASSERT(newDefaults.getDefaultReadConcern()->getLevel() == defaults.getDefaultReadConcern()->getLevel()); ASSERT_EQ(5, defaults.getDefaultWriteConcern()->wNumNodes); - if (_isDefaultWCMajorityEnabled) { - ASSERT(defaults.getDefaultWriteConcernSource() == DefaultWriteConcernSourceEnum::kGlobal); - } + // Default write concern source is not saved on disk. + ASSERT(!defaults.getDefaultWriteConcernSource()); _lookupMock.setLookupCallReturnValue(std::move(defaults)); _rwcd.refreshIfNecessary(operationContext()); @@ -994,6 +1100,7 @@ TEST_F(ReadWriteConcernDefaultsTestWithClusterTime, ASSERT(newDefaults.getDefaultWriteConcern()); ASSERT_EQ(5, newDefaults.getDefaultWriteConcern()->wNumNodes); if (_isDefaultWCMajorityEnabled) { + // Default write concern source is calculated through 'getDefault'. ASSERT(newDefaults.getDefaultWriteConcernSource() == DefaultWriteConcernSourceEnum::kGlobal); } @@ -1013,15 +1120,15 @@ TEST_F(ReadWriteConcernDefaultsTestWithClusterTime, defaults.getDefaultWriteConcern()->wNumNodes); ASSERT_LT(*oldDefaults.getUpdateOpTime(), *defaults.getUpdateOpTime()); ASSERT_LT(*oldDefaults.getUpdateWallClockTime(), *defaults.getUpdateWallClockTime()); - if (_isDefaultWCMajorityEnabled) { - ASSERT(defaults.getDefaultWriteConcernSource() == DefaultWriteConcernSourceEnum::kGlobal); - } + // Default write concern source is not saved on disk. + ASSERT(!defaults.getDefaultWriteConcernSource()); _lookupMock.setLookupCallReturnValue(std::move(defaults)); _rwcd.refreshIfNecessary(operationContext()); auto newDefaults = _rwcd.getDefault(operationContext()); ASSERT_LT(oldDefaults.localUpdateWallClockTime(), newDefaults.localUpdateWallClockTime()); if (_isDefaultWCMajorityEnabled) { + // Default write concern source is calculated through 'getDefault'. ASSERT(newDefaults.getDefaultWriteConcernSource() == DefaultWriteConcernSourceEnum::kGlobal); } @@ -1073,14 +1180,14 @@ TEST_F(ReadWriteConcernDefaultsTestWithClusterTime, operationContext(), boost::none, WriteConcernOptions()); ASSERT(!defaults.getDefaultReadConcern()); ASSERT(!defaults.getDefaultWriteConcern()); - if (_isDefaultWCMajorityEnabled) { - ASSERT(defaults.getDefaultWriteConcernSource() == DefaultWriteConcernSourceEnum::kImplicit); - } + // Default write concern source is not saved on disk. + ASSERT(!defaults.getDefaultWriteConcernSource()); _lookupMock.setLookupCallReturnValue(std::move(defaults)); _rwcd.refreshIfNecessary(operationContext()); auto newDefaults = _rwcd.getDefault(operationContext()); if (_isDefaultWCMajorityEnabled) { + // Default write concern source is calculated through 'getDefault'. ASSERT(newDefaults.getDefaultWriteConcernSource() == DefaultWriteConcernSourceEnum::kImplicit); } @@ -1140,15 +1247,15 @@ TEST_F(ReadWriteConcernDefaultsTestWithClusterTime, ASSERT(WriteConcernOptions::SyncMode::JOURNAL == defaults.getDefaultWriteConcern()->syncMode); ASSERT_LT(*oldDefaults.getUpdateOpTime(), *defaults.getUpdateOpTime()); ASSERT_LT(*oldDefaults.getUpdateWallClockTime(), *defaults.getUpdateWallClockTime()); - if (_isDefaultWCMajorityEnabled) { - ASSERT(defaults.getDefaultWriteConcernSource() == DefaultWriteConcernSourceEnum::kGlobal); - } + // Default write concern source is not saved on disk. + ASSERT(!defaults.getDefaultWriteConcernSource()); _lookupMock.setLookupCallReturnValue(std::move(defaults)); _rwcd.refreshIfNecessary(operationContext()); auto newDefaults = _rwcd.getDefault(operationContext()); ASSERT_LT(oldDefaults.localUpdateWallClockTime(), newDefaults.localUpdateWallClockTime()); if (_isDefaultWCMajorityEnabled) { + // Default write concern source is calculated through 'getDefault'. ASSERT(newDefaults.getDefaultWriteConcernSource() == DefaultWriteConcernSourceEnum::kGlobal); } @@ -1169,15 +1276,15 @@ TEST_F(ReadWriteConcernDefaultsTestWithClusterTime, ASSERT(WriteConcernOptions::SyncMode::UNSET == defaults.getDefaultWriteConcern()->syncMode); ASSERT_LT(*oldDefaults.getUpdateOpTime(), *defaults.getUpdateOpTime()); ASSERT_LT(*oldDefaults.getUpdateWallClockTime(), *defaults.getUpdateWallClockTime()); - if (_isDefaultWCMajorityEnabled) { - ASSERT(defaults.getDefaultWriteConcernSource() == DefaultWriteConcernSourceEnum::kGlobal); - } + // Default write concern source is not saved on disk. + ASSERT(!defaults.getDefaultWriteConcernSource()); _lookupMock.setLookupCallReturnValue(std::move(defaults)); _rwcd.refreshIfNecessary(operationContext()); auto newDefaults = _rwcd.getDefault(operationContext()); ASSERT_LT(oldDefaults.localUpdateWallClockTime(), newDefaults.localUpdateWallClockTime()); if (_isDefaultWCMajorityEnabled) { + // Default write concern source is calculated through 'getDefault'. ASSERT(newDefaults.getDefaultWriteConcernSource() == DefaultWriteConcernSourceEnum::kGlobal); } |