Clio  develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
WriterState.hpp
1#pragma once
2
3#include "data/LedgerCacheInterface.hpp"
4#include "etl/SystemState.hpp"
5#include "util/prometheus/Bool.hpp"
6#include "util/prometheus/Label.hpp"
7#include "util/prometheus/Prometheus.hpp"
8
9#include <functional>
10#include <memory>
11
12namespace etl {
13
22public:
23 virtual ~WriterStateInterface() = default;
24
29 [[nodiscard]] virtual bool
30 isReadOnly() const = 0;
31
36 [[nodiscard]] virtual bool
37 isWriting() const = 0;
38
45 virtual void
47
54 virtual void
56
62 [[nodiscard]] virtual bool
63 isFallback() const = 0;
64
75 [[nodiscard]] virtual bool
76 isFallbackRecovery() const = 0;
77
92 virtual void
93 setFallbackRecovery(bool newValue) = 0;
94
106 virtual void
108
114 [[nodiscard]] virtual bool
115 isEtlStarted() const = 0;
116
122 [[nodiscard]] virtual bool
123 isCacheFull() const = 0;
124
134 [[nodiscard]] virtual std::unique_ptr<WriterStateInterface>
135 clone() const = 0;
136};
137
146private:
147 std::shared_ptr<SystemState>
148 systemState_;
149 std::reference_wrapper<data::LedgerCacheInterface const> cache_;
150
159 util::prometheus::Bool isFallbackRecovery_ = PrometheusService::boolMetric(
160 "etl_writing_deciding_fallback_recovery",
162 "Whether clio is in recovery from the fallback writer decision mechanism"
163 );
164
165public:
172 WriterState(std::shared_ptr<SystemState> state, data::LedgerCacheInterface const& cache);
173
174 [[nodiscard]] bool
175 isReadOnly() const override;
176
181 [[nodiscard]] bool
182 isWriting() const override;
183
190 void
191 startWriting() override;
192
199 void
200 giveUpWriting() override;
201
208 void
209 setWriterDecidingFallback() override;
210
216 [[nodiscard]] bool
217 isFallback() const override;
218
220 [[nodiscard]] bool
221 isFallbackRecovery() const override;
222
224 void
225 setFallbackRecovery(bool newValue) override;
226
228 [[nodiscard]] bool
229 isEtlStarted() const override;
230
232 [[nodiscard]] bool
233 isCacheFull() const override;
234
242 [[nodiscard]] std::unique_ptr<WriterStateInterface>
243 clone() const override;
244};
245
246} // namespace etl
static util::prometheus::Bool boolMetric(std::string name, util::prometheus::Labels labels, std::optional< std::string > description=std::nullopt)
Get a bool based metric. It will be created if it doesn't exist.
Definition Prometheus.cpp:201
Cache for an entire ledger.
Definition LedgerCacheInterface.hpp:21
Interface for managing writer state in the ETL subsystem.
Definition WriterState.hpp:21
virtual void setWriterDecidingFallback()=0
Switch the cluster to the fallback writer decision mechanism.
virtual bool isEtlStarted() const =0
Whether the ETL monitor has started and the node is ready to become a writer.
virtual bool isFallback() const =0
Check if the cluster is using the fallback writer decision mechanism.
virtual void giveUpWriting()=0
Request to stop writing to the database.
virtual bool isWriting() const =0
Check if the ETL process is currently writing to the database.
virtual std::unique_ptr< WriterStateInterface > clone() const =0
Create a clone of this writer state.
virtual bool isFallbackRecovery() const =0
Check if this node is in fallback recovery mode.
virtual void setFallbackRecovery(bool newValue)=0
Set or clear the fallback recovery flag.
virtual void startWriting()=0
Request to start writing to the database.
virtual bool isReadOnly() const =0
Check if the ETL process is in strict read-only mode.
virtual bool isCacheFull() const =0
Whether the ledger cache is fully loaded.
WriterState(std::shared_ptr< SystemState > state, data::LedgerCacheInterface const &cache)
Construct a WriterState with the given system state and cache.
Definition WriterState.cpp:11
bool isFallbackRecovery() const override
Check if this node is in fallback recovery mode.
Definition WriterState.cpp:63
bool isFallback() const override
Check if the cluster is using the fallback writer decision mechanism.
Definition WriterState.cpp:57
void startWriting() override
Request to start writing to the database.
Definition WriterState.cpp:32
void setFallbackRecovery(bool newValue) override
Set or clear the fallback recovery flag.
Definition WriterState.cpp:69
bool isCacheFull() const override
Whether the ledger cache is fully loaded.
Definition WriterState.cpp:84
bool isEtlStarted() const override
Whether the ETL monitor has started and the node is ready to become a writer.
Definition WriterState.cpp:78
void giveUpWriting() override
Request to stop writing to the database.
Definition WriterState.cpp:41
void setWriterDecidingFallback() override
Switch the cluster to the fallback writer decision mechanism.
Definition WriterState.cpp:50
bool isWriting() const override
Check if the ETL process is currently writing to the database.
Definition WriterState.cpp:26
std::unique_ptr< WriterStateInterface > clone() const override
Create a clone of this writer state.
Definition WriterState.cpp:90
bool isReadOnly() const override
Check if the ETL process is in strict read-only mode.
Definition WriterState.cpp:20
Class representing a collection of Prometheus labels.
Definition Label.hpp:41