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 Types inherited from etlng::LoadBalancerInterface
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, std::chrono::steady_clock::duration retryAfter=std::chrono::seconds{2}) override
 Load the initial ledger, writing data to the queue.
 
std::vector< std::string > loadInitialLedger (uint32_t sequence, etlng::InitialLoadObserverInterface &observer, std::chrono::steady_clock::duration retryAfter) override
 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}) override
 Fetch data for a specific ledger.
 
boost::json::value toJson () const override
 Represent the state of this load balancer as a JSON object.
 
std::expected< boost::json::object, rpc::CombinedErrorforwardToRippled (boost::json::object const &request, std::optional< std::string > const &clientIp, bool isAdmin, boost::asio::yield_context yield) override
 Forward a JSON RPC request to a randomly selected rippled node.
 
std::optional< ETLStategetETLState () noexcept override
 Return state of ETL nodes.
 
void stop (boost::asio::yield_context yield) override
 Stop the load balancer. This will stop all subscription sources.
 
- Public Member Functions inherited from etlng::LoadBalancerInterface

Static Public Member Functions

static std::shared_ptr< LoadBalancerInterface > 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)
 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} )
overridevirtual

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

Implements etlng::LoadBalancerInterface.

◆ forwardToRippled()

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

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

Implements etlng::LoadBalancerInterface.

◆ getETLState()

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

Return state of ETL nodes.

Returns
ETL state, nullopt if etl nodes not available

Implements etlng::LoadBalancerInterface.

◆ loadInitialLedger() [1/2]

std::vector< std::string > etl::LoadBalancer::loadInitialLedger ( uint32_t sequence,
etlng::InitialLoadObserverInterface & observer,
std::chrono::steady_clock::duration retryAfter )
inlineoverridevirtual

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
observerThe observer to notify of progress
retryAfterTime to wait between retries (2 seconds by default)
Returns
A std::vector<std::string> The ledger data

Implements etlng::LoadBalancerInterface.

◆ loadInitialLedger() [2/2]

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

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
retryAfterTime to wait between retries (2 seconds by default)
Returns
A std::vector<std::string> The ledger data

Implements etlng::LoadBalancerInterface.

◆ makeLoadBalancer()

std::shared_ptr< etlng::LoadBalancerInterface > 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)
overridevirtual

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

Implements etlng::LoadBalancerInterface.

◆ toJson()

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

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

Returns
JSON representation of the state of this load balancer.

Implements etlng::LoadBalancerInterface.


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