rippled
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | List of all members
ripple::NodeStore::DatabaseRotating Class Referenceabstract

#include <DatabaseRotating.h>

Inheritance diagram for ripple::NodeStore::DatabaseRotating:
Inheritance graph
[legend]
Collaboration diagram for ripple::NodeStore::DatabaseRotating:
Collaboration graph
[legend]

Public Member Functions

 DatabaseRotating (Scheduler &scheduler, int readThreads, Section const &config, beast::Journal journal)
 
virtual void rotate (std::unique_ptr< NodeStore::Backend > &&newBackend, std::function< void(std::string const &writableName, std::string const &archiveName)> const &f)=0
 Rotates the backends.
 
virtual std::string getName () const =0
 Retrieve the name associated with this backend.
 
virtual void importDatabase (Database &source)=0
 Import objects from another database.
 
virtual std::int32_t getWriteLoad () const =0
 Retrieve the estimated number of pending write operations.
 
virtual void store (NodeObjectType type, Blob &&data, uint256 const &hash, std::uint32_t ledgerSeq)=0
 Store the object.
 
virtual bool isSameDB (std::uint32_t s1, std::uint32_t s2)=0
 
virtual void sync ()=0
 
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.
 
virtual void sweep ()=0
 Remove expired entries from the positive and negative caches.
 
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

virtual std::shared_ptr< NodeObjectfetchNodeObject (uint256 const &hash, std::uint32_t ledgerSeq, FetchReport &fetchReport, bool duplicate)=0
 
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 threadEntry ()
 

Private Attributes

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 14 of file DatabaseRotating.h.

Constructor & Destructor Documentation

◆ DatabaseRotating()

ripple::NodeStore::DatabaseRotating::DatabaseRotating ( Scheduler scheduler,
int  readThreads,
Section const &  config,
beast::Journal  journal 
)

Definition at line 17 of file DatabaseRotating.h.

Member Function Documentation

◆ rotate()

virtual void ripple::NodeStore::DatabaseRotating::rotate ( std::unique_ptr< NodeStore::Backend > &&  newBackend,
std::function< void(std::string const &writableName, std::string const &archiveName)> const &  f 
)
pure virtual

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.

Implemented in ripple::NodeStore::DatabaseRotatingImp.

◆ getName()

virtual std::string ripple::NodeStore::Database::getName ( ) const
pure virtualinherited

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.

Implemented in ripple::NodeStore::DatabaseNodeImp, and ripple::NodeStore::DatabaseRotatingImp.

◆ importDatabase()

virtual void ripple::NodeStore::Database::importDatabase ( Database source)
pure virtualinherited

Import objects from another database.

Implemented in ripple::NodeStore::DatabaseNodeImp, and ripple::NodeStore::DatabaseRotatingImp.

◆ getWriteLoad()

virtual std::int32_t ripple::NodeStore::Database::getWriteLoad ( ) const
pure virtualinherited

Retrieve the estimated number of pending write operations.

This is used for diagnostics.

Implemented in ripple::NodeStore::DatabaseNodeImp, and ripple::NodeStore::DatabaseRotatingImp.

◆ store()

virtual void ripple::NodeStore::Database::store ( NodeObjectType  type,
Blob &&  data,
uint256 const &  hash,
std::uint32_t  ledgerSeq 
)
pure virtualinherited

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?

Implemented in ripple::NodeStore::DatabaseNodeImp, and ripple::NodeStore::DatabaseRotatingImp.

◆ isSameDB()

virtual bool ripple::NodeStore::Database::isSameDB ( std::uint32_t  s1,
std::uint32_t  s2 
)
pure virtualinherited

◆ sync()

virtual void ripple::NodeStore::Database::sync ( )
pure virtualinherited

◆ fetchNodeObject() [1/2]

std::shared_ptr< NodeObject > ripple::NodeStore::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 221 of file Database.cpp.

◆ fetchNodeObject() [2/2]

virtual std::shared_ptr< NodeObject > ripple::NodeStore::Database::fetchNodeObject ( uint256 const &  hash,
std::uint32_t  ledgerSeq,
FetchReport fetchReport,
bool  duplicate 
)
privatepure virtualinherited

◆ asyncFetch()

void ripple::NodeStore::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 ripple::NodeStore::DatabaseNodeImp.

Definition at line 165 of file Database.cpp.

◆ sweep()

virtual void ripple::NodeStore::Database::sweep ( )
pure virtualinherited

Remove expired entries from the positive and negative caches.

Implemented in ripple::NodeStore::DatabaseNodeImp, and ripple::NodeStore::DatabaseRotatingImp.

◆ getStoreCount()

std::uint64_t ripple::NodeStore::Database::getStoreCount ( ) const
inherited

Gather statistics pertaining to read and write activities.

Parameters
objJson object reference into which to place counters.

Definition at line 154 of file Database.h.

◆ getFetchTotalCount()

std::uint32_t ripple::NodeStore::Database::getFetchTotalCount ( ) const
inherited

Definition at line 160 of file Database.h.

◆ getFetchHitCount()

