20 #include <ripple/app/ledger/Ledger.h>
21 #include <ripple/basics/chrono.h>
22 #include <ripple/beast/core/CurrentThreadName.h>
23 #include <ripple/nodestore/Database.h>
24 #include <ripple/protocol/HashPrefix.h>
38 , scheduler_(scheduler)
43 Throw<std::runtime_error>(
"Invalid earliest_seq");
45 while (readThreads-- > 0)
98 read_[hash].emplace_back(ledgerSeq, std::move(cb));
107 auto storeBatch = [&]() {
114 JLOG(
j_.
error()) <<
"Exception caught in function " << __func__
115 <<
". Error: " << e.
what();
120 for (
auto const& nodeObject : batch)
121 sz += nodeObject->getData().size();
150 auto const begin{steady_clock::now()};
156 fetchSz_ += nodeObject->getData().size();
161 duration_cast<milliseconds>(steady_clock::now() - begin);
172 JLOG(
j_.
error()) <<
"Source ledger sequence " << srcLedger.
info().
seq
178 return fail(
"Invalid hash");
180 return fail(
"Invalid account hash");
184 return fail(
"Source and destination databases are the same");
188 auto storeBatch = [&]() {
190 for (
auto const& nodeObject : batch)
191 sz += nodeObject->getData().size();
195 dstBackend->storeBatch(batch);
200 std::string(
"Exception caught in function ") + __func__ +
201 ". Error: " + e.
what());
224 if (
auto nodeObject = srcDB.fetchNodeObject(
225 node.getHash().as_uint256(), srcLedger.
info().
seq))
241 return fail(
"Invalid state map");
245 return fail(
"Failed to store state map");
252 return fail(
"Invalid transaction map");
256 return fail(
"Failed to store transaction map");
259 if (!batch.
empty() && !storeBatch())
260 return fail(
"Failed to store");
290 if (it ==
read_.end())
295 lastHash = it->first;
296 entry = std::move(it->second);
301 auto seq = entry[0].first;
304 for (
auto const& req : entry)
306 if ((seq == req.first) ||
isSameDB(req.first, seq))
Holds a collection of configuration values.
@ ledgerMaster
ledger master data for signing
Persistency layer for NodeObject.
SHAMapHash getHash() const
void stopped()
Called by derived classes to indicate that the stoppable has stopped.
Family const & family() const
std::map< uint256, std::vector< std::pair< std::uint32_t, std::function< void(std::shared_ptr< NodeObject > const &)> > > > read_
static std::shared_ptr< NodeObject > createObject(NodeObjectType type, Blob &&data, uint256 const &hash)
Create an object from fields.
std::atomic< std::uint64_t > fetchTotalCount_
void asyncFetch(uint256 const &hash, std::uint32_t ledgerSeq, std::function< void(std::shared_ptr< NodeObject > const &)> &&callback)
Fetch an object without waiting.
std::atomic< std::uint32_t > fetchSz_
Contains information about a fetch operation.
void addRaw(LedgerInfo const &info, Serializer &s)
std::shared_ptr< SHAMap > snapShot(bool isMutable) const
std::atomic< std::uint32_t > fetchHitCount_
virtual NodeStore::Database & db()=0
@ batchWritePreallocationSize
void onChildrenStopped() override
Override called when all children have stopped.
LedgerInfo const & info() const override
Returns information about the ledger.
Provides an interface for starting and stopping.
void importInternal(Backend &dstBackend, Database &srcDB)
SHAMap const & stateMap() const
std::condition_variable readCondVar_
virtual void onFetch(FetchReport const &report)=0
Reports completion of a fetch Allows the scheduler to monitor the node store's performance.
A generic endpoint for log messages.
Scheduling for asynchronous backend activity.
std::shared_ptr< NodeObject > fetchNodeObject(uint256 const &hash, std::uint32_t ledgerSeq=0, FetchType fetchType=FetchType::synchronous)
Fetch a node object.
virtual ~Database()
Destroy the node store.
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.
void storeStats(std::uint64_t count, std::uint64_t sz)
SHAMap const & txMap() const
void setCurrentThreadName(std::string_view name)
Changes the name of the caller thread.
T emplace_back(T... args)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
void onStop() override
Override called when the stop notification is issued.
virtual bool storeLedger(std::shared_ptr< Ledger const > const &srcLedger)=0
Store a ledger from a different database.
std::vector< std::thread > readThreads_
static constexpr std::uint32_t XRP_LEDGER_EARLIEST_SEQ
The XRP ledger network's earliest allowed sequence.
const std::uint32_t earliestLedgerSeq_
int add32(std::uint32_t i)
Information about the notional ledger backing the view.
virtual bool isSameDB(std::uint32_t s1, std::uint32_t s2)=0
virtual void storeBatch(Batch const &batch)=0
Store a group of objects.
std::chrono::milliseconds elapsed
T & get(EitherAmount &amt)
bool isStopping() const
Returns true if the stoppable should stop.
A backend used for the NodeStore.