Clio develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
LoadBalancerInterface.hpp
Go to the documentation of this file.
1//------------------------------------------------------------------------------
2/*
3 This file is part of clio: https://github.com/XRPLF/clio
4 Copyright (c) 2024, 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
21#pragma once
22
23#include "etl/ETLState.hpp"
24#include "etlng/InitialLoadObserverInterface.hpp"
25#include "rpc/Errors.hpp"
26
27#include <boost/asio/spawn.hpp>
28#include <boost/json/object.hpp>
29#include <boost/json/value.hpp>
30#include <org/xrpl/rpc/v1/ledger.pb.h>
31#include <xrpl/proto/org/xrpl/rpc/v1/get_ledger.pb.h>
32
33#include <chrono>
34#include <cstdint>
35#include <expected>
36#include <optional>
37#include <string>
38#include <vector>
39
40namespace etlng {
41
46 Cancelled, /*< Indicating the initial load got cancelled by user */
47 Errored, /*< Indicating some error happened during initial ledger load */
48};
49
54using InitialLedgerLoadResult = std::expected<std::vector<std::string>, InitialLedgerLoadError>;
55
60public:
61 using RawLedgerObjectType = org::xrpl::rpc::v1::RawLedgerObject;
62 using GetLedgerResponseType = org::xrpl::rpc::v1::GetLedgerResponse;
63 using OptionalGetLedgerResponseType = std::optional<GetLedgerResponseType>;
64
65 virtual ~LoadBalancerInterface() = default;
66
76 [[nodiscard]] virtual InitialLedgerLoadResult
78 uint32_t sequence,
80 std::chrono::steady_clock::duration retryAfter = std::chrono::seconds{2}
81 ) = 0;
82
91 [[nodiscard]] virtual std::vector<std::string>
92 loadInitialLedger(uint32_t sequence, std::chrono::steady_clock::duration retryAfter = std::chrono::seconds{2}) = 0;
93
107 [[nodiscard]] virtual OptionalGetLedgerResponseType
109 uint32_t ledgerSequence,
110 bool getObjects,
111 bool getObjectNeighbors,
112 std::chrono::steady_clock::duration retryAfter = std::chrono::seconds{2}
113 ) = 0;
114
120 [[nodiscard]] virtual boost::json::value
121 toJson() const = 0;
122
132 [[nodiscard]] virtual std::expected<boost::json::object, rpc::CombinedError>
134 boost::json::object const& request,
135 std::optional<std::string> const& clientIp,
136 bool isAdmin,
137 boost::asio::yield_context yield
138 ) = 0;
139
144 [[nodiscard]] virtual std::optional<etl::ETLState>
145 getETLState() noexcept = 0;
146
153 virtual void
154 stop(boost::asio::yield_context yield) = 0;
155};
156
157} // namespace etlng
InitialLedgerLoadError
Represents possible errors for initial ledger load.
Definition LoadBalancerInterface.hpp:45
std::expected< std::vector< std::string >, InitialLedgerLoadError > InitialLedgerLoadResult
The result type of the initial ledger load.
Definition LoadBalancerInterface.hpp:54
An interface for LoadBalancer.
Definition LoadBalancerInterface.hpp:59
virtual std::expected< boost::json::object, rpc::CombinedError > forwardToRippled(boost::json::object const &request, std::optional< std::string > const &clientIp, bool isAdmin, boost::asio::yield_context yield)=0
Forward a JSON RPC request to a randomly selected rippled node.
virtual std::vector< std::string > loadInitialLedger(uint32_t sequence, std::chrono::steady_clock::duration retryAfter=std::chrono::seconds{2})=0
Load the initial ledger, writing data to the queue.
virtual void stop(boost::asio::yield_context yield)=0
Stop the load balancer. This will stop all subscription sources.
virtual InitialLedgerLoadResult loadInitialLedger(uint32_t sequence, etlng::InitialLoadObserverInterface &loader, std::chrono::steady_clock::duration retryAfter=std::chrono::seconds{2})=0
Load the initial ledger, writing data to the queue.
virtual boost::json::value toJson() const =0
Represent the state of this load balancer as a JSON object.
virtual std::optional< etl::ETLState > getETLState() noexcept=0
Return state of ETL nodes.
virtual OptionalGetLedgerResponseType fetchLedger(uint32_t ledgerSequence, bool getObjects, bool getObjectNeighbors, std::chrono::steady_clock::duration retryAfter=std::chrono::seconds{2})=0
Fetch data for a specific ledger.
The interface for observing the initial ledger load.
Definition InitialLoadObserverInterface.hpp:36