Clio develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
etl::LoadBalancer Class Reference

This class is used to manage connections to transaction processing processes. More...

#include <LoadBalancer.hpp>

Inheritance diagram for etl::LoadBalancer:
Collaboration diagram for etl::LoadBalancer:

Public Types

using RawLedgerObjectType = org::xrpl::rpc::v1::RawLedgerObject
 
using GetLedgerResponseType = org::xrpl::rpc::v1::GetLedgerResponse
 
using OptionalGetLedgerResponseType = std::optional<GetLedgerResponseType>
 

Public Member Functions

 LoadBalancer (util::config::ClioConfigDefinition const &config, boost::asio::io_context &ioc, std::shared_ptr< BackendInterface > backend, std::shared_ptr< feed::SubscriptionManagerInterface > subscriptions, std::shared_ptr< NetworkValidatedLedgersInterface > validatedLedgers, SourceFactory sourceFactory=makeSource)
 Create an instance of the load balancer.
 
std::vector< std::string > loadInitialLedger (uint32_t sequence, bool cacheOnly=false, std::chrono::steady_clock::duration retryAfter=std::chrono::seconds{2})
 Load the initial ledger, writing data to the queue.
 
OptionalGetLedgerResponseType fetchLedger (uint32_t ledgerSequence, bool getObjects, bool getObjectNeighbors, std::chrono::steady_clock::duration retryAfter=std::chrono::seconds{2})
 Fetch data for a specific ledger.
 
boost::json::value toJson () const
 Represent the state of this load balancer as a JSON object.
 
std::expected< boost::json::object, rpc::ClioErrorforwardToRippled (boost::json::object const &request, std::optional< std::string > const &clientIp, bool isAdmin, boost::asio::yield_context yield)
 Forward a JSON RPC request to a randomly selected rippled node.
 
std::optional< ETLStategetETLState () noexcept
 Return state of ETL nodes.
 
void stop (boost::asio::yield_context yield)
 Stop the load balancer. This will stop all subscription sources.
 
- Public Member Functions inherited from etl::LoadBalancerTag

Static Public Member Functions

static std::shared_ptr< LoadBalancermakeLoadBalancer (util::config::ClioConfigDefinition const &config, boost::asio::io_context &ioc, std::shared_ptr< BackendInterface > backend, std::shared_ptr< feed::SubscriptionManagerInterface > subscriptions, std::shared_ptr< NetworkValidatedLedgersInterface > validatedLedgers, SourceFactory sourceFactory=makeSource)
 A factory function for the load balancer.
 

Static Public Attributes

static constexpr std::string_view kADMIN_FORWARDING_X_USER_VALUE = "clio_admin"
 Value for the X-User header when forwarding admin requests.
 
static constexpr std::string_view kUSER_FORWARDING_X_USER_VALUE = "clio_user"
 Value for the X-User header when forwarding user requests.
 

Detailed Description

This class is used to manage connections to transaction processing processes.

This class spawns a listener for each etl source, which listens to messages on the ledgers stream (to keep track of which ledgers have been validated by the network, and the range of ledgers each etl source has). This class also allows requests for ledger data to be load balanced across all possible ETL sources.

Constructor & Destructor Documentation

◆ LoadBalancer()

etl::LoadBalancer::LoadBalancer ( util::config::ClioConfigDefinition const & config,
boost::asio::io_context & ioc,
std::shared_ptr< BackendInterface > backend,
std::shared_ptr< feed::SubscriptionManagerInterface > subscriptions,
std::shared_ptr< NetworkValidatedLedgersInterface > validatedLedgers,
SourceFactory sourceFactory = makeSource )

Create an instance of the load balancer.

Parameters
configThe configuration to use
iocThe io_context to run on
backendBackendInterface implementation
subscriptionsSubscription manager
validatedLedgersThe network validated ledgers datastructure
sourceFactoryA factory function to create a source

Member Function Documentation

◆ fetchLedger()

LoadBalancer::OptionalGetLedgerResponseType etl::LoadBalancer::fetchLedger ( uint32_t ledgerSequence,
bool getObjects,
bool getObjectNeighbors,
std::chrono::steady_clock::duration retryAfter = std::chrono::seconds{2} )

Fetch data for a specific ledger.

This function will continuously try to fetch data for the specified ledger until the fetch succeeds, the ledger is found in the database, or the server is shutting down.

Parameters
ledgerSequenceSequence of the ledger to fetch
getObjectsWhether to get the account state diff between this ledger and the prior one
getObjectNeighborsWhether to request object neighbors
retryAfterTime to wait between retries (2 seconds by default)
Returns
The extracted data, if extraction was successful. If the ledger was found in the database or the server is shutting down, the optional will be empty

◆ forwardToRippled()

std::expected< boost::json::object, rpc::ClioError > etl::LoadBalancer::forwardToRippled ( boost::json::object const & request,
std::optional< std::string > const & clientIp,
bool isAdmin,
boost::asio::yield_context yield )

Forward a JSON RPC request to a randomly selected rippled node.

Parameters
requestJSON-RPC request to forward
clientIpThe IP address of the peer, if known
isAdminWhether the request is from an admin
yieldThe coroutine context
Returns
Response received from rippled node as JSON object on success or error on failure

◆ getETLState()

std::optional< ETLState > etl::LoadBalancer::getETLState ( )
noexcept

Return state of ETL nodes.

Returns
ETL state, nullopt if etl nodes not available

◆ loadInitialLedger()

std::vector< std::string > etl::LoadBalancer::loadInitialLedger ( uint32_t sequence,
bool cacheOnly = false,
std::chrono::steady_clock::duration retryAfter = std::chrono::seconds{2} )

Load the initial ledger, writing data to the queue.

Note
This function will retry indefinitely until the ledger is downloaded.
Parameters
sequenceSequence of ledger to download
cacheOnlyWhether to only write to cache and not to the DB; defaults to false
retryAfterTime to wait between retries (2 seconds by default)
Returns
A std::vector<std::string> The ledger data

◆ makeLoadBalancer()

std::shared_ptr< LoadBalancer > etl::LoadBalancer::makeLoadBalancer ( util::config::ClioConfigDefinition const & config,
boost::asio::io_context & ioc,
std::shared_ptr< BackendInterface > backend,
std::shared_ptr< feed::SubscriptionManagerInterface > subscriptions,
std::shared_ptr< NetworkValidatedLedgersInterface > validatedLedgers,
SourceFactory sourceFactory = makeSource )
static

A factory function for the load balancer.

Parameters
configThe configuration to use
iocThe io_context to run on
backendBackendInterface implementation
subscriptionsSubscription manager
validatedLedgersThe network validated ledgers datastructure
sourceFactoryA factory function to create a source
Returns
A shared pointer to a new instance of LoadBalancer

◆ stop()

void etl::LoadBalancer::stop ( boost::asio::yield_context yield)

Stop the load balancer. This will stop all subscription sources.

Note
This function will asynchronously wait for all sources to stop.
Parameters
yieldThe coroutine context

◆ toJson()

boost::json::value etl::LoadBalancer::toJson ( ) const

Represent the state of this load balancer as a JSON object.

Returns
JSON representation of the state of this load balancer.

The documentation for this class was generated from the following files: