xrpld
Loading...
Searching...
No Matches
xrpl::node_store::DatabaseRotatingImp Class Reference

#include <DatabaseRotatingImp.h>

Inheritance diagram for xrpl::node_store::DatabaseRotatingImp:
Collaboration diagram for xrpl::node_store::DatabaseRotatingImp:

Public Member Functions

 DatabaseRotatingImp ()=delete
 DatabaseRotatingImp (DatabaseRotatingImp const &)=delete
DatabaseRotatingImpoperator= (DatabaseRotatingImp const &)=delete
 DatabaseRotatingImp (Scheduler &scheduler, int readThreads, std::shared_ptr< Backend > writableBackend, std::shared_ptr< Backend > archiveBackend, Section const &config, beast::Journal j)
 ~DatabaseRotatingImp () override
void rotate (std::unique_ptr< node_store::Backend > &&newBackend, std::function< void(std::string const &writableName, std::string const &archiveName)> const &f) override
 Rotates the backends.
std::string getName () const override
 Retrieve the name associated with this backend.
std::int32_t getWriteLoad () const override
 Retrieve the estimated number of pending write operations.
void importDatabase (Database &source) override
 Import objects from another database.
bool isSameDB (std::uint32_t, std::uint32_t) override
 Check if two ledgers are in the same database.
void store (NodeObjectType type, Blob &&data, uint256 const &hash, std::uint32_t) override
 Store the object.
void sync () override
void sweep () override
 Remove expired entries from the positive and negative caches.
void setRotationInFlight (bool inFlight) override
 Marks an online-delete rotation as in progress (or completed).
std::shared_ptr< NodeObjectfetchNodeObject (uint256 const &hash, std::uint32_t ledgerSeq=0, FetchType fetchType=FetchType::Synchronous, bool duplicate=false)
 Fetch a node object.
virtual void asyncFetch (uint256 const &hash, std::uint32_t ledgerSeq, std::function< void(std::shared_ptr< NodeObject > const &)> &&callback)
 Fetch an object without waiting.
std::uint64_t getStoreCount () const
 Gather statistics pertaining to read and write activities.
std::uint32_t getFetchTotalCount () const
std::uint32_t getFetchHitCount () const
std::uint64_t getStoreSize () const
std::uint32_t getFetchSize () const
void getCountsJson (json::Value &obj)
int fdRequired () const
 Returns the number of file descriptors the database expects to need.
virtual void stop ()
bool isStopping () const
std::uint32_t earliestLedgerSeq () const noexcept

Protected Member Functions

void storeStats (std::uint64_t count, std::uint64_t sz)
void importInternal (Backend &dstBackend, Database &srcDB)
void updateFetchMetrics (uint64_t fetches, uint64_t hits, uint64_t duration)

Protected Attributes

beast::Journal const j_
Schedulerscheduler_
int fdRequired_ {0}
std::atomic< std::uint32_tfetchHitCount_ {0}
std::atomic< std::uint32_tfetchSz_ {0}
std::uint32_t const earliestLedgerSeq_
int const requestBundle_

Private Member Functions

std::shared_ptr< NodeObjectfetchNodeObject (uint256 const &hash, std::uint32_t, FetchReport &fetchReport, bool duplicate) override
void forEach (std::function< void(std::shared_ptr< NodeObject >)> f) override
 Visit every object in the database This is usually called during import.
void threadEntry ()

Private Attributes

std::shared_ptr< BackendwritableBackend_
std::shared_ptr< BackendarchiveBackend_
std::mutex mutex_
std::atomic< bool > rotationInFlight_ {false}
std::atomic< std::uint64_tcopyForwardCount_ {0}
std::atomic< std::uint64_tstoreCount_ {0}
std::atomic< std::uint64_tstoreSz_ {0}
std::atomic< std::uint64_tfetchTotalCount_ {0}
std::atomic< std::uint64_tfetchDurationUs_ {0}
std::atomic< std::uint64_tstoreDurationUs_ {0}
std::mutex readLock_
std::condition_variable readCondVar_
std::map< uint256, std::vector< std::pair< std::uint32_t, std::function< void(std::shared_ptr< NodeObject > const &)> > > > read_
std::atomic< bool > readStopping_ = false
std::atomic< int > readThreads_ = 0
std::atomic< int > runningThreads_ = 0

Detailed Description

Definition at line 21 of file DatabaseRotatingImp.h.

Constructor & Destructor Documentation

◆ DatabaseRotatingImp() [1/3]

