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)
114 if (
read_.emplace(hash, ledgerSeq).second)
123 auto storeBatch = [&]() {
130 JLOG(
j_.
error()) <<
"Exception caught in function " << __func__
131 <<
". Error: " << e.
what();
136 for (
auto const& nodeObject : batch)
137 sz += nodeObject->getData().size();
166 auto const begin{steady_clock::now()};
172 fetchSz_ += nodeObject->getData().size();
178 duration_cast<milliseconds>(steady_clock::now() - begin);
191 JLOG(
j_.
error()) <<
"Source ledger sequence " << srcLedger.
info().
seq
196 if (!dstPCache || !dstNCache)
197 return fail(
"Invalid destination cache");
199 return fail(
"Invalid hash");
201 return fail(
"Invalid account hash");
205 return fail(
"Source and destination databases are the same");
209 auto storeBatch = [&]() {
211 for (
auto const& nodeObject : batch)
213 dstPCache->canonicalize_replace_cache(
214 nodeObject->getHash(), nodeObject);
215 dstNCache->erase(nodeObject->getHash());
216 sz += nodeObject->getData().size();
221 dstBackend->storeBatch(batch);
226 std::string(
"Exception caught in function ") + __func__ +
227 ". Error: " + e.
what());
250 if (
auto nodeObject = srcDB.fetchNodeObject(
251 node.getHash().as_uint256(), srcLedger.
info().
seq))
267 return fail(
"Invalid state map");
271 return fail(
"Failed to store state map");
278 return fail(
"Invalid transaction map");
282 return fail(
"Failed to store transaction map");
285 if (!batch.
empty() && !storeBatch())
286 return fail(
"Failed to store");
313 if (it ==
read_.end())
320 lastHash = it->first;
321 lastSeq = it->second;
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
static std::shared_ptr< NodeObject > createObject(NodeObjectType type, Blob &&data, uint256 const &hash)
Create an object from fields.
std::atomic< std::uint64_t > fetchTotalCount_
std::atomic< std::uint32_t > fetchSz_
Contains information about a fetch operation.
void addRaw(LedgerInfo const &info, Serializer &s)
std::map< uint256, std::uint32_t > read_
std::shared_ptr< SHAMap > snapShot(bool isMutable) const
std::atomic< std::uint32_t > fetchHitCount_
virtual NodeStore::Database & db()=0
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_
void waitReads()
Wait for all currently pending async reads to complete.
@ batchWritePreallocationSize
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::condition_variable readGenCondVar_
virtual bool asyncFetch(uint256 const &hash, std::uint32_t ledgerSeq, std::shared_ptr< NodeObject > &nodeObject)=0
Fetch an object without waiting.
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.
Maintains a cache of keys with no associated data.
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.