22#include "data/BackendInterface.hpp"
23#include "util/log/Logger.hpp"
25#include <grpcpp/grpcpp.h>
26#include <xrpl/proto/org/xrpl/rpc/v1/xrp_ledger.grpc.pb.h>
37template <
typename LoadBalancerType>
40 using OptionalGetLedgerResponseType =
typename LoadBalancerType::OptionalGetLedgerResponseType;
45 std::shared_ptr<BackendInterface> backend_;
46 std::shared_ptr<LoadBalancerType> loadBalancer_;
52 LedgerFetcher(std::shared_ptr<BackendInterface> backend, std::shared_ptr<LoadBalancerType> balancer)
53 : backend_(std::move(backend)), loadBalancer_(std::move(balancer))
66 [[nodiscard]] OptionalGetLedgerResponseType
69 LOG(log_.
debug()) <<
"Attempting to fetch ledger with sequence = " << sequence;
71 auto response = loadBalancer_->fetchLedger(sequence,
false,
false);
73 LOG(log_.
trace()) <<
"GetLedger reply = " << response->DebugString();
86 [[nodiscard]] OptionalGetLedgerResponseType
89 LOG(log_.
debug()) <<
"Attempting to fetch ledger with sequence = " << sequence;
91 auto const isCacheFull = backend_->cache().isFull();
92 auto const isLedgerCached = backend_->cache().latestLedgerSequence() >= sequence;
94 LOG(log_.
info()) << sequence <<
" is already cached, the current latest seq in cache is "
95 << backend_->cache().latestLedgerSequence() <<
" and the cache is "
96 << (isCacheFull ?
"full" :
"not full");
99 auto response = loadBalancer_->fetchLedger(sequence,
true, !isCacheFull || isLedgerCached);
101 LOG(log_.
trace()) <<
"GetLedger reply = " << response->DebugString();
GRPC Ledger data fetcher.
Definition LedgerFetcher.hpp:38
LedgerFetcher(std::shared_ptr< BackendInterface > backend, std::shared_ptr< LoadBalancerType > balancer)
Create an instance of the fetcher.
Definition LedgerFetcher.hpp:52
OptionalGetLedgerResponseType fetchDataAndDiff(uint32_t sequence)
Extract diff data for a particular ledger from an ETL source.
Definition LedgerFetcher.hpp:87
OptionalGetLedgerResponseType fetchData(uint32_t sequence)
Extract data for a particular ledger from an ETL source.
Definition LedgerFetcher.hpp:67
A simple thread-safe logger for the channel specified in the constructor.
Definition Logger.hpp:110
Pump debug(SourceLocationType const &loc=CURRENT_SRC_LOCATION) const
Interface for logging at Severity::DBG severity.
Definition Logger.cpp:200
Pump trace(SourceLocationType const &loc=CURRENT_SRC_LOCATION) const
Interface for logging at Severity::TRC severity.
Definition Logger.cpp:195
Pump info(SourceLocationType const &loc=CURRENT_SRC_LOCATION) const
Interface for logging at Severity::NFO severity.
Definition Logger.cpp:205