summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierlauro Sciarelli <pierlauro.sciarelli@mongodb.com>2020-07-16 23:19:53 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-07-16 23:44:21 +0000
commitd760da5e25d5de81fc144e818fb612661adb4728 (patch)
tree33eb43f8c0df473ff7c7734dde4ce9e17cd3bc2d
parent550a9ee713078ec583621a0d6c368a6bc6ce43d2 (diff)
downloadmongo-d760da5e25d5de81fc144e818fb612661adb4728.tar.gz
SERVER-48717 Implement the persist/recover functionalities of the VectorClock [last additional changes]
-rw-r--r--src/mongo/db/vector_clock.cpp7
-rw-r--r--src/mongo/db/vector_clock.h14
-rw-r--r--src/mongo/db/vector_clock_mongod.cpp6
-rw-r--r--src/mongo/db/vector_clock_mongod_test.cpp8
4 files changed, 19 insertions, 16 deletions
diff --git a/src/mongo/db/vector_clock.cpp b/src/mongo/db/vector_clock.cpp
index 2168c852c33..c8f730cf39f 100644
--- a/src/mongo/db/vector_clock.cpp
+++ b/src/mongo/db/vector_clock.cpp
@@ -36,6 +36,8 @@
#include "mongo/db/auth/authorization_session.h"
#include "mongo/db/logical_clock_gen.h"
#include "mongo/db/logical_time_validator.h"
+#include "mongo/db/vector_clock_document_gen.h"
+#include "mongo/util/static_immortal.h"
namespace mongo {
@@ -404,4 +406,9 @@ void VectorClock::advanceTime_forTest(Component component, LogicalTime newTime)
_advanceTime(std::move(newTimeArray));
}
+const Query& VectorClock::stateQuery() {
+ static StaticImmortal q{QUERY(VectorClockDocument::k_idFieldName << kDocIdKey)};
+ return *q;
+}
+
} // namespace mongo
diff --git a/src/mongo/db/vector_clock.h b/src/mongo/db/vector_clock.h
index 750f3a9133c..d3e40190b22 100644
--- a/src/mongo/db/vector_clock.h
+++ b/src/mongo/db/vector_clock.h
@@ -35,10 +35,9 @@
#include "mongo/db/logical_time.h"
#include "mongo/db/operation_context.h"
#include "mongo/db/service_context.h"
-#include "mongo/db/vector_clock_document_gen.h"
#include "mongo/platform/mutex.h"
#include "mongo/transport/session.h"
-#include "mongo/util/static_immortal.h"
+
namespace mongo {
@@ -137,8 +136,8 @@ public:
/*
* Methods to save/recover the the vector clock to/from persistent storage. Subclasses are
- * eventually expected to override those method to provide persistence mechanisms. Default
- * implementations result in a NOP.
+ * eventually expected to override these methods to provide persistence mechanisms. Default
+ * implementations do nothing.
*/
virtual SharedSemiFuture<void> persist(OperationContext* opCtx) {
return SharedSemiFuture<void>();
@@ -147,16 +146,13 @@ public:
return SharedSemiFuture<void>();
}
virtual void waitForInMemoryVectorClockToBePersisted(OperationContext* opCtx) {}
- virtual void waitForVectorClockToBeRecovered(OperationContext* opCtx){};
+ virtual void waitForVectorClockToBeRecovered(OperationContext* opCtx) {}
void resetVectorClock_forTest();
void advanceTime_forTest(Component component, LogicalTime newTime);
// Query to use when reading/writing the vector clock state document.
- static const Query& kStateQuery() {
- static StaticImmortal<Query> q{QUERY(VectorClockDocument::k_idFieldName << kDocIdKey)};
- return *q;
- }
+ static const Query& stateQuery();
// The _id value of the vector clock singleton document.
static constexpr StringData kDocIdKey = "vectorClockState"_sd;
diff --git a/src/mongo/db/vector_clock_mongod.cpp b/src/mongo/db/vector_clock_mongod.cpp
index c0c1caea299..f517dc0d945 100644
--- a/src/mongo/db/vector_clock_mongod.cpp
+++ b/src/mongo/db/vector_clock_mongod.cpp
@@ -239,7 +239,7 @@ private:
vcd.setVectorClock(obj);
store.update(opCtx,
- VectorClock::kStateQuery(),
+ VectorClock::stateQuery(),
vcd.toBSON(),
WriteConcerns::kMajorityWriteConcern,
true);
@@ -259,14 +259,14 @@ private:
NamespaceString nss(NamespaceString::kVectorClockNamespace);
PersistentTaskStore<VectorClockDocument> store(nss);
- int nDocuments = store.count(opCtx, VectorClock::kStateQuery());
+ int nDocuments = store.count(opCtx, VectorClock::stateQuery());
if (nDocuments == 0) {
LOGV2_DEBUG(4924403, 2, "No VectorClockDocument to recover");
return;
}
fassert(4924404, nDocuments == 1);
- store.forEach(opCtx, VectorClock::kStateQuery(), [&](const VectorClockDocument& vcd) {
+ store.forEach(opCtx, VectorClock::stateQuery(), [&](const VectorClockDocument& vcd) {
BSONObj obj = vcd.getVectorClock();
LogicalTimeArray newTime;
diff --git a/src/mongo/db/vector_clock_mongod_test.cpp b/src/mongo/db/vector_clock_mongod_test.cpp
index 6e07080d591..4e9d5ec63d7 100644
--- a/src/mongo/db/vector_clock_mongod_test.cpp
+++ b/src/mongo/db/vector_clock_mongod_test.cpp
@@ -295,17 +295,17 @@ TEST_F(VectorClockMongoDTest, PersistVectorClockDocument) {
PersistentTaskStore<VectorClockDocument> store(nss);
// Check that no vectorClockState document is present
- ASSERT_EQUALS(store.count(opCtx, VectorClock::kStateQuery()), 0);
+ ASSERT_EQUALS(store.count(opCtx, VectorClock::stateQuery()), 0);
// Persist and check that the vectorClockState document has been persisted
auto future = vc->persist(opCtx);
future.get();
- ASSERT_EQUALS(store.count(opCtx, VectorClock::kStateQuery()), 1);
+ ASSERT_EQUALS(store.count(opCtx, VectorClock::stateQuery()), 1);
// Check that the vectorClockState document is still one after more persist calls
future = vc->persist(opCtx);
vc->waitForInMemoryVectorClockToBePersisted(opCtx);
- ASSERT_EQUALS(store.count(opCtx, VectorClock::kStateQuery()), 1);
+ ASSERT_EQUALS(store.count(opCtx, VectorClock::stateQuery()), 1);
}
TEST_F(VectorClockMongoDTest, RecoverVectorClockDocument) {
@@ -351,7 +351,7 @@ TEST_F(VectorClockMongoDTest, RecoverNotExistingVectorClockDocument) {
PersistentTaskStore<VectorClockDocument> store(nss);
// Check that no recovery document is stored and call recovery
- int nDocuments = store.count(opCtx, VectorClock::kStateQuery());
+ int nDocuments = store.count(opCtx, VectorClock::stateQuery());
ASSERT_EQUALS(nDocuments, 0);
auto future = vc->recover(opCtx);