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)
129 status = backend->fetch(hash.
begin(), &nObj);
148 JLOG(
j_.
fatal()) <<
"Corrupt NodeObject #" << hash;
151 JLOG(
j_.
warn()) <<
"Unknown status=" << status;
196 auto const before = steady_clock::now();
199 auto nObj = pCache.
fetch(hash);
209 nObj = pCache.
fetch(hash);
220 JLOG(
j_.
trace()) <<
"HOS: " << hash <<
" fetch: in db";
223 report.
wasFound =
static_cast<bool>(nObj);
224 report.
elapsed = duration_cast<milliseconds>(steady_clock::now() - before);
237 assert(
static_cast<bool>(dstPCache) ==
static_cast<bool>(dstNCache));
249 JLOG(
j_.
error()) <<
"source and destination databases are the same";
255 auto storeBatch = [&]() {
256 if (dstPCache && dstNCache)
258 for (
auto& nObj : batch)
260 dstPCache->canonicalize_replace_cache(nObj->getHash(), nObj);
261 dstNCache->erase(nObj->getHash());
265 dstBackend->storeBatch(batch);
271 if (
auto nObj = srcDB.fetch(
272 node.getNodeHash().as_uint256(), srcLedger.
info().
seq))
304 <<
" state map invalid";
307 if (next && next->info().parentHash == srcLedger.
info().
hash)
309 auto have = next->stateMap().snapShot(
false);
325 <<
" transaction map invalid";
362 if (it ==
read_.end())
369 lastHash = it->first;
370 lastSeq = std::get<0>(it->second);
371 lastPcache = std::get<1>(it->second).lock();
372 lastNcache = std::get<2>(it->second).lock();
378 if (lastPcache && lastNcache)
379 doFetch(lastHash, lastSeq, *lastPcache, *lastNcache,
true);
Holds a collection of configuration values.
@ ledgerMaster
ledger master data for signing
std::map< uint256, std::tuple< std::uint32_t, std::weak_ptr< TaggedCache< uint256, NodeObject > >, std::weak_ptr< KeyCache< uint256 > > > > read_
Persistency layer for NodeObject.
SHAMapHash getHash() const
std::shared_ptr< NodeObject > doFetch(uint256 const &hash, std::uint32_t seq, TaggedCache< uint256, NodeObject > &pCache, KeyCache< uint256 > &nCache, bool isAsync)
void stopped()
Called by derived classes to indicate that the stoppable has stopped.
Stream trace() const
Severity stream access functions.
virtual std::shared_ptr< NodeObject > fetchFrom(uint256 const &hash, std::uint32_t seq)=0
Family const & family() const
static std::shared_ptr< NodeObject > createObject(NodeObjectType type, Blob &&data, uint256 const &hash)
Create an object from fields.
std::shared_ptr< T > fetch(const key_type &key)
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
bool touch_if_exists(KeyComparable const &key)
Refresh the last access time on a key if present.
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)
bool insert(Key const &key)
Insert the specified key.
void Rethrow()
Rethrow the exception currently being handled.
SHAMap const & stateMap() const
std::condition_variable readCondVar_
void waitReads()
Wait for all currently pending async reads to complete.
void storeStats(size_t sz)
@ 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.
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.
std::shared_ptr< NodeObject > fetchInternal(uint256 const &hash, std::shared_ptr< Backend > backend)
Status
Return codes from Backend operations.
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
Copies a ledger stored in a different database to this one.
std::condition_variable readGenCondVar_
std::atomic< std::uint32_t > storeCount_
std::vector< std::thread > readThreads_
static constexpr std::uint32_t XRP_LEDGER_EARLIEST_SEQ
The XRP ledger network's earliest allowed sequence.
virtual bool asyncFetch(uint256 const &hash, std::uint32_t seq, std::shared_ptr< NodeObject > &object)=0
Fetch an object without waiting.
const std::uint32_t earliestLedgerSeq_
std::atomic< std::uint32_t > fetchTotalCount_
std::atomic< std::uint32_t > storeSz_
int add32(std::uint32_t i)
Information about the notional ledger backing the view.
bool canonicalize_replace_client(const key_type &key, std::shared_ptr< T > &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.