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/ETLState.hpp"
26#include "etl/SystemState.hpp"
27#include "etl/impl/AmendmentBlockHandler.hpp"
28#include "etl/impl/LedgerFetcher.hpp"
29#include "etlng/CacheLoaderInterface.hpp"
30#include "etlng/CacheUpdaterInterface.hpp"
31#include "etlng/ETLServiceInterface.hpp"
32#include "etlng/ExtractorInterface.hpp"
33#include "etlng/InitialLoadObserverInterface.hpp"
34#include "etlng/LedgerPublisherInterface.hpp"
36#include "etlng/LoaderInterface.hpp"
37#include "etlng/MonitorInterface.hpp"
38#include "etlng/MonitorProviderInterface.hpp"
39#include "etlng/TaskManagerInterface.hpp"
40#include "etlng/TaskManagerProviderInterface.hpp"
41#include "etlng/impl/AmendmentBlockHandler.hpp"
42#include "etlng/impl/CacheUpdater.hpp"
43#include "etlng/impl/Extraction.hpp"
44#include "etlng/impl/LedgerPublisher.hpp"
45#include "etlng/impl/Loading.hpp"
46#include "etlng/impl/Registry.hpp"
47#include "etlng/impl/Scheduling.hpp"
48#include "etlng/impl/TaskManager.hpp"
49#include "etlng/impl/ext/Cache.hpp"
50#include "etlng/impl/ext/Core.hpp"
51#include "etlng/impl/ext/NFT.hpp"
52#include "etlng/impl/ext/Successor.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/core.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 etlng {
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<etl::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<etlng::TaskManagerProviderInterface> taskManagerProvider_;
109 std::shared_ptr<etlng::MonitorProviderInterface> monitorProvider_;
110 std::shared_ptr<etl::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:
144 std::reference_wrapper<util::config::ClioConfigDefinition const> config,
145 std::shared_ptr<data::BackendInterface> backend,
146 std::shared_ptr<LoadBalancerInterface> balancer,
147 std::shared_ptr<etl::NetworkValidatedLedgersInterface> ledgers,
148 std::shared_ptr<LedgerPublisherInterface> publisher,
149 std::shared_ptr<CacheLoaderInterface> cacheLoader,
150 std::shared_ptr<CacheUpdaterInterface> cacheUpdater,
151 std::shared_ptr<ExtractorInterface> extractor,
152 std::shared_ptr<LoaderInterface> loader,
153 std::shared_ptr<InitialLoadObserverInterface> initialLoadObserver,
154 std::shared_ptr<etlng::TaskManagerProviderInterface> taskManagerProvider,
155 std::shared_ptr<etlng::MonitorProviderInterface> monitorProvider,
156 std::shared_ptr<etl::SystemState> state
157 );
158
159 ~ETLService() override;
160
161 void
162 run() override;
163
164 void
165 stop() override;
166
167 boost::json::object
168 getInfo() const override;
169
170 bool
171 isAmendmentBlocked() const override;
172
173 bool
174 isCorruptionDetected() const override;
175
176 std::optional<etl::ETLState>
177 getETLState() const override;
178
179 std::uint32_t
180 lastCloseAgeSeconds() const override;
181
182private:
183 std::optional<data::LedgerRange>
184 loadInitialLedgerIfNeeded();
185
186 void
187 startMonitor(uint32_t seq);
188
189 void
190 startLoading(uint32_t seq);
191
192 void
193 attemptTakeoverWriter();
194
195 void
196 giveUpWriter();
197};
198
199} // namespace etlng
This class is responsible for continuously extracting data from a p2p node, and writing that data to ...
Definition ETLService.hpp:94
void stop() override
Stop the ETL service.
Definition ETLService.cpp:152
void run() override
Start all components to run ETL service.
Definition ETLService.cpp:123
bool isCorruptionDetected() const override
Check whether Clio detected DB corruptions.
Definition ETLService.cpp:185
std::uint32_t lastCloseAgeSeconds() const override
Get time passed since last ledger close, in seconds.
Definition ETLService.cpp:197
std::optional< etl::ETLState > getETLState() const override
Get the etl nodes' state.
Definition ETLService.cpp:191
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< etl::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< etlng::TaskManagerProviderInterface > taskManagerProvider, std::shared_ptr< etlng::MonitorProviderInterface > monitorProvider, std::shared_ptr< etl::SystemState > state)
Create an instance of ETLService.
Definition ETLService.cpp:72
boost::json::object getInfo() const override
Get state of ETL as a JSON object.
Definition ETLService.cpp:165
bool isAmendmentBlocked() const override
Check for the amendment blocked state.
Definition ETLService.cpp:179
A simple thread-safe logger for the channel specified in the constructor.
Definition Logger.hpp:111
A type-erased execution context.
Definition AnyExecutionContext.hpp:41
This is a base class for any ETL service implementations.
Definition ETLServiceInterface.hpp:36