summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJack Mulrow <jack.mulrow@mongodb.com>2020-01-08 15:35:46 +0000
committerevergreen <evergreen@mongodb.com>2020-01-08 15:35:46 +0000
commite3dd9e80e38f3528bc50c3e1115c46a0687885fa (patch)
treef8a9a724ed170e45ecf1f0cc73c086ad82c45c0e /src
parentd401d80a2c89d89db26750956cb3b3261e595a34 (diff)
downloadmongo-e3dd9e80e38f3528bc50c3e1115c46a0687885fa.tar.gz
SERVER-45282 Unify how mongos and mongod default RWC caches handle deleted defaults document
Diffstat (limited to 'src')
-rw-r--r--src/mongo/db/read_write_concern_defaults.cpp7
-rw-r--r--src/mongo/db/read_write_concern_defaults.h2
-rw-r--r--src/mongo/db/read_write_concern_defaults_test.cpp24
3 files changed, 29 insertions, 4 deletions
diff --git a/src/mongo/db/read_write_concern_defaults.cpp b/src/mongo/db/read_write_concern_defaults.cpp
index 4b77b993b1b..d43a2d2258d 100644
--- a/src/mongo/db/read_write_concern_defaults.cpp
+++ b/src/mongo/db/read_write_concern_defaults.cpp
@@ -54,7 +54,7 @@ public:
const boost::optional<BSONObj>& newDefaultsDoc)
: _service(service), _rwcDefaults(rwcDefaults) {
// Note this will throw if the document can't be parsed. In the case of a delete, there will
- // be no new defaults document and the RWConcern will be default constructed, which matches
+ // be no new defaults document and the RWConcern will be default constructed, which matches
// the behavior when lookup discovers a non-existent defaults document.
_rwc = newDefaultsDoc
? RWConcernDefault::parse(IDLParserErrorContext("RWDefaultsWriteObserver"),
@@ -173,9 +173,10 @@ void ReadWriteConcernDefaults::refreshIfNecessary(OperationContext* opCtx) {
return;
}
auto currentDefaultsHandle = _defaults.acquire(opCtx, Type::kReadWriteConcernEntry);
- if (!currentDefaultsHandle ||
+ if (!currentDefaultsHandle || !possibleNewDefaults->getEpoch() ||
(possibleNewDefaults->getEpoch() > (**currentDefaultsHandle)->getEpoch())) {
- // Use the new defaults if they have a higher epoch, or if there are currently no defaults.
+ // Use the new defaults if they have a higher epoch, if there are no defaults in the cache,
+ // or if the found defaults have no epoch, meaning there are no defaults in config.settings.
log() << "refreshed RWC defaults to " << possibleNewDefaults->toBSON();
setDefault(std::move(*possibleNewDefaults));
}
diff --git a/src/mongo/db/read_write_concern_defaults.h b/src/mongo/db/read_write_concern_defaults.h
index 17b971a14b1..7c0b3f520d7 100644
--- a/src/mongo/db/read_write_concern_defaults.h
+++ b/src/mongo/db/read_write_concern_defaults.h
@@ -114,7 +114,7 @@ public:
/**
* Manually looks up the latest defaults, and if their epoch is more recent than the cached
- * defaults, then update the cache with the new defaults.
+ * defaults or indicates there are no defaults, then update the cache with the new defaults.
*/
void refreshIfNecessary(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 56e98f0cd6c..13532a03325 100644
--- a/src/mongo/db/read_write_concern_defaults_test.cpp
+++ b/src/mongo/db/read_write_concern_defaults_test.cpp
@@ -480,5 +480,29 @@ TEST_F(ReadWriteConcernDefaultsTestWithClusterTime,
ASSERT_LT(*oldDefaults.getLocalSetTime(), *newDefaults.getLocalSetTime());
}
+TEST_F(ReadWriteConcernDefaultsTestWithClusterTime, TestRefreshDefaultsWithDeletedDefaults) {
+ RWConcernDefault origDefaults;
+ origDefaults.setEpoch(Timestamp(10, 20));
+ origDefaults.setSetTime(Date_t::fromMillisSinceEpoch(1234));
+ _lookupMock.setLookupCallReturnValue(std::move(origDefaults));
+
+ auto origCachedDefaults = _rwcd.getDefault(operationContext());
+ ASSERT_EQ(Timestamp(10, 20), *origCachedDefaults.getEpoch());
+ ASSERT_EQ(Date_t::fromMillisSinceEpoch(1234), *origCachedDefaults.getSetTime());
+
+ getClock()->reserveTicks(1);
+ getMockClockSource()->advance(Milliseconds(1));
+
+ _lookupMock.setLookupCallReturnValue(RWConcernDefault());
+
+ _rwcd.refreshIfNecessary(operationContext());
+
+ // The cache should now contain default constructed defaults.
+ auto newCachedDefaults = _rwcd.getDefault(operationContext());
+ ASSERT(!newCachedDefaults.getEpoch());
+ ASSERT(!newCachedDefaults.getSetTime());
+ ASSERT_LT(*origCachedDefaults.getLocalSetTime(), *newCachedDefaults.getLocalSetTime());
+}
+
} // namespace
} // namespace mongo