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> systemState_;
148 std::reference_wrapper<data::LedgerCacheInterface const> cache_;
149
159 "etl_writing_deciding_fallback_recovery",
161 "Whether clio is in recovery from the fallback writer decision mechanism"
162 );
163
164public:
171 WriterState(std::shared_ptr<SystemState> state, data::LedgerCacheInterface const& cache);
172
177 [[nodiscard]] bool
178 isReadOnly() const override;
179
184 [[nodiscard]] bool
185 isWriting() const override;
186
193 void
194 startWriting() override;
195
202 void
203 giveUpWriting() override;
204
211 void
212 setWriterDecidingFallback() override;
213
219 [[nodiscard]] bool
220 isFallback() const override;
221
225 [[nodiscard]] bool
226 isFallbackRecovery() const override;
227
231 void
232 setFallbackRecovery(bool newValue) override;
233
237 [[nodiscard]] bool
238 isEtlStarted() const override;
239
243 [[nodiscard]] bool
244 isCacheFull() const override;
245
253 [[nodiscard]] std::unique_ptr<WriterStateInterface>
254 clone() const override;
255};
256
257} // 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
This namespace contains everything to do with the ETL and ETL sources.
Definition AmendmentBlockHandlerInterface.hpp:6
AnyBool< GaugeInt > Bool
Alias for Prometheus bool metric with GaugeInt implementation.
Definition Bool.hpp:74