xrpl::node_store::DatabaseRotatingImp::DatabaseRotatingImp ( )
delete

◆ DatabaseRotatingImp() [2/3]

xrpl::node_store::DatabaseRotatingImp::DatabaseRotatingImp ( DatabaseRotatingImp const & )
delete

◆ DatabaseRotatingImp() [3/3]

xrpl::node_store::DatabaseRotatingImp::DatabaseRotatingImp ( Scheduler & scheduler,
int readThreads,
std::shared_ptr< Backend > writableBackend,
std::shared_ptr< Backend > archiveBackend,
Section const & config,
beast::Journal j )

Definition at line 27 of file DatabaseRotatingImp.cpp.

◆ ~DatabaseRotatingImp()

xrpl::node_store::DatabaseRotatingImp::~DatabaseRotatingImp ( )
override

Definition at line 37 of file DatabaseRotatingImp.h.

Member Function Documentation

◆ operator=()

DatabaseRotatingImp & xrpl::node_store::DatabaseRotatingImp::operator= ( DatabaseRotatingImp const & )
delete

◆ rotate()

void xrpl::node_store::DatabaseRotatingImp::rotate ( std::unique_ptr< node_store::Backend > && newBackend,
std::function< void(std::string const &writableName, std::string const &archiveName)> const & f )
overridevirtual

Rotates the backends.

Parameters
newBackendNew writable backend
fA function executed after the rotation outside of lock. The values passed to f will be the new backend database names after rotation.

Implements xrpl::node_store::DatabaseRotating.

Definition at line 45 of file DatabaseRotatingImp.cpp.

◆ getName()

std::string xrpl::node_store::DatabaseRotatingImp::getName ( ) const
overridevirtual

Retrieve the name associated with this backend.

This is used for diagnostics and may not reflect the actual path or paths used by the underlying backend.

Implements xrpl::node_store::Database.

Definition at line 90 of file DatabaseRotatingImp.cpp.

◆ getWriteLoad()

std::int32_t xrpl::node_store::DatabaseRotatingImp::getWriteLoad ( ) const
overridevirtual

Retrieve the estimated number of pending write operations.

This is used for diagnostics.

Implements xrpl::node_store::Database.

Definition at line 97 of file DatabaseRotatingImp.cpp.

◆ importDatabase()

void xrpl::node_store::DatabaseRotatingImp::importDatabase ( Database & source)
overridevirtual

Import objects from another database.

Implements xrpl::node_store::Database.

Definition at line 104 of file DatabaseRotatingImp.cpp.

◆ isSameDB()

bool xrpl::node_store::DatabaseRotatingImp::isSameDB ( std::uint32_t s1,
std::uint32_t s2 )
overridevirtual

Check if two ledgers are in the same database.

If these two sequence numbers map to the same database, the result of a fetch with either sequence number would be identical.

Parameters
s1The first sequence number
s2The second sequence number
Returns
'true' if both ledgers would be in the same DB

Implements xrpl::node_store::Database.

Definition at line 58 of file DatabaseRotatingImp.h.

◆ store()

void xrpl::node_store::DatabaseRotatingImp::store ( NodeObjectType type,
Blob && data,
uint256 const & hash,
std::uint32_t ledgerSeq )
overridevirtual

Store the object.

The caller's Blob parameter is overwritten.

Parameters
typeThe type of object.
dataThe payload of the object. The caller's variable is overwritten.
hashThe 256-bit hash of the payload data.
ledgerSeqThe sequence of the ledger the object belongs to.
Returns
true if the object was stored?

Implements xrpl::node_store::Database.

Definition at line 122 of file DatabaseRotatingImp.cpp.

◆ sync()

void xrpl::node_store::DatabaseRotatingImp::sync ( )
overridevirtual

Implements xrpl::node_store::Database.

Definition at line 115 of file DatabaseRotatingImp.cpp.

◆ sweep()

void xrpl::node_store::DatabaseRotatingImp::sweep ( )
overridevirtual

Remove expired entries from the positive and negative caches.

Implements xrpl::node_store::Database.

Definition at line 136 of file DatabaseRotatingImp.cpp.

◆ setRotationInFlight()

void xrpl::node_store::DatabaseRotatingImp::setRotationInFlight ( bool inFlight)
overridevirtual

Marks an online-delete rotation as in progress (or completed).

While in flight, a read served by the archive backend is copied forward into the writable backend even for ordinary (duplicate == false) fetches: the archive is about to be deleted, and a node body canonicalized into caches during the rotation window would otherwise survive only in RAM once the archive is dropped.

