20 #include <ripple/nodestore/Database.h>
21 #include <ripple/app/ledger/Ledger.h>
22 #include <ripple/basics/chrono.h>
23 #include <ripple/beast/core/CurrentThreadName.h>
24 #include <ripple/protocol/HashPrefix.h>
38 , scheduler_(scheduler)
39 , earliestLedgerSeq_(
get<
std::uint32_t>(
45 Throw<std::runtime_error>(
"Invalid earliest_seq");
47 while (readThreads-- > 0)
129 status = backend->fetch(hash.
begin(), &nObj);
134 "Exception, " << e.
what();
150 "Corrupt NodeObject #" << hash;
154 "Unknown status=" << status;
198 auto const before = steady_clock::now();
201 auto nObj = pCache.
fetch(hash);
211 nObj = pCache.
fetch(hash);
223 "HOS: " << hash <<
" fetch: in db";
226 report.
wasFound =
static_cast<bool>(nObj);
227 report.
elapsed = duration_cast<milliseconds>(
228 steady_clock::now() - before);
241 assert(
static_cast<bool>(dstPCache) ==
static_cast<bool>(dstNCache));
247 "source ledger seq " << srcLedger.
info().
seq <<
251 auto& srcDB =
const_cast<Database&
>(
257 "source and destination databases are the same";
263 auto storeBatch = [&]() {
264 if (dstPCache && dstNCache)
266 for (
auto& nObj : batch)
268 dstPCache->canonicalize_replace_cache(nObj->getHash(), nObj);
269 dstNCache->erase(nObj->getHash());
273 dstBackend->storeBatch(batch);
280 if (
auto nObj = srcDB.fetch(
281 node.getNodeHash().as_uint256(), srcLedger.
info().
seq))
313 "source ledger seq " << srcLedger.
info().
seq <<
314 " state map invalid";
317 if (next && next->info().parentHash == srcLedger.
info().
hash)
319 auto have = next->stateMap().snapShot(
false);
321 false)->visitDifferences(&(*have), visit);
335 "source ledger seq " << srcLedger.
info().
seq <<
336 " transaction map invalid";
373 if (it ==
read_.end())
380 lastHash = it->first;
381 lastSeq = std::get<0>(it->second);
382 lastPcache = std::get<1>(it->second).lock();
383 lastNcache = std::get<2>(it->second).lock();
389 if (lastPcache && lastNcache)
390 doFetch(lastHash, lastSeq, *lastPcache, *lastNcache,
true);
Holds a collection of configuration values.
@ ledgerMaster
ledger master data for signing
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::map< uint256, std::tuple< std::uint32_t, std::weak_ptr< TaggedCache< uint256, NodeObject > >, std::weak_ptr< KeyCache< uint256 > > > > read_
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_
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.