0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 09:32:32 +01:00

SERVER-45097 Permit default write concern without w field

This commit is contained in:
Kevin Pulo 2020-01-08 13:14:35 +00:00 committed by evergreen
parent accf5bb6e6
commit 7b9cc569b3
2 changed files with 45 additions and 1 deletions

View File

@ -127,7 +127,7 @@ RWConcernDefault ReadWriteConcernDefaults::generateNewConcerns(
checkSuitabilityAsDefault(*rc);
rwc.setDefaultReadConcern(rc);
}
if (wc && !wc->usedDefaultW) {
if (wc && !wc->usedDefault) {
checkSuitabilityAsDefault(*wc);
rwc.setDefaultWriteConcern(wc);
}

View File

@ -436,5 +436,49 @@ TEST_F(ReadWriteConcernDefaultsTestWithClusterTime,
ASSERT_LT(*oldDefaults.getLocalSetTime(), *newDefaults.getLocalSetTime());
}
TEST_F(ReadWriteConcernDefaultsTestWithClusterTime,
TestGenerateNewConcernsValidSetWriteConcernWithOnlyJ) {
auto oldDefaults = setupOldDefaults();
auto defaults =
_rwcd.generateNewConcerns(operationContext(),
boost::none,
uassertStatusOK(WriteConcernOptions::parse(BSON("j" << true))));
ASSERT(oldDefaults.getDefaultReadConcern()->getLevel() ==
defaults.getDefaultReadConcern()->getLevel());
ASSERT_EQ(1, defaults.getDefaultWriteConcern()->wNumNodes);
ASSERT_EQ(0, defaults.getDefaultWriteConcern()->wTimeout);
ASSERT(WriteConcernOptions::SyncMode::JOURNAL == defaults.getDefaultWriteConcern()->syncMode);
ASSERT_LT(*oldDefaults.getEpoch(), *defaults.getEpoch());
ASSERT_LT(*oldDefaults.getSetTime(), *defaults.getSetTime());
ASSERT(!defaults.getLocalSetTime());
_lookupMock.setLookupCallReturnValue(std::move(defaults));
_rwcd.refreshIfNecessary(operationContext());
auto newDefaults = _rwcd.getDefault(operationContext());
ASSERT_LT(*oldDefaults.getLocalSetTime(), *newDefaults.getLocalSetTime());
}
TEST_F(ReadWriteConcernDefaultsTestWithClusterTime,
TestGenerateNewConcernsValidSetWriteConcernWithOnlyWtimeout) {
auto oldDefaults = setupOldDefaults();
auto defaults = _rwcd.generateNewConcerns(
operationContext(),
boost::none,
uassertStatusOK(WriteConcernOptions::parse(BSON("wtimeout" << 12345))));
ASSERT(oldDefaults.getDefaultReadConcern()->getLevel() ==
defaults.getDefaultReadConcern()->getLevel());
ASSERT_EQ(1, defaults.getDefaultWriteConcern()->wNumNodes);
ASSERT_EQ(12345, defaults.getDefaultWriteConcern()->wTimeout);
ASSERT(WriteConcernOptions::SyncMode::UNSET == defaults.getDefaultWriteConcern()->syncMode);
ASSERT_LT(*oldDefaults.getEpoch(), *defaults.getEpoch());
ASSERT_LT(*oldDefaults.getSetTime(), *defaults.getSetTime());
ASSERT(!defaults.getLocalSetTime());
_lookupMock.setLookupCallReturnValue(std::move(defaults));
_rwcd.refreshIfNecessary(operationContext());
auto newDefaults = _rwcd.getDefault(operationContext());
ASSERT_LT(*oldDefaults.getLocalSetTime(), *newDefaults.getLocalSetTime());
}
} // namespace
} // namespace mongo