Implements xrpl::node_store::DatabaseRotating.

Definition at line 82 of file DatabaseRotatingImp.cpp.

◆ fetchNodeObject() [1/2]

std::shared_ptr< NodeObject > xrpl::node_store::DatabaseRotatingImp::fetchNodeObject ( uint256 const & hash,
std::uint32_t ,
FetchReport & fetchReport,
bool duplicate )
overrideprivatevirtual

Implements xrpl::node_store::Database.

Definition at line 142 of file DatabaseRotatingImp.cpp.

◆ forEach()

void xrpl::node_store::DatabaseRotatingImp::forEach ( std::function< void(std::shared_ptr< NodeObject >)> f)
overrideprivatevirtual

Visit every object in the database This is usually called during import.

Note
This routine will not be called concurrently with itself or other methods.
See also
import

Implements xrpl::node_store::Database.

Definition at line 221 of file DatabaseRotatingImp.cpp.

◆ fetchNodeObject() [2/2]

std::shared_ptr< NodeObject > xrpl::node_store::Database::fetchNodeObject ( uint256 const & hash,
std::uint32_t ledgerSeq = 0,
FetchType fetchType = FetchType::Synchronous,
bool duplicate = false )
inherited

Fetch a node object.

If the object is known to be not in the database, isn't found in the database during the fetch, or failed to load correctly during the fetch, nullptr is returned.

Note
This can be called concurrently.
Parameters
hashThe key of the object to retrieve.
ledgerSeqThe sequence of the ledger where the object is stored.
fetchTypethe type of fetch, synchronous or asynchronous.
Returns
The object, or nullptr if it couldn't be retrieved.

Definition at line 231 of file libxrpl/nodestore/Database.cpp.

◆ asyncFetch()

void xrpl::node_store::Database::asyncFetch ( uint256 const & hash,
std::uint32_t ledgerSeq,
std::function< void(std::shared_ptr< NodeObject > const &)> && callback )
virtualinherited

Fetch an object without waiting.

If I/O is required to determine whether or not the object is present, false is returned. Otherwise, true is returned and object is set to refer to the object, or nullptr if the object is not present. If I/O is required, the I/O is scheduled and true is returned

Note
This can be called concurrently.
Parameters
hashThe key of the object to retrieve
ledgerSeqThe sequence of the ledger where the object is stored.
callbackCallback function when read completes

Reimplemented in xrpl::node_store::DatabaseNodeImp.

Definition at line 178 of file libxrpl/nodestore/Database.cpp.

◆ getStoreCount()

std::uint64_t xrpl::node_store::Database::getStoreCount ( ) const
inherited

Gather statistics pertaining to read and write activities.

Parameters
objJson object reference into which to place counters.

Definition at line 171 of file Database.h.

◆ getFetchTotalCount()

std::uint32_t xrpl::node_store::Database::getFetchTotalCount ( ) const
inherited

Definition at line 177 of file Database.h.

◆ getFetchHitCount()

std::uint32_t xrpl::node_store::Database::getFetchHitCount ( ) const
inherited

Definition at line 183 of file Database.h.

◆ getStoreSize()

std::uint64_t xrpl::node_store::Database::getStoreSize ( ) const
inherited

Definition at line 189 of file Database.h.

◆ getFetchSize()

std::uint32_t xrpl::node_store::Database::getFetchSize ( ) const
inherited

Definition at line 195 of file Database.h.

◆ getCountsJson()

void xrpl::node_store::Database::getCountsJson ( json::Value & obj)
inherited

Definition at line 258 of file libxrpl/nodestore/Database.cpp.

◆ fdRequired()

int xrpl::node_store::Database::fdRequired ( ) const
inherited

Returns the number of file descriptors the database expects to need.

Definition at line 207 of file Database.h.

◆ stop()

void xrpl::node_store::Database::stop ( )
virtualinherited

Definition at line 144 of file libxrpl/nodestore/Database.cpp.

◆ isStopping()

bool xrpl::node_store::Database::isStopping ( ) const
inherited

Definition at line 138 of file libxrpl/nodestore/Database.cpp.

◆ earliestLedgerSeq()

std::uint32_t xrpl::node_store::Database::earliestLedgerSeq ( ) const
nodiscardnoexceptinherited
Returns
The earliest ledger sequence allowed

Definition at line 222 of file Database.h.

◆ storeStats()

void xrpl::node_store::Database::storeStats ( std::uint64_t count,
std::uint64_t sz )
protectedinherited

Definition at line 249 of file Database.h.

◆ importInternal()

