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

Publishes ledgers in a synchronized fashion. More...

#include <LedgerPublisher.hpp>

Inheritance diagram for etl::impl::LedgerPublisher:
Collaboration diagram for etl::impl::LedgerPublisher:

Public Member Functions

 LedgerPublisher (util::async::AnyExecutionContext ctx, std::shared_ptr< BackendInterface > backend, std::shared_ptr< feed::SubscriptionManagerInterface > subscriptions, SystemState const &state, std::chrono::steady_clock::duration maxWaitForDbProgress=kDefaultMaxWaitForDbProgress)
 Create an instance of the publisher.
bool publish (uint32_t ledgerSequence, std::optional< uint32_t > maxAttempts, std::chrono::steady_clock::duration attemptsDelay=std::chrono::seconds{1}) override
 Attempt to read the specified ledger from the database, and then publish that ledger to the ledgers stream.
void publish (xrpl::LedgerHeader const &lgrInfo)
 Publish the passed ledger asynchronously.
std::uint32_t lastPublishAgeSeconds () const override
 Get time passed since last publish, in seconds.
std::chrono::time_point< std::chrono::system_clock > getLastPublish () const override
 Get last publish time as a time point.
std::uint32_t lastCloseAgeSeconds () const override
 Get time passed since last ledger close, in seconds.
std::optional< uint32_t > getLastPublishedSequence () const
 Get the sequence of the last schueduled ledger to publish, Be aware that the ledger may not have been published to network.
void stop () override
 Stops publishing.

Static Public Attributes

static constexpr std::chrono::steady_clock::duration kDefaultMaxWaitForDbProgress
 Default for how long publish() waits while the DB is reachable but stays behind the requested ledger without making progress.

Detailed Description

Publishes ledgers in a synchronized fashion.

If ETL is started far behind the network, ledgers will be written and published very rapidly. Monitoring processes will publish ledgers as they are written. However, to publish a ledger, the monitoring process needs to read all of the transactions for that ledger from the database. Reading the transactions from the database requires network calls, which can be slow. It is imperative however that the monitoring processes keep up with the writer, else the monitoring processes will not be able to detect if the writer failed. Therefore, publishing each ledger (which includes reading all of the transactions from the database) is done from the application wide asio io_service, and a strand is used to ensure ledgers are published in order.

Constructor & Destructor Documentation

◆ LedgerPublisher()

etl::impl::LedgerPublisher::LedgerPublisher ( util::async::AnyExecutionContext ctx,
std::shared_ptr< BackendInterface > backend,
std::shared_ptr< feed::SubscriptionManagerInterface > subscriptions,
SystemState const & state,
std::chrono::steady_clock::duration maxWaitForDbProgress = kDefaultMaxWaitForDbProgress )
inline

Create an instance of the publisher.

Parameters
ctxThe execution context used for the publishing strand
backendThe backend to read ledgers from
subscriptionsThe subscription manager to publish ledgers to
stateThe shared ETL state
maxWaitForDbProgressHow long publish() waits while the DB stays behind the requested ledger without making progress before asserting

Member Function Documentation

◆ getLastPublish()

std::chrono::time_point< std::chrono::system_clock > etl::impl::LedgerPublisher::getLastPublish ( ) const
inlineoverridevirtual

Get last publish time as a time point.

Implements etl::LedgerPublisherInterface.

◆ lastCloseAgeSeconds()

std::uint32_t etl::impl::LedgerPublisher::lastCloseAgeSeconds ( ) const
inlineoverridevirtual

Get time passed since last ledger close, in seconds.

Implements etl::LedgerPublisherInterface.

◆ lastPublishAgeSeconds()

std::uint32_t etl::impl::LedgerPublisher::lastPublishAgeSeconds ( ) const
inlineoverridevirtual

Get time passed since last publish, in seconds.

Implements etl::LedgerPublisherInterface.

◆ publish() [1/2]

bool etl::impl::LedgerPublisher::publish ( uint32_t ledgerSequence,
std::optional< uint32_t > maxAttempts,
std::chrono::steady_clock::duration attemptsDelay = std::chrono::seconds{1} )
inlineoverridevirtual

Attempt to read the specified ledger from the database, and then publish that ledger to the ledgers stream.

The caller must only request ledgers that it has already seen committed to the database. While the ledger range can't be fetched, this waits indefinitely (until stop() is called). If the range is fetched but stays behind the requested ledger without progressing for longer than the configured maximum wait, the invariant is considered broken and this asserts: a restart is then the only way for the node to recover.

Parameters
ledgerSequencethe sequence of the ledger to publish
maxAttemptsthe number of times to attempt to read the ledger from the database
attemptsDelaythe delay between attempts to read the ledger from the database
Returns
Whether the ledger was found in the database and published

Implements etl::LedgerPublisherInterface.

◆ publish() [2/2]

void etl::impl::LedgerPublisher::publish ( xrpl::LedgerHeader const & lgrInfo)
inline

Publish the passed ledger asynchronously.

All ledgers are published thru publishStrand_ which ensures that all publishes are performed in a serial fashion.

Parameters
lgrInfothe ledger to publish

◆ stop()

void etl::impl::LedgerPublisher::stop ( )
inlineoverridevirtual

Stops publishing.

Any ongoing or future publish(seq, ...) call returns false without waiting for the ledger to appear in the database.

Implements etl::LedgerPublisherInterface.

Member Data Documentation

◆ kDefaultMaxWaitForDbProgress

std::chrono::steady_clock::duration etl::impl::LedgerPublisher::kDefaultMaxWaitForDbProgress
staticconstexpr
Initial value:
=
std::chrono::minutes{5}

Default for how long publish() waits while the DB is reachable but stays behind the requested ledger without making progress.


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