#include namespace xrpl { namespace NodeStore { void DatabaseNodeImp::store(NodeObjectType type, Blob&& data, uint256 const& hash, std::uint32_t) { storeStats(1, data.size()); auto obj = NodeObject::createObject(type, std::move(data), hash); backend_->store(obj); } void DatabaseNodeImp::asyncFetch( uint256 const& hash, std::uint32_t ledgerSeq, std::function const&)>&& callback) { Database::asyncFetch(hash, ledgerSeq, std::move(callback)); } std::shared_ptr DatabaseNodeImp::fetchNodeObject(uint256 const& hash, std::uint32_t, FetchReport& fetchReport, bool duplicate) { std::shared_ptr nodeObject = nullptr; Status status; try { status = backend_->fetch(hash.data(), &nodeObject); } catch (std::exception const& e) { JLOG(j_.fatal()) << "fetchNodeObject " << hash << ": Exception fetching from backend: " << e.what(); Rethrow(); } switch (status) { case ok: case notFound: break; case dataCorrupt: JLOG(j_.fatal()) << "fetchNodeObject " << hash << ": nodestore data is corrupted"; break; default: JLOG(j_.warn()) << "fetchNodeObject " << hash << ": backend returns unknown result " << status; break; } if (nodeObject) fetchReport.wasFound = true; return nodeObject; } std::vector> DatabaseNodeImp::fetchBatch(std::vector const& hashes) { using namespace std::chrono; auto const before = steady_clock::now(); std::vector batch{}; batch.reserve(hashes.size()); for (size_t i = 0; i < hashes.size(); ++i) { auto const& hash = hashes[i]; batch.push_back(&hash); } auto results = backend_->fetchBatch(batch).first; for (size_t i = 0; i < results.size(); ++i) { if (!results[i]) { JLOG(j_.error()) << "fetchBatch - " << "record not found in db. hash = " << strHex(hashes[i]); } } auto fetchDurationUs = std::chrono::duration_cast(steady_clock::now() - before).count(); updateFetchMetrics(hashes.size(), 0, fetchDurationUs); return results; } } // namespace NodeStore } // namespace xrpl