Clio  develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
WriterState.hpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of clio: https://github.com/XRPLF/clio
4 Copyright (c) 2025, the clio developers.
5
6 Permission to use, copy, modify, and distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#pragma once
21
22#include "etl/SystemState.hpp"
23
24#include <memory>
25
26namespace etl {
27
36public:
37 virtual ~WriterStateInterface() = default;
38
43 [[nodiscard]] virtual bool
44 isReadOnly() const = 0;
45
50 [[nodiscard]] virtual bool
51 isWriting() const = 0;
52
59 virtual void
61
68 virtual void
70
76 [[nodiscard]] virtual bool
77 isFallback() const = 0;
78
87 virtual void
89
95 [[nodiscard]] virtual bool
96 isLoadingCache() const = 0;
97
107 [[nodiscard]] virtual std::unique_ptr<WriterStateInterface>
108 clone() const = 0;
109};
110
119private:
120 std::shared_ptr<SystemState> systemState_;
121
122public:
127 WriterState(std::shared_ptr<SystemState> state);
128
129 bool
130 isReadOnly() const override;
131
136 bool
137 isWriting() const override;
138
145 void
146 startWriting() override;
147
154 void
155 giveUpWriting() override;
156
163 void
164 setWriterDecidingFallback() override;
165
171 bool
172 isFallback() const override;
173
179 bool
180 isLoadingCache() const override;
181
189 std::unique_ptr<WriterStateInterface>
190 clone() const override;
191};
192
193} // namespace etl
Interface for managing writer state in the ETL subsystem.
Definition WriterState.hpp:35
virtual void setWriterDecidingFallback()=0
Switch the cluster to the fallback writer decision mechanism.
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 void startWriting()=0
Request to start writing to the database.
virtual bool isLoadingCache() const =0
Whether clio is still loading cache after startup.
virtual bool isReadOnly() const =0
Check if the ETL process is in strict read-only mode.
bool isLoadingCache() const override
Whether clio is still loading cache after startup.
Definition WriterState.cpp:76
bool isFallback() const override
Check if the cluster is using the fallback writer decision mechanism.
Definition WriterState.cpp:70
void startWriting() override
Request to start writing to the database.
Definition WriterState.cpp:46
void giveUpWriting() override
Request to stop writing to the database.
Definition WriterState.cpp:55
void setWriterDecidingFallback() override
Switch the cluster to the fallback writer decision mechanism.
Definition WriterState.cpp:64
bool isWriting() const override
Check if the ETL process is currently writing to the database.
Definition WriterState.cpp:40
std::unique_ptr< WriterStateInterface > clone() const override
Create a clone of this writer state.
Definition WriterState.cpp:82
WriterState(std::shared_ptr< SystemState > state)
Construct a WriterState with the given system state.
Definition WriterState.cpp:29
bool isReadOnly() const override
Check if the ETL process is in strict read-only mode.
Definition WriterState.cpp:34