diff options
author | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2020-08-09 07:14:29 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-08-11 09:45:26 +0000 |
commit | 0514a0d5286e9c988cbb0fa127220d11932b5883 (patch) | |
tree | 148a9a8ae3780bad2fdf86a6e1951bea0a2412ae | |
parent | 354959497599265c78f520a6a80fb378ed6932bd (diff) | |
download | mongo-0514a0d5286e9c988cbb0fa127220d11932b5883.tar.gz |
SERVER-49921 Pull the `_vectorClockPersist` command out of the 'vector_clock_mongod' library
It should be in the same library where the commands are included, rather
than together with the VectorClock implementation.
-rw-r--r-- | src/mongo/db/SConscript | 7 | ||||
-rw-r--r-- | src/mongo/db/s/SConscript | 7 | ||||
-rw-r--r-- | src/mongo/db/s/vector_clock_persist_command.cpp (renamed from src/mongo/db/vector_clock_persist_command.cpp) | 13 | ||||
-rw-r--r-- | src/mongo/db/vector_clock.cpp | 1 | ||||
-rw-r--r-- | src/mongo/db/vector_clock.h | 17 | ||||
-rw-r--r-- | src/mongo/db/vector_clock_mongod.cpp | 21 | ||||
-rw-r--r-- | src/mongo/db/vector_clock_mutable.cpp | 1 | ||||
-rw-r--r-- | src/mongo/db/vector_clock_mutable.h | 15 | ||||
-rw-r--r-- | src/mongo/db/vector_clock_trivial.cpp | 19 | ||||
-rw-r--r-- | src/mongo/s/vector_clock_mongos.cpp | 15 |
10 files changed, 57 insertions, 59 deletions
diff --git a/src/mongo/db/SConscript b/src/mongo/db/SConscript index 95446be6a41..341cbef3c3d 100644 --- a/src/mongo/db/SConscript +++ b/src/mongo/db/SConscript @@ -1630,19 +1630,18 @@ env.Library( env.Library( target='vector_clock_mongod', source=[ - 'vector_clock_persist_command.cpp', 'vector_clock_mongod.cpp', ], LIBDEPS=[ 'vector_clock_mutable', ], LIBDEPS_PRIVATE=[ + '$BUILD_DIR/mongo/db/s/sharding_api_d', + '$BUILD_DIR/mongo/s/grid', 'dbdirectclient', - 'rw_concern_d', 'repl/replica_set_aware_service', + 'rw_concern_d', 'server_options_core', - '$BUILD_DIR/mongo/db/s/sharding_api_d', - '$BUILD_DIR/mongo/s/grid', ], ) diff --git a/src/mongo/db/s/SConscript b/src/mongo/db/s/SConscript index 61309e39100..36c623c8c4b 100644 --- a/src/mongo/db/s/SConscript +++ b/src/mongo/db/s/SConscript @@ -159,7 +159,7 @@ env.Library( '$BUILD_DIR/mongo/db/dbdirectclient', '$BUILD_DIR/mongo/db/repl/wait_for_majority_service', '$BUILD_DIR/mongo/db/rw_concern_d', - '$BUILD_DIR/mongo/db/vector_clock_mutable', + '$BUILD_DIR/mongo/db/vector_clock_mongod', '$BUILD_DIR/mongo/executor/task_executor_pool', '$BUILD_DIR/mongo/s/grid', 'sharding_api_d', @@ -249,11 +249,11 @@ env.Library( ], LIBDEPS_PRIVATE=[ '$BUILD_DIR/mongo/db/commands/mongod_fcv', + '$BUILD_DIR/mongo/db/pipeline/sharded_agg_helpers', '$BUILD_DIR/mongo/db/snapshot_window_options', - '$BUILD_DIR/mongo/db/vector_clock_mutable', + '$BUILD_DIR/mongo/db/vector_clock_mongod', '$BUILD_DIR/mongo/s/catalog/sharding_catalog_client_impl', '$BUILD_DIR/mongo/util/options_parser/options_parser', - '$BUILD_DIR/mongo/db/pipeline/sharded_agg_helpers', ], ) @@ -304,6 +304,7 @@ env.Library( 'split_vector_command.cpp', 'txn_two_phase_commit_cmds.cpp', 'unset_sharding_command.cpp', + 'vector_clock_persist_command.cpp', 'wait_for_ongoing_chunk_splits_command.cpp', ], LIBDEPS_PRIVATE=[ diff --git a/src/mongo/db/vector_clock_persist_command.cpp b/src/mongo/db/s/vector_clock_persist_command.cpp index 71cf0248ff8..e32523ed40c 100644 --- a/src/mongo/db/vector_clock_persist_command.cpp +++ b/src/mongo/db/s/vector_clock_persist_command.cpp @@ -31,10 +31,7 @@ #include "mongo/platform/basic.h" -#include <set> - #include "mongo/db/commands.h" -#include "mongo/db/repl/replication_coordinator.h" #include "mongo/db/vector_clock.h" namespace mongo { @@ -51,7 +48,7 @@ public: return AllowedOnSecondary::kNever; } - virtual bool supportsWriteConcern(const BSONObj& cmd) const override { + bool supportsWriteConcern(const BSONObj& cmd) const override { return true; } @@ -63,11 +60,9 @@ public: bool run(OperationContext* opCtx, const std::string& dbname_unused, const BSONObj& cmdObj, - BSONObjBuilder& result) { - auto sc = opCtx->getServiceContext(); - auto vc = VectorClock::get(sc); - - vc->persist().get(opCtx); + BSONObjBuilder& result) override { + auto* const vectorClock = VectorClock::get(opCtx->getServiceContext()); + vectorClock->persist().get(opCtx); return true; } diff --git a/src/mongo/db/vector_clock.cpp b/src/mongo/db/vector_clock.cpp index d39c281397d..4270f66e669 100644 --- a/src/mongo/db/vector_clock.cpp +++ b/src/mongo/db/vector_clock.cpp @@ -40,7 +40,6 @@ #include "mongo/util/static_immortal.h" namespace mongo { - namespace { const auto vectorClockDecoration = ServiceContext::declareDecoration<VectorClock*>(); diff --git a/src/mongo/db/vector_clock.h b/src/mongo/db/vector_clock.h index f95f043b829..2437c84fa16 100644 --- a/src/mongo/db/vector_clock.h +++ b/src/mongo/db/vector_clock.h @@ -166,9 +166,9 @@ public: // The _id value of the vector clock singleton document. static constexpr StringData kDocIdKey = "vectorClockState"_sd; - // Methods used for unit-testing only - - void resetVectorClock_forTest(); + /////////////////////////////////////////////////////////////////////////////////////////////// + // The group of methods below is only used for unit-testing + /////////////////////////////////////////////////////////////////////////////////////////////// void advanceClusterTime_forTest(LogicalTime newTime) { _advanceTime_forTest(Component::ClusterTime, newTime); @@ -182,6 +182,8 @@ public: _advanceTime_forTest(Component::TopologyTime, newTime); } + void resetVectorClock_forTest(); + protected: class ComponentFormat { public: @@ -311,22 +313,27 @@ protected: */ void _advanceTime(LogicalTimeArray&& newTime); + /////////////////////////////////////////////////////////////////////////////////////////////// + // The group of methods below is only used for unit-testing + /////////////////////////////////////////////////////////////////////////////////////////////// + void _advanceTime_forTest(Component component, LogicalTime newTime); // Initialised only once, when the specific vector clock instance gets instantiated on the // service context ServiceContext* _service{nullptr}; - // The mutex protects _vectorTime and _isEnabled. + // Protects the fields below // // Note that ConfigTime is advanced under the ReplicationCoordinator mutex, so to avoid // potential deadlocks the ReplicationCoordator mutex should never be acquired whilst the // VectorClock mutex is held. mutable Mutex _mutex = MONGO_MAKE_LATCH("VectorClock::_mutex"); - LogicalTimeArray _vectorTime; bool _isEnabled{true}; + LogicalTimeArray _vectorTime; + private: class PlainComponentFormat; class SignedComponentFormat; diff --git a/src/mongo/db/vector_clock_mongod.cpp b/src/mongo/db/vector_clock_mongod.cpp index 736bc41966b..015a4a55b17 100644 --- a/src/mongo/db/vector_clock_mongod.cpp +++ b/src/mongo/db/vector_clock_mongod.cpp @@ -43,9 +43,6 @@ namespace mongo { namespace { -/** - * Vector clock implementation for mongod. - */ class VectorClockMongoD : public VectorClockMutable, public ReplicaSetAwareService<VectorClockMongoD> { VectorClockMongoD(const VectorClockMongoD&) = delete; @@ -63,9 +60,9 @@ public: SharedSemiFuture<void> recover() override; void waitForVectorClockToBeRecovered() override; - void _tickTo(Component component, LogicalTime newTime) override; +private: + // VectorClock methods implementation -protected: bool _gossipOutInternal(OperationContext* opCtx, BSONObjBuilder* out, const LogicalTimeArray& time) const override; @@ -78,11 +75,17 @@ protected: LogicalTimeArray _gossipInExternal(OperationContext* opCtx, const BSONObj& in, bool couldBeUnauthenticated) override; - bool _permitRefreshDuringGossipOut() const override; + bool _permitRefreshDuringGossipOut() const override { + return false; + } + + // VectorClockMutable methods implementation LogicalTime _tick(Component component, uint64_t nTicks) override; + void _tickTo(Component component, LogicalTime newTime) override; + + // ReplicaSetAwareService methods implementation -private: void onStartup(OperationContext* opCtx) override {} void onStepUpBegin(OperationContext* opCtx, long long term) override {} void onStepUpComplete(OperationContext* opCtx, long long term) override {} @@ -383,10 +386,6 @@ VectorClock::LogicalTimeArray VectorClockMongoD::_gossipInExternal(OperationCont return newTime; } -bool VectorClockMongoD::_permitRefreshDuringGossipOut() const { - return false; -} - LogicalTime VectorClockMongoD::_tick(Component component, uint64_t nTicks) { if (component == Component::ClusterTime) { // Although conceptually ClusterTime can only be ticked when a mongod is able to take writes diff --git a/src/mongo/db/vector_clock_mutable.cpp b/src/mongo/db/vector_clock_mutable.cpp index 5bf3fda8d9e..601c53e4a7f 100644 --- a/src/mongo/db/vector_clock_mutable.cpp +++ b/src/mongo/db/vector_clock_mutable.cpp @@ -36,7 +36,6 @@ #include "mongo/logv2/log.h" namespace mongo { - namespace { const auto vectorClockMutableDecoration = ServiceContext::declareDecoration<VectorClockMutable*>(); diff --git a/src/mongo/db/vector_clock_mutable.h b/src/mongo/db/vector_clock_mutable.h index f184d7bfbb9..5b43171b5a7 100644 --- a/src/mongo/db/vector_clock_mutable.h +++ b/src/mongo/db/vector_clock_mutable.h @@ -44,6 +44,7 @@ public: // clock implementation. static VectorClockMutable* get(ServiceContext* service); static VectorClockMutable* get(OperationContext* ctx); + static void registerVectorClockOnServiceContext(ServiceContext* service, VectorClockMutable* vectorClockMutable); @@ -59,7 +60,7 @@ public: } LogicalTime tickTopologyTime(uint64_t nTicks) { return _tick(Component::TopologyTime, nTicks); - }; + } /** * Authoritatively ticks the current time of the specified component to newTime. @@ -91,18 +92,18 @@ protected: LogicalTime _advanceComponentTimeByTicks(Component component, uint64_t nTicks); /** - * Returns the next time value for the component, and provides a guarantee that any future call - * to tick() will return a value at least 'nTicks' ticks in the future from the current time. - */ - virtual LogicalTime _tick(Component component, uint64_t nTicks) = 0; - - /** * Called by sublclasses in order to actually tickTo a Component time, once they have determined * that doing so is permissible. */ void _advanceComponentTimeTo(Component component, LogicalTime&& newTime); /** + * Returns the next time value for the component, and provides a guarantee that any future call + * to tick() will return a value at least 'nTicks' ticks in the future from the current time. + */ + virtual LogicalTime _tick(Component component, uint64_t nTicks) = 0; + + /** * Authoritatively ticks the current time of the Component to newTime. * * For ClusterTime, this should only be used for initializing from a trusted source, eg. from an diff --git a/src/mongo/db/vector_clock_trivial.cpp b/src/mongo/db/vector_clock_trivial.cpp index b789e1851a2..f2d9bfb7e32 100644 --- a/src/mongo/db/vector_clock_trivial.cpp +++ b/src/mongo/db/vector_clock_trivial.cpp @@ -45,10 +45,8 @@ public: VectorClockTrivial(); virtual ~VectorClockTrivial(); - void _tickTo(Component component, LogicalTime newTime) override; - -protected: - LogicalTime _tick(Component component, uint64_t nTicks) override; +private: + // VectorClock methods implementation bool _gossipOutInternal(OperationContext* opCtx, BSONObjBuilder* out, @@ -62,7 +60,14 @@ protected: LogicalTimeArray _gossipInExternal(OperationContext* opCtx, const BSONObj& in, bool couldBeUnauthenticated) override; - bool _permitRefreshDuringGossipOut() const override; + bool _permitRefreshDuringGossipOut() const override { + return false; + } + + // VectorClockMutable methods implementation + + LogicalTime _tick(Component component, uint64_t nTicks) override; + void _tickTo(Component component, LogicalTime newTime) override; }; const auto vectorClockTrivialDecoration = ServiceContext::declareDecoration<VectorClockTrivial>(); @@ -108,10 +113,6 @@ VectorClock::LogicalTimeArray VectorClockTrivial::_gossipInExternal(OperationCon return {}; } -bool VectorClockTrivial::_permitRefreshDuringGossipOut() const { - return false; -} - LogicalTime VectorClockTrivial::_tick(Component component, uint64_t nTicks) { return _advanceComponentTimeByTicks(component, nTicks); } diff --git a/src/mongo/s/vector_clock_mongos.cpp b/src/mongo/s/vector_clock_mongos.cpp index 30a1e036ba1..f2308880113 100644 --- a/src/mongo/s/vector_clock_mongos.cpp +++ b/src/mongo/s/vector_clock_mongos.cpp @@ -34,9 +34,6 @@ namespace mongo { namespace { -/** - * Vector clock implementation for mongos. - */ class VectorClockMongoS : public VectorClock { VectorClockMongoS(const VectorClockMongoS&) = delete; VectorClockMongoS& operator=(const VectorClockMongoS&) = delete; @@ -45,7 +42,9 @@ public: VectorClockMongoS(); virtual ~VectorClockMongoS(); -protected: +private: + // VectorClock methods implementation + bool _gossipOutInternal(OperationContext* opCtx, BSONObjBuilder* out, const LogicalTimeArray& time) const override; @@ -58,7 +57,9 @@ protected: LogicalTimeArray _gossipInExternal(OperationContext* opCtx, const BSONObj& in, bool couldBeUnauthenticated) override; - bool _permitRefreshDuringGossipOut() const override; + bool _permitRefreshDuringGossipOut() const override { + return true; + } }; const auto vectorClockMongoSDecoration = ServiceContext::declareDecoration<VectorClockMongoS>(); @@ -108,9 +109,5 @@ VectorClock::LogicalTimeArray VectorClockMongoS::_gossipInExternal(OperationCont return newTime; } -bool VectorClockMongoS::_permitRefreshDuringGossipOut() const { - return true; -} - } // namespace } // namespace mongo |