1#include <xrpl/basics/chrono.h>
2#include <xrpl/beast/core/CurrentThreadName.h>
3#include <xrpl/json/json_value.h>
4#include <xrpl/nodestore/Database.h>
5#include <xrpl/protocol/HashPrefix.h>
6#include <xrpl/protocol/jss.h>
19 , scheduler_(scheduler)
22 , requestBundle_(
get<int>(config,
"rq_bundle", 4))
23 , readThreads_(
std::max(1, readThreads))
27 "ripple::NodeStore::Database::Database : nonzero threads input");
30 Throw<std::runtime_error>(
"Invalid earliest_seq");
32 if (requestBundle_ < 1 || requestBundle_ > 64)
33 Throw<std::runtime_error>(
"Invalid rq_bundle");
72 for (
auto it =
read.begin(); it !=
read.end(); ++it)
76 "ripple::NodeStore::Database::Database : non-empty "
79 auto const& hash = it->first;
80 auto const& data = it->second;
81 auto const seqn = data[0].first;
91 for (
auto const& req : data)
94 (seqn == req.first) ||
isSameDB(req.first, seqn)
137 JLOG(
j_.
debug()) <<
"Clearing read queue because of stop request";
143 JLOG(
j_.
debug()) <<
"Waiting for stop request to complete...";
147 auto const start = steady_clock::now();
152 steady_clock::now() - start < 30s,
153 "ripple::NodeStore::Database::stop : maximum stop duration");
157 JLOG(
j_.
debug()) <<
"Stop request completed in "
158 << duration_cast<std::chrono::milliseconds>(
159 steady_clock::now() - start)
174 read_[
hash].emplace_back(ledgerSeq, std::move(cb));
184 auto storeBatch = [&, fname = __func__]() {
191 JLOG(
j_.
error()) <<
"Exception caught in function " << fname
192 <<
". Error: " << e.
what();
197 for (
auto const& nodeObject :
batch)
198 sz += nodeObject->getData().size();
206 "ripple::NodeStore::Database::importInternal : non-null node");
210 batch.emplace_back(std::move(nodeObject));
230 auto const begin{steady_clock::now()};
233 auto dur = steady_clock::now() - begin;
238 fetchSz_ += nodeObject->getData().size();
242 fetchReport.
elapsed = duration_cast<milliseconds>(dur);
252 "ripple::NodeStore::Database::getCountsJson : valid input type");
A generic endpoint for log messages.
A backend used for the NodeStore.
virtual void storeBatch(Batch const &batch)=0
Store a group of objects.
Persistency layer for NodeObject.
void getCountsJson(Json::Value &obj)
std::atomic< std::uint32_t > fetchSz_
void storeStats(std::uint64_t count, std::uint64_t sz)
virtual void asyncFetch(uint256 const &hash, std::uint32_t ledgerSeq, std::function< void(std::shared_ptr< NodeObject > const &)> &&callback)
Fetch an object without waiting.
virtual void for_each(std::function< void(std::shared_ptr< NodeObject >)> f)=0
Visit every object in the database This is usually called during import.
virtual ~Database()
Destroy the node store.
std::condition_variable readCondVar_
std::atomic< std::uint64_t > storeCount_
std::uint32_t const earliestLedgerSeq_
std::map< uint256, std::vector< std::pair< std::uint32_t, std::function< void(std::shared_ptr< NodeObject > const &)> > > > read_
std::atomic< std::uint64_t > storeSz_
std::shared_ptr< NodeObject > fetchNodeObject(uint256 const &hash, std::uint32_t ledgerSeq=0, FetchType fetchType=FetchType::synchronous, bool duplicate=false)
Fetch a node object.
std::atomic< bool > readStopping_
std::atomic< std::uint32_t > fetchHitCount_
std::atomic< std::uint64_t > fetchDurationUs_
std::atomic< int > runningThreads_
virtual bool isSameDB(std::uint32_t s1, std::uint32_t s2)=0
std::atomic< std::uint64_t > fetchTotalCount_
std::atomic< int > readThreads_
void importInternal(Backend &dstBackend, Database &srcDB)
Scheduling for asynchronous backend activity.
virtual void onFetch(FetchReport const &report)=0
Reports completion of a fetch Allows the scheduler to monitor the node store's performance.
Holds a collection of configuration values.
void setCurrentThreadName(std::string_view newThreadName)
Changes the name of the caller thread.
void read(nudb::detail::istream &is, std::size_t &u)
@ batchWritePreallocationSize
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
static constexpr std::uint32_t XRP_LEDGER_EARLIEST_SEQ
The XRP ledger network's earliest allowed sequence.
T get(Section const §ion, std::string const &name, T const &defaultValue=T{})
Retrieve a key/value pair from a section.
Contains information about a fetch operation.
std::chrono::milliseconds elapsed