Clio  develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
ETLService.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 "data/BackendInterface.hpp"
23#include "data/Types.hpp"
24#include "etl/CacheLoaderInterface.hpp"
25#include "etl/CacheUpdaterInterface.hpp"
26#include "etl/ETLServiceInterface.hpp"
27#include "etl/ETLState.hpp"
28#include "etl/ExtractorInterface.hpp"
29#include "etl/InitialLoadObserverInterface.hpp"
30#include "etl/LedgerPublisherInterface.hpp"
32#include "etl/LoaderInterface.hpp"
33#include "etl/MonitorInterface.hpp"
34#include "etl/MonitorProviderInterface.hpp"
36#include "etl/SystemState.hpp"
37#include "etl/TaskManagerInterface.hpp"
38#include "etl/TaskManagerProviderInterface.hpp"
39#include "etl/impl/AmendmentBlockHandler.hpp"
40#include "etl/impl/CacheUpdater.hpp"
41#include "etl/impl/Extraction.hpp"
42#include "etl/impl/LedgerFetcher.hpp"
43#include "etl/impl/LedgerPublisher.hpp"
44#include "etl/impl/Loading.hpp"
45#include "etl/impl/Registry.hpp"
46#include "etl/impl/Scheduling.hpp"
47#include "etl/impl/TaskManager.hpp"
48#include "etl/impl/ext/Cache.hpp"
49#include "etl/impl/ext/Core.hpp"
50#include "etl/impl/ext/NFT.hpp"
51#include "etl/impl/ext/Successor.hpp"
52#include "feed/SubscriptionManagerInterface.hpp"
53#include "util/async/AnyExecutionContext.hpp"
54#include "util/async/AnyOperation.hpp"
55#include "util/config/ConfigDefinition.hpp"
56#include "util/log/Logger.hpp"
57
58#include <boost/asio/io_context.hpp>
59#include <boost/json/object.hpp>
60#include <boost/signals2/connection.hpp>
61#include <fmt/format.h>
62#include <xrpl/basics/Blob.h>
63#include <xrpl/basics/base_uint.h>
64#include <xrpl/basics/strHex.h>
65#include <xrpl/proto/org/xrpl/rpc/v1/get_ledger.pb.h>
66#include <xrpl/proto/org/xrpl/rpc/v1/ledger.pb.h>
67#include <xrpl/protocol/LedgerHeader.h>
68#include <xrpl/protocol/STTx.h>
69#include <xrpl/protocol/TxFormats.h>
70#include <xrpl/protocol/TxMeta.h>
71
72#include <cstddef>
73#include <cstdint>
74#include <functional>
75#include <memory>
76#include <optional>
77#include <string>
78
79namespace etl {
80
95 util::Logger log_{"ETL"};
96
98 std::reference_wrapper<util::config::ClioConfigDefinition const> config_;
99 std::shared_ptr<BackendInterface> backend_;
100 std::shared_ptr<LoadBalancerInterface> balancer_;
101 std::shared_ptr<NetworkValidatedLedgersInterface> ledgers_;
102 std::shared_ptr<LedgerPublisherInterface> publisher_;
103 std::shared_ptr<CacheLoaderInterface> cacheLoader_;
104 std::shared_ptr<CacheUpdaterInterface> cacheUpdater_;
105 std::shared_ptr<ExtractorInterface> extractor_;
106 std::shared_ptr<LoaderInterface> loader_;
107 std::shared_ptr<InitialLoadObserverInterface> initialLoadObserver_;
108 std::shared_ptr<TaskManagerProviderInterface> taskManagerProvider_;
109 std::shared_ptr<MonitorProviderInterface> monitorProvider_;
110 std::shared_ptr<SystemState> state_;
111
112 std::optional<uint32_t> startSequence_;
113 std::optional<uint32_t> finishSequence_;
114
115 std::unique_ptr<MonitorInterface> monitor_;
116 std::unique_ptr<TaskManagerInterface> taskMan_;
117
118 boost::signals2::scoped_connection monitorNewSeqSubscription_;
119 boost::signals2::scoped_connection monitorDbStalledSubscription_;
120
121 std::optional<util::async::AnyOperation<void>> mainLoop_;
122
123public:
137 static std::shared_ptr<ETLServiceInterface>
141 std::shared_ptr<BackendInterface> backend,
142 std::shared_ptr<feed::SubscriptionManagerInterface> subscriptions,
143 std::shared_ptr<LoadBalancerInterface> balancer,
144 std::shared_ptr<NetworkValidatedLedgersInterface> ledgers
145 );
146
167 std::reference_wrapper<util::config::ClioConfigDefinition const> config,
168 std::shared_ptr<data::BackendInterface> backend,
169 std::shared_ptr<LoadBalancerInterface> balancer,
170 std::shared_ptr<NetworkValidatedLedgersInterface> ledgers,
171 std::shared_ptr<LedgerPublisherInterface> publisher,
172 std::shared_ptr<CacheLoaderInterface> cacheLoader,
173 std::shared_ptr<CacheUpdaterInterface> cacheUpdater,
174 std::shared_ptr<ExtractorInterface> extractor,
175 std::shared_ptr<LoaderInterface> loader,
176 std::shared_ptr<InitialLoadObserverInterface> initialLoadObserver,
177 std::shared_ptr<TaskManagerProviderInterface> taskManagerProvider,
178 std::shared_ptr<MonitorProviderInterface> monitorProvider,
179 std::shared_ptr<SystemState> state
180 );
181
182 ~ETLService() override;
183
184 void
185 run() override;
186
187 void
188 stop() override;
189
190 boost::json::object
191 getInfo() const override;
192
193 bool
194 isAmendmentBlocked() const override;
195
196 bool
197 isCorruptionDetected() const override;
198
199 std::optional<ETLState>
200 getETLState() const override;
201
202 std::uint32_t
203 lastCloseAgeSeconds() const override;
204
205private:
206 std::optional<data::LedgerRange>
207 loadInitialLedgerIfNeeded();
208
209 void
210 startMonitor(uint32_t seq);
211
212 void
213 startLoading(uint32_t seq);
214
215 void
216 attemptTakeoverWriter();
217
218 void
219 giveUpWriter();
220};
221
222} // namespace etl
bool isAmendmentBlocked() const override
Check for the amendment blocked state.
Definition ETLService.cpp:255
void run() override
Start all components to run ETL service.
Definition ETLService.cpp:195
ETLService(util::async::AnyExecutionContext ctx, std::reference_wrapper< util::config::ClioConfigDefinition const > config, std::shared_ptr< data::BackendInterface > backend, std::shared_ptr< LoadBalancerInterface > balancer, std::shared_ptr< NetworkValidatedLedgersInterface > ledgers, std::shared_ptr< LedgerPublisherInterface > publisher, std::shared_ptr< CacheLoaderInterface > cacheLoader, std::shared_ptr< CacheUpdaterInterface > cacheUpdater, std::shared_ptr< ExtractorInterface > extractor, std::shared_ptr< LoaderInterface > loader, std::shared_ptr< InitialLoadObserverInterface > initialLoadObserver, std::shared_ptr< TaskManagerProviderInterface > taskManagerProvider, std::shared_ptr< MonitorProviderInterface > monitorProvider, std::shared_ptr< SystemState > state)
Create an instance of ETLService.
Definition ETLService.cpp:144
boost::json::object getInfo() const override
Get state of ETL as a JSON object.
Definition ETLService.cpp:241
bool isCorruptionDetected() const override
Check whether Clio detected DB corruptions.
Definition ETLService.cpp:261
static std::shared_ptr< ETLServiceInterface > makeETLService(util::config::ClioConfigDefinition const &config, util::async::AnyExecutionContext ctx, std::shared_ptr< BackendInterface > backend, std::shared_ptr< feed::SubscriptionManagerInterface > subscriptions, std::shared_ptr< LoadBalancerInterface > balancer, std::shared_ptr< NetworkValidatedLedgersInterface > ledgers)
A factory function to spawn new ETLService instances.
Definition ETLService.cpp:79
void stop() override
Stop the ETL service.
Definition ETLService.cpp:228
std::uint32_t lastCloseAgeSeconds() const override
Get time passed since last ledger close, in seconds.
Definition ETLService.cpp:273
std::optional< ETLState > getETLState() const override
Get the etl nodes' state.
Definition ETLService.cpp:267
A simple thread-safe logger for the channel specified in the constructor.
Definition Logger.hpp:95
A type-erased execution context.
Definition AnyExecutionContext.hpp:41
All the config data will be stored and extracted from this class.
Definition ConfigDefinition.hpp:50
This is a base class for any ETL service implementations.
Definition ETLServiceInterface.hpp:36