diff options
Diffstat (limited to 'src/mongo/db/process_health/fault.h')
-rw-r--r-- | src/mongo/db/process_health/fault.h | 78 |
1 files changed, 57 insertions, 21 deletions
diff --git a/src/mongo/db/process_health/fault.h b/src/mongo/db/process_health/fault.h index 383c4121e5e..a3fc1dbf577 100644 --- a/src/mongo/db/process_health/fault.h +++ b/src/mongo/db/process_health/fault.h @@ -28,29 +28,31 @@ */ #pragma once -#include <memory> - -#include "mongo/bson/bsonobjbuilder.h" -#include "mongo/db/process_health/fault_facets_container.h" +#include "mongo/db/process_health/fault_facet.h" +#include "mongo/db/service_context.h" +#include "mongo/util/clock_source.h" #include "mongo/util/duration.h" -#include "mongo/util/uuid.h" +#include "mongo/util/timer.h" namespace mongo { namespace process_health { /** - * Detailed description of the current fault. - * @see FaultManager for more details. + * Internal implementation of the Fault class. + * @see Fault */ class Fault : public std::enable_shared_from_this<Fault> { Fault(const Fault&) = delete; Fault& operator=(const Fault&) = delete; public: - Fault() = default; - virtual ~Fault() = default; + explicit Fault(ClockSource* clockSource); + + ~Fault() = default; - virtual UUID getId() const = 0; + // Fault interface. + + UUID getId() const; /** * The fault severity value is an aggregate severity calculated @@ -61,36 +63,70 @@ public: * (0, 1.0): Transient fault condition * [1.0, Inf): Active fault condition */ - virtual double getSeverity() const = 0; + double getSeverity() const; /** * @return The lifetime of this fault from the moment it was created. * Invariant: getDuration() >= getActiveFaultDuration() */ - virtual Milliseconds getDuration() const = 0; + Milliseconds getDuration() const; /** * Describes the current fault. */ - virtual void appendDescription(BSONObjBuilder* builder) const = 0; + void appendDescription(BSONObjBuilder* builder) const; BSONObj toBSON() const { BSONObjBuilder builder; appendDescription(&builder); return builder.obj(); } -}; -using FaultConstPtr = std::shared_ptr<const Fault>; + std::vector<FaultFacetPtr> getFacets() const; -/** - * Internal Fault interface that has accessors to manage Facets this Fault owns. - */ -class FaultInternal : public Fault, public FaultFacetsContainer { -public: - ~FaultInternal() override = default; + /** + * Checks that a Facet of a given type already exists and returns it. + * + * @returns existing facet or null. + */ + FaultFacetPtr getFaultFacet(FaultFacetType type); + + /** + * Update the fault with supplied facet. + * + * @param facet new value to insert/replace or nullptr to delete. + */ + void upsertFacet(FaultFacetPtr facet); + + + /** + * Delete a facet from this fault by its type. + * + * @param type type of facet to remove. + */ + void removeFacet(FaultFacetType type); + + /** + * Performs necessary actions to delete all resolved facets. + */ + void garbageCollectResolvedFacets(); + + bool hasCriticalFacet(const FaultManagerConfig& config) const; + +private: + const UUID _id = UUID::gen(); + + ClockSource* const _clockSource; + const Date_t _startTime; + + mutable Mutex _mutex = MONGO_MAKE_LATCH(HierarchicalAcquisitionLevel(0), "Fault::_mutex"); + // We don't need a map by type because we expect to have only few facets. + // Linear search is much faster, we want to avoid any lock contention here. + std::deque<FaultFacetPtr> _facets; }; +using FaultPtr = std::shared_ptr<Fault>; +using FaultConstPtr = std::shared_ptr<const Fault>; } // namespace process_health } // namespace mongo |