diff options
author | Pierlauro Sciarelli <pierlauro.sciarelli@mongodb.com> | 2020-07-07 11:45:40 +0200 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-07-07 10:18:44 +0000 |
commit | ff4465b905b331fc82edb8194092917ad0c7255f (patch) | |
tree | 15f837e1f1c701a680d0335ecbe727fad0075098 /src | |
parent | b887370e6772548bf91a3816fa2c8a25a49e9f61 (diff) | |
download | mongo-ff4465b905b331fc82edb8194092917ad0c7255f.tar.gz |
SERVER-49315 Allow definition of custom vector clock gossip formats
Diffstat (limited to 'src')
-rw-r--r-- | src/mongo/db/vector_clock.cpp | 62 | ||||
-rw-r--r-- | src/mongo/db/vector_clock.h | 32 |
2 files changed, 46 insertions, 48 deletions
diff --git a/src/mongo/db/vector_clock.cpp b/src/mongo/db/vector_clock.cpp index 613cffeff17..5991ba97671 100644 --- a/src/mongo/db/vector_clock.cpp +++ b/src/mongo/db/vector_clock.cpp @@ -113,38 +113,10 @@ void VectorClock::_advanceTime(LogicalTimeArray&& newTime) { } } -class VectorClock::GossipFormat { +class VectorClock::PlainComponentFormat : public VectorClock::ComponentFormat { public: - class Plain; - class Signed; - template <class ActualFormat> - class OnlyGossipOutOnNewFCV; - - static const ComponentArray<std::unique_ptr<GossipFormat>> _formatters; - - GossipFormat(std::string fieldName) : _fieldName(fieldName) {} - virtual ~GossipFormat() = default; - - // Returns true if the time was output, false otherwise. - virtual bool out(ServiceContext* service, - OperationContext* opCtx, - bool permitRefresh, - BSONObjBuilder* out, - LogicalTime time, - Component component) const = 0; - virtual LogicalTime in(ServiceContext* service, - OperationContext* opCtx, - const BSONObj& in, - bool couldBeUnauthenticated, - Component component) const = 0; - - const std::string _fieldName; -}; - -class VectorClock::GossipFormat::Plain : public VectorClock::GossipFormat { -public: - using GossipFormat::GossipFormat; - virtual ~Plain() = default; + using ComponentFormat::ComponentFormat; + virtual ~PlainComponentFormat() = default; bool out(ServiceContext* service, OperationContext* opCtx, @@ -174,10 +146,10 @@ public: }; template <class ActualFormat> -class VectorClock::GossipFormat::OnlyGossipOutOnNewFCV : public ActualFormat { +class VectorClock::OnlyOutOnNewFCVComponentFormat : public ActualFormat { public: using ActualFormat::ActualFormat; - virtual ~OnlyGossipOutOnNewFCV() = default; + virtual ~OnlyOutOnNewFCVComponentFormat() = default; bool out(ServiceContext* service, OperationContext* opCtx, @@ -203,10 +175,10 @@ public: } }; -class VectorClock::GossipFormat::Signed : public VectorClock::GossipFormat { +class VectorClock::SignedComponentFormat : public VectorClock::ComponentFormat { public: - using GossipFormat::GossipFormat; - virtual ~Signed() = default; + using ComponentFormat::ComponentFormat; + virtual ~SignedComponentFormat() = default; bool out(ServiceContext* service, OperationContext* opCtx, @@ -339,14 +311,14 @@ private: static constexpr char kSignatureKeyIdFieldName[] = "keyId"; }; -const VectorClock::ComponentArray<std::unique_ptr<VectorClock::GossipFormat>> - VectorClock::GossipFormat::_formatters{ - std::make_unique<VectorClock::GossipFormat::Signed>(VectorClock::kClusterTimeFieldName), +const VectorClock::ComponentArray<std::unique_ptr<VectorClock::ComponentFormat>> + VectorClock::_gossipFormatters{ + std::make_unique<VectorClock::SignedComponentFormat>(VectorClock::kClusterTimeFieldName), std::make_unique< - VectorClock::GossipFormat::OnlyGossipOutOnNewFCV<VectorClock::GossipFormat::Plain>>( + VectorClock::OnlyOutOnNewFCVComponentFormat<VectorClock::PlainComponentFormat>>( VectorClock::kConfigTimeFieldName), std::make_unique< - VectorClock::GossipFormat::OnlyGossipOutOnNewFCV<VectorClock::GossipFormat::Plain>>( + VectorClock::OnlyOutOnNewFCVComponentFormat<VectorClock::PlainComponentFormat>>( VectorClock::kTopologyTimeFieldName)}; bool VectorClock::gossipOut(OperationContext* opCtx, @@ -389,7 +361,7 @@ bool VectorClock::_gossipOutComponent(OperationContext* opCtx, BSONObjBuilder* out, const LogicalTimeArray& time, Component component) const { - bool wasOutput = GossipFormat::_formatters[component]->out( + bool wasOutput = _gossipFormatters[component]->out( _service, opCtx, _permitRefreshDuringGossipOut(), out, time[component], component); return (component == Component::ClusterTime) ? wasOutput : false; } @@ -399,12 +371,12 @@ void VectorClock::_gossipInComponent(OperationContext* opCtx, bool couldBeUnauthenticated, LogicalTimeArray* newTime, Component component) { - (*newTime)[component] = GossipFormat::_formatters[component]->in( - _service, opCtx, in, couldBeUnauthenticated, component); + (*newTime)[component] = + _gossipFormatters[component]->in(_service, opCtx, in, couldBeUnauthenticated, component); } std::string VectorClock::_componentName(Component component) { - return GossipFormat::_formatters[component]->_fieldName; + return _gossipFormatters[component]->_fieldName; } bool VectorClock::isEnabled() const { diff --git a/src/mongo/db/vector_clock.h b/src/mongo/db/vector_clock.h index a55f3c037f5..6434cd3aa6b 100644 --- a/src/mongo/db/vector_clock.h +++ b/src/mongo/db/vector_clock.h @@ -54,7 +54,7 @@ public: _kNumComponents = 3, }; -private: +protected: template <typename T> class ComponentArray : public std::array<T, static_cast<unsigned long>(Component::_kNumComponents)> { @@ -76,7 +76,6 @@ private: T& operator[](unsigned long i); }; -protected: using LogicalTimeArray = ComponentArray<LogicalTime>; public: @@ -137,6 +136,28 @@ public: void advanceTime_forTest(Component component, LogicalTime newTime); protected: + class ComponentFormat { + + public: + ComponentFormat(std::string fieldName) : _fieldName(fieldName) {} + virtual ~ComponentFormat() = default; + + // Returns true if the time was output, false otherwise. + virtual bool out(ServiceContext* service, + OperationContext* opCtx, + bool permitRefresh, + BSONObjBuilder* out, + LogicalTime time, + Component component) const = 0; + virtual LogicalTime in(ServiceContext* service, + OperationContext* opCtx, + const BSONObj& in, + bool couldBeUnauthenticated, + Component component) const = 0; + + const std::string _fieldName; + }; + VectorClock(); virtual ~VectorClock(); @@ -258,7 +279,12 @@ protected: bool _isEnabled{true}; private: - class GossipFormat; + class PlainComponentFormat; + class SignedComponentFormat; + template <class ActualFormat> + class OnlyOutOnNewFCVComponentFormat; + + static const ComponentArray<std::unique_ptr<ComponentFormat>> _gossipFormatters; }; } // namespace mongo |