20 #include <ripple/app/ledger/Ledger.h>
21 #include <ripple/basics/chrono.h>
22 #include <ripple/beast/core/CurrentThreadName.h>
23 #include <ripple/json/json_value.h>
24 #include <ripple/nodestore/Database.h>
25 #include <ripple/protocol/HashPrefix.h>
26 #include <ripple/protocol/jss.h>
41 , scheduler_(scheduler)
46 Throw<std::runtime_error>(
"Invalid earliest_seq");
48 while (readThreads-- > 0)
101 read_[hash].emplace_back(ledgerSeq, std::move(cb));
110 auto storeBatch = [&]() {
117 JLOG(
j_.
error()) <<
"Exception caught in function " << __func__
118 <<
". Error: " << e.
what();
123 for (
auto const& nodeObject : batch)
124 sz += nodeObject->getData().size();
153 auto const begin{steady_clock::now()};
159 fetchSz_ += nodeObject->getData().size();
164 duration_cast<milliseconds>(steady_clock::now() - begin);
175 JLOG(
j_.
error()) <<
"Source ledger sequence " << srcLedger.
info().
seq
181 return fail(
"Invalid hash");
183 return fail(
"Invalid account hash");
187 return fail(
"Source and destination databases are the same");
191 auto storeBatch = [&]() {
193 for (
auto const& nodeObject : batch)
194 sz += nodeObject->getData().size();
198 dstBackend->storeBatch(batch);
203 std::string(
"Exception caught in function ") + __func__ +
204 ". Error: " + e.
what());
227 if (
auto nodeObject = srcDB.fetchNodeObject(
228 node.getHash().as_uint256(), srcLedger.
info().
seq))
244 return fail(
"Invalid state map");
248 return fail(
"Failed to store state map");
255 return fail(
"Invalid transaction map");
259 return fail(
"Failed to store transaction map");
262 if (!batch.
empty() && !storeBatch())
263 return fail(
"Failed to store");
293 if (it ==
read_.end())
298 lastHash = it->first;
299 entry = std::move(it->second);
304 auto seq = entry[0].first;
307 for (
auto const& req : entry)
309 if ((seq == req.first) ||
isSameDB(req.first, seq))
333 obj[jss::node_writes_duration_us] =
std::to_string(c.writeDurationUs);
Holds a collection of configuration values.
@ ledgerMaster
ledger master data for signing
std::atomic< std::uint64_t > fetchDurationUs_
Persistency layer for NodeObject.
SHAMapHash getHash() const
void stopped()
Called by derived classes to indicate that the stoppable has stopped.
Family const & family() const
void addRaw(LedgerInfo const &info, Serializer &s, bool includeHash)
virtual Counters const & counters() const =0
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.
virtual Backend & getBackend()=0
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.
std::shared_ptr< SHAMap > snapShot(bool isMutable) const
std::atomic< std::uint32_t > fetchHitCount_
virtual NodeStore::Database & db()=0
std::atomic< std::uint64_t > storeCount_
@ batchWritePreallocationSize
void onChildrenStopped() override
Override called when all children have stopped.
std::atomic< std::uint64_t > storeSz_
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.
void getCountsJson(Json::Value &obj)
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.