void xrpl::node_store::Database::importInternal ( Backend & dstBackend,
Database & srcDB )
protectedinherited

Definition at line 193 of file libxrpl/nodestore/Database.cpp.

◆ updateFetchMetrics()

void xrpl::node_store::Database::updateFetchMetrics ( uint64_t fetches,
uint64_t hits,
uint64_t duration )
protectedinherited

Definition at line 261 of file Database.h.

◆ threadEntry()

void xrpl::node_store::Database::threadEntry ( )
privateinherited

Member Data Documentation

◆ writableBackend_

std::shared_ptr<Backend> xrpl::node_store::DatabaseRotatingImp::writableBackend_
private

Definition at line 77 of file DatabaseRotatingImp.h.

◆ archiveBackend_

std::shared_ptr<Backend> xrpl::node_store::DatabaseRotatingImp::archiveBackend_
private

Definition at line 78 of file DatabaseRotatingImp.h.

◆ mutex_

std::mutex xrpl::node_store::DatabaseRotatingImp::mutex_
mutableprivate

Definition at line 79 of file DatabaseRotatingImp.h.

◆ rotationInFlight_

std::atomic<bool> xrpl::node_store::DatabaseRotatingImp::rotationInFlight_ {false}
private

Definition at line 86 of file DatabaseRotatingImp.h.

◆ copyForwardCount_

std::atomic<std::uint64_t> xrpl::node_store::DatabaseRotatingImp::copyForwardCount_ {0}
private

Definition at line 87 of file DatabaseRotatingImp.h.

◆ j_

beast::Journal const xrpl::node_store::Database::j_
protectedinherited

Definition at line 228 of file Database.h.

◆ scheduler_

Scheduler& xrpl::node_store::Database::scheduler_
protectedinherited

Definition at line 229 of file Database.h.

◆ fdRequired_

int xrpl::node_store::Database::fdRequired_ {0}
protectedinherited

Definition at line 230 of file Database.h.

◆ fetchHitCount_

std::atomic<std::uint32_t> xrpl::node_store::Database::fetchHitCount_ {0}
protectedinherited

Definition at line 232 of file Database.h.

◆ fetchSz_

std::atomic<std::uint32_t> xrpl::node_store::Database::fetchSz_ {0}
protectedinherited

Definition at line 233 of file Database.h.

◆ earliestLedgerSeq_

std::uint32_t const xrpl::node_store::Database::earliestLedgerSeq_
protectedinherited

Definition at line 241 of file Database.h.

◆ requestBundle_

int const xrpl::node_store::Database::requestBundle_
protectedinherited

Definition at line 246 of file Database.h.

◆ storeCount_

std::atomic<std::uint64_t> xrpl::node_store::Database::storeCount_ {0}
privateinherited

Definition at line 269 of file Database.h.

◆ storeSz_

std::atomic<std::uint64_t> xrpl::node_store::Database::storeSz_ {0}
privateinherited

Definition at line 270 of file Database.h.

◆ fetchTotalCount_

std::atomic<std::uint64_t> xrpl::node_store::Database::fetchTotalCount_ {0}
privateinherited

Definition at line 271 of file Database.h.

◆ fetchDurationUs_

std::atomic<std::uint64_t> xrpl::node_store::Database::fetchDurationUs_ {0}
privateinherited

Definition at line 272 of file Database.h.

◆ storeDurationUs_

std::atomic<std::uint64_t> xrpl::node_store::Database::storeDurationUs_ {0}
privateinherited

Definition at line 273 of file Database.h.

◆ readLock_

std::mutex xrpl::node_store::Database::readLock_
mutableprivateinherited

Definition at line 275 of file Database.h.

◆ readCondVar_

std::condition_variable xrpl::node_store::Database::readCondVar_
privateinherited

Definition at line 276 of file Database.h.

◆ read_

std::map< uint256, std::vector< std::pair<std::uint32_t, std::function<void(std::shared_ptr<NodeObject> const&)> > > > xrpl::node_store::Database::read_
privateinherited

Definition at line 283 of file Database.h.

◆ readStopping_

std::atomic<bool> xrpl::node_store::Database::readStopping_ = false
privateinherited

Definition at line 285 of file Database.h.

◆ readThreads_

std::atomic<int> xrpl::node_store::Database::readThreads_ = 0
privateinherited

Definition at line 286 of file Database.h.

◆ runningThreads_

std::atomic<int> xrpl::node_store::Database::runningThreads_ = 0
privateinherited

Definition at line 287 of file Database.h.