std::uint32_t ripple::NodeStore::Database::getFetchHitCount ( ) const
inherited

Definition at line 166 of file Database.h.

◆ getStoreSize()

std::uint64_t ripple::NodeStore::Database::getStoreSize ( ) const
inherited

Definition at line 172 of file Database.h.

◆ getFetchSize()

std::uint32_t ripple::NodeStore::Database::getFetchSize ( ) const
inherited

Definition at line 178 of file Database.h.

◆ getCountsJson()

void ripple::NodeStore::Database::getCountsJson ( Json::Value obj)
inherited

Definition at line 248 of file Database.cpp.

◆ fdRequired()

int ripple::NodeStore::Database::fdRequired ( ) const
inherited

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

Definition at line 188 of file Database.h.

◆ stop()

void ripple::NodeStore::Database::stop ( )
virtualinherited

Definition at line 130 of file Database.cpp.

◆ isStopping()

bool ripple::NodeStore::Database::isStopping ( ) const
inherited

Definition at line 124 of file Database.cpp.

◆ earliestLedgerSeq()

std::uint32_t ripple::NodeStore::Database::earliestLedgerSeq ( ) const
noexceptinherited
Returns
The earliest ledger sequence allowed

Definition at line 202 of file Database.h.

◆ storeStats()

void ripple::NodeStore::Database::storeStats ( std::uint64_t  count,
std::uint64_t  sz 
)
protectedinherited

Definition at line 229 of file Database.h.

◆ importInternal()

void ripple::NodeStore::Database::importInternal ( Backend dstBackend,
Database srcDB 
)
protectedinherited

Definition at line 180 of file Database.cpp.

◆ updateFetchMetrics()

void ripple::NodeStore::Database::updateFetchMetrics ( uint64_t  fetches,
uint64_t  hits,
uint64_t  duration 
)
protectedinherited

Definition at line 243 of file Database.h.

◆ for_each()

virtual void ripple::NodeStore::Database::for_each ( std::function< void(std::shared_ptr< NodeObject >)>  f)
privatepure virtualinherited

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

Implemented in ripple::NodeStore::DatabaseNodeImp, and ripple::NodeStore::DatabaseRotatingImp.

◆ threadEntry()

void ripple::NodeStore::Database::threadEntry ( )
privateinherited

Member Data Documentation

◆ j_

beast::Journal const ripple::NodeStore::Database::j_
protectedinherited

Definition at line 208 of file Database.h.

◆ scheduler_

Scheduler& ripple::NodeStore::Database::scheduler_
protectedinherited

Definition at line 209 of file Database.h.

◆ fdRequired_

int ripple::NodeStore::Database::fdRequired_ {0}
protectedinherited

Definition at line 210 of file Database.h.

◆ fetchHitCount_

std::atomic<std::uint32_t> ripple::NodeStore::Database::fetchHitCount_ {0}
protectedinherited

Definition at line 212 of file Database.h.

◆ fetchSz_

std::atomic<std::uint32_t> ripple::NodeStore::Database::fetchSz_ {0}
protectedinherited

Definition at line 213 of file Database.h.

◆ earliestLedgerSeq_

std::uint32_t const ripple::NodeStore::Database::earliestLedgerSeq_
protectedinherited

Definition at line 221 of file Database.h.

◆ requestBundle_

int const ripple::NodeStore::Database::requestBundle_
protectedinherited

Definition at line 226 of file Database.h.

◆ storeCount_

std::atomic<std::uint64_t> ripple::NodeStore::Database::storeCount_ {0}
privateinherited

Definition at line 251 of file Database.h.

◆ storeSz_

std::atomic<std::uint64_t> ripple::NodeStore::Database::storeSz_ {0}
privateinherited

Definition at line 252 of file Database.h.

◆ fetchTotalCount_

std::atomic<std::uint64_t> ripple::NodeStore::Database::fetchTotalCount_ {0}
privateinherited

Definition at line 253 of file Database.h.

◆ fetchDurationUs_

std::atomic<std::uint64_t> ripple::NodeStore::Database::fetchDurationUs_ {0}
privateinherited

Definition at line 254 of file Database.h.

◆ storeDurationUs_

std::atomic<std::uint64_t> ripple::NodeStore::Database::storeDurationUs_ {0}
privateinherited

Definition at line 255 of file Database.h.

◆ readLock_

std::mutex ripple::NodeStore::Database::readLock_
mutableprivateinherited

Definition at line 257 of file Database.h.

◆ readCondVar_

std::condition_variable ripple::NodeStore::Database::readCondVar_
privateinherited

Definition at line 258 of file Database.h.

◆ read_

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

Definition at line 266 of file Database.h.

◆ readStopping_

std::atomic<bool> ripple::NodeStore::Database::readStopping_ = false
privateinherited

Definition at line 268 of file Database.h.

◆ readThreads_

std::atomic<int> ripple::NodeStore::Database::readThreads_ = 0
privateinherited

Definition at line 269 of file Database.h.

◆ runningThreads_

std::atomic<int> ripple::NodeStore::Database::runningThreads_ = 0
privateinherited

Definition at line 270 of file Database.h.