rippled
Public Member Functions | Private Member Functions | Private Attributes | List of all members
ripple::ETLLoadBalancer Class Reference

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). More...

Collaboration diagram for ripple::ETLLoadBalancer:
Collaboration graph
[legend]

Public Member Functions

 ETLLoadBalancer (ReportingETL &etl)
 
void add (std::string &host, std::string &websocketPort, std::string &grpcPort)
 Add an ETL source. More...
 
void add (std::string &host, std::string &websocketPort)
 Add an ETL source without gRPC support. More...
 
void loadInitialLedger (uint32_t sequence, ThreadSafeQueue< std::shared_ptr< SLE >> &writeQueue)
 Load the initial ledger, writing data to the queue. More...
 
std::optional< org::xrpl::rpc::v1::GetLedgerResponse > fetchLedger (uint32_t ledgerSequence, bool getObjects)
 Fetch data for a specific ledger. More...
 
void start ()
 Setup all of the ETL sources and subscribe to the necessary streams. More...
 
void stop ()
 
bool shouldPropagateStream (ETLSource *in) const
 Determine whether messages received on the transactions_proposed stream should be forwarded to subscribing clients. More...
 
Json::Value toJson () const
 
std::unique_ptr< org::xrpl::rpc::v1::XRPLedgerAPIService::Stub > getP2pForwardingStub () const
 Randomly select a p2p node to forward a gRPC request to. More...
 
Json::Value forwardToP2p (RPC::JsonContext &context) const
 Forward a JSON RPC request to a randomly selected p2p node. More...
 

Private Member Functions

template<class Func >
bool execute (Func f, uint32_t ledgerSequence)
 f is a function that takes an ETLSource as an argument and returns a bool. More...
 

Private Attributes

ReportingETLetl_
 
beast::Journal journal_
 
std::vector< std::unique_ptr< ETLSource > > sources_
 

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.

Definition at line 315 of file ETLSource.h.

Constructor & Destructor Documentation

◆ ETLLoadBalancer()

ripple::ETLLoadBalancer::ETLLoadBalancer ( ReportingETL etl)

Definition at line 650 of file ETLSource.cpp.

Member Function Documentation

◆ add() [1/2]

void ripple::ETLLoadBalancer::add ( std::string host,
std::string websocketPort,
std::string grpcPort 
)

Add an ETL source.

Parameters
hosthost or ip of ETL source
websocketPortport where ETL source accepts websocket connections
grpcPortport where ETL source accepts gRPC requests

Definition at line 657 of file ETLSource.cpp.

◆ add() [2/2]

void ripple::ETLLoadBalancer::add ( std::string host,
std::string websocketPort 
)

Add an ETL source without gRPC support.

This source will send messages on the ledgers and transactions_proposed streams, but will not be able to handle the gRPC requests that are used for ETL

Parameters
hosthost or ip of ETL source
websocketPortport where ETL source accepts websocket connections

Definition at line 670 of file ETLSource.cpp.

◆ loadInitialLedger()

void ripple::ETLLoadBalancer::loadInitialLedger ( uint32_t  sequence,
ThreadSafeQueue< std::shared_ptr< SLE >> &  writeQueue 
)

Load the initial ledger, writing data to the queue.

Parameters
sequencesequence of ledger to download
writeQueuequeue to push downloaded data to

Definition at line 680 of file ETLSource.cpp.

◆ fetchLedger()

std::optional< org::xrpl::rpc::v1::GetLedgerResponse > ripple::ETLLoadBalancer::fetchLedger ( uint32_t  ledgerSequence,
bool  getObjects 
)

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 ledger to fetch data for
getObjectsif true, fetch diff between specified ledger and previous
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

Definition at line 699 of file ETLSource.cpp.

◆ start()

void ripple::ETLLoadBalancer::start ( )

Setup all of the ETL sources and subscribe to the necessary streams.

Definition at line 969 of file ETLSource.cpp.

◆ stop()

void ripple::ETLLoadBalancer::stop ( )

Definition at line 976 of file ETLSource.cpp.

◆ shouldPropagateStream()

bool ripple::ETLLoadBalancer::shouldPropagateStream ( ETLSource in) const

Determine whether messages received on the transactions_proposed stream should be forwarded to subscribing clients.

The server subscribes to transactions_proposed, validations, and manifests on multiple ETLSources, yet only forwards messages from one source at any given time (to avoid sending duplicate messages to clients).

Parameters
inETLSource in question
Returns
true if messages should be forwarded

Definition at line 377 of file ETLSource.h.

◆ toJson()

Json::Value ripple::ETLLoadBalancer::toJson ( ) const

Definition at line 397 of file ETLSource.h.

◆ getP2pForwardingStub()

std::unique_ptr< org::xrpl::rpc::v1::XRPLedgerAPIService::Stub > ripple::ETLLoadBalancer::getP2pForwardingStub ( ) const

Randomly select a p2p node to forward a gRPC request to.

Returns
gRPC stub to forward requests to p2p node

Definition at line 733 of file ETLSource.cpp.

◆ forwardToP2p()

Json::Value ripple::ETLLoadBalancer::forwardToP2p ( RPC::JsonContext context) const

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

Parameters
contextcontext of the request
Returns
response received from p2p node

Definition at line 755 of file ETLSource.cpp.

◆ execute()

template<class Func >
bool ripple::ETLLoadBalancer::execute ( Func  f,
uint32_t  ledgerSequence 
)
private

f is a function that takes an ETLSource as an argument and returns a bool.

Attempt to execute f for one randomly chosen ETLSource that has the specified ledger. If f returns false, another randomly chosen ETLSource is used. The process repeats until f returns true.

Parameters
ffunction to execute. This function takes the ETL source as an argument, and returns a bool.
ledgerSequencef is executed for each ETLSource that has this ledger
Returns
true if f was eventually executed successfully. false if the ledger was found in the database or the server is shutting down

Definition at line 898 of file ETLSource.cpp.

Member Data Documentation

◆ etl_

ReportingETL& ripple::ETLLoadBalancer::etl_
private

Definition at line 318 of file ETLSource.h.

◆ journal_

beast::Journal ripple::ETLLoadBalancer::journal_
private

Definition at line 320 of file ETLSource.h.

◆ sources_

std::vector<std::unique_ptr<ETLSource> > ripple::ETLLoadBalancer::sources_
private

Definition at line 322 of file ETLSource.h.