rippled
Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | List of all members
ripple::NodeStore::DatabaseRotatingImp Class Reference
Inheritance diagram for ripple::NodeStore::DatabaseRotatingImp:
Inheritance graph
[legend]
Collaboration diagram for ripple::NodeStore::DatabaseRotatingImp:
Collaboration graph
[legend]

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 ()
 
void rotateWithLock (std::function< std::unique_ptr< NodeStore::Backend >(std::string const &writableBackendName)> const &f) override
 Rotates the backends. More...
 
std::string getName () const override
 Retrieve the name associated with this backend. More...
 
std::int32_t getWriteLoad () const override
 Retrieve the estimated number of pending write operations. More...
 
void importDatabase (Database &source) override
 Import objects from another database. More...
 
bool isSameDB (std::uint32_t, std::uint32_t) override
 
void store (NodeObjectType type, Blob &&data, uint256 const &hash, std::uint32_t) override
 Store the object. More...
 
void sync () override
 
bool storeLedger (std::shared_ptr< Ledger const > const &srcLedger) override
 Store a ledger from a different database. More...
 
void sweep () override
 Remove expired entries from the positive and negative caches. More...
 
std::shared_ptr< NodeObjectfetchNodeObject (uint256 const &hash, std::uint32_t ledgerSeq=0, FetchType fetchType=FetchType::synchronous, bool duplicate=false)
 Fetch a node object. More...
 
virtual void asyncFetch (uint256 const &hash, std::uint32_t ledgerSeq, std::function< void(std::shared_ptr< NodeObject > const &)> &&callback)
 Fetch an object without waiting. More...
 
std::uint64_t getStoreCount () const
 Gather statistics pertaining to read and write activities. More...
 
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. More...
 
virtual void stop ()
 
bool isStopping () const
 
std::uint32_t ledgersPerShard () const noexcept
 
std::uint32_t earliestLedgerSeq () const noexcept
 
std::uint32_t earliestShardIndex () const noexcept
 
std::uint32_t firstLedgerSeq (std::uint32_t shardIndex) const noexcept
 Calculates the first ledger sequence for a given shard index. More...
 
std::uint32_t lastLedgerSeq (std::uint32_t shardIndex) const noexcept
 Calculates the last ledger sequence for a given shard index. More...
 
std::uint32_t seqToShardIndex (std::uint32_t ledgerSeq) const noexcept
 Calculates the shard index for a given ledger sequence. More...
 
std::uint32_t maxLedgers (std::uint32_t shardIndex) const noexcept
 Calculates the maximum ledgers for a given shard index. More...
 

Protected Member Functions

bool storeLedger (Ledger const &srcLedger, std::shared_ptr< Backend > dstBackend)
 
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

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

Private Member Functions

std::shared_ptr< NodeObjectfetchNodeObject (uint256 const &hash, std::uint32_t, FetchReport &fetchReport, bool duplicate) override
 
void for_each (std::function< void(std::shared_ptr< NodeObject >)> f) override
 Visit every object in the database This is usually called during import. More...
 
virtual std::optional< Backend::Counters< std::uint64_t > > getCounters () const
 Retrieve backend read and write stats. More...
 
void threadEntry ()
 

Private Attributes

std::shared_ptr< BackendwritableBackend_
 
std::shared_ptr< BackendarchiveBackend_
 
std::mutex mutex_
 
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 28 of file DatabaseRotatingImp.h.

Constructor & Destructor Documentation

◆ DatabaseRotatingImp() [1/3]

ripple::NodeStore::DatabaseRotatingImp::DatabaseRotatingImp ( )
delete

◆ DatabaseRotatingImp() [2/3]

ripple::NodeStore::DatabaseRotatingImp::DatabaseRotatingImp ( DatabaseRotatingImp const &  )
delete

◆ DatabaseRotatingImp() [3/3]

ripple::NodeStore::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()

ripple::NodeStore::DatabaseRotatingImp::~DatabaseRotatingImp ( )

Definition at line 44 of file DatabaseRotatingImp.h.

Member Function Documentation

◆ operator=()

DatabaseRotatingImp& ripple::NodeStore::DatabaseRotatingImp::operator= ( DatabaseRotatingImp const &  )
delete

◆ rotateWithLock()

void ripple::NodeStore::DatabaseRotatingImp::rotateWithLock ( std::function< std::unique_ptr< NodeStore::Backend >(std::string const &writableBackendName)> const &  f)
overridevirtual

Rotates the backends.

Parameters
fA function executed before the rotation and under the same lock

Implements ripple::NodeStore::DatabaseRotating.

Definition at line 45 of file DatabaseRotatingImp.cpp.

◆ getName()

std::string ripple::NodeStore::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 ripple::NodeStore::Database.

Definition at line 58 of file DatabaseRotatingImp.cpp.

◆ getWriteLoad()

std::int32_t ripple::NodeStore::DatabaseRotatingImp::getWriteLoad ( ) const
overridevirtual

Retrieve the estimated number of pending write operations.

This is used for diagnostics.

Implements ripple::NodeStore::Database.

Definition at line 65 of file DatabaseRotatingImp.cpp.

◆ importDatabase()

void ripple::NodeStore::DatabaseRotatingImp::importDatabase ( Database source)
overridevirtual

Import objects from another database.

Implements ripple::NodeStore::Database.

Definition at line 72 of file DatabaseRotatingImp.cpp.

◆ isSameDB()

bool ripple::NodeStore::DatabaseRotatingImp::isSameDB ( std::uint32_t  ,
std::uint32_t   
)
overridevirtual

Implements ripple::NodeStore::Database.

Definition at line 63 of file DatabaseRotatingImp.h.

◆ store()

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

Definition at line 101 of file DatabaseRotatingImp.cpp.

◆ sync()

void ripple::NodeStore::DatabaseRotatingImp::sync ( )
overridevirtual

Implements ripple::NodeStore::Database.

Definition at line 94 of file DatabaseRotatingImp.cpp.

◆ storeLedger() [1/2]

bool ripple::NodeStore::DatabaseRotatingImp::storeLedger ( std::shared_ptr< Ledger const > const &  srcLedger)
overridevirtual

Store a ledger from a different database.

Parameters
srcLedgerThe ledger to store.
Returns
true if the operation was successful

Implements ripple::NodeStore::Database.

Definition at line 83 of file DatabaseRotatingImp.cpp.

◆ sweep()

void ripple::NodeStore::DatabaseRotatingImp::sweep ( )
overridevirtual

Remove expired entries from the positive and negative caches.

Implements ripple::NodeStore::Database.

Definition at line 119 of file DatabaseRotatingImp.cpp.

◆ fetchNodeObject() [1/2]

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

Implements ripple::NodeStore::Database.

Definition at line 125 of file DatabaseRotatingImp.cpp.

◆ for_each()

void ripple::NodeStore::DatabaseRotatingImp::for_each ( 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 ripple::NodeStore::Database.

Definition at line 195 of file DatabaseRotatingImp.cpp.

◆ fetchNodeObject() [2/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 252 of file Database.cpp.

◆ 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, used by the shard store.
callbackCallback function when read completes

Reimplemented in ripple::NodeStore::DatabaseNodeImp.

Definition at line 198 of file Database.cpp.

◆ storeLedger() [2/2]

bool ripple::NodeStore::Database::storeLedger ( Ledger const &  srcLedger,
std::shared_ptr< Backend dstBackend 
)
protectedinherited

Definition at line 279 of file Database.cpp.

◆ 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 182 of file Database.h.

◆ getFetchTotalCount()

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

Definition at line 188 of file Database.h.

◆ getFetchHitCount()

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

Definition at line 194 of file Database.h.

◆ getStoreSize()

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

Definition at line 200 of file Database.h.

◆ getFetchSize()

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

Definition at line 206 of file Database.h.

◆ getCountsJson()

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

Definition at line 378 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 216 of file Database.h.

◆ stop()

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

Reimplemented in ripple::NodeStore::DatabaseShardImp.

Definition at line 165 of file Database.cpp.

◆ isStopping()

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

Definition at line 146 of file Database.cpp.

◆ ledgersPerShard()

std::uint32_t ripple::NodeStore::Database::ledgersPerShard ( ) const
noexceptinherited
Returns
The maximum number of ledgers stored in a shard

Definition at line 230 of file Database.h.

◆ earliestLedgerSeq()

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

Definition at line 238 of file Database.h.

◆ earliestShardIndex()

std::uint32_t ripple::NodeStore::Database::earliestShardIndex ( ) const
noexceptinherited
Returns
The earliest shard index

Definition at line 246 of file Database.h.

◆ firstLedgerSeq()

std::uint32_t ripple::NodeStore::Database::firstLedgerSeq ( std::uint32_t  shardIndex) const
noexceptinherited

Calculates the first ledger sequence for a given shard index.

Parameters
shardIndexThe shard index considered
Returns
The first ledger sequence pertaining to the shard index

Definition at line 257 of file Database.h.

◆ lastLedgerSeq()

std::uint32_t ripple::NodeStore::Database::lastLedgerSeq ( std::uint32_t  shardIndex) const
noexceptinherited

Calculates the last ledger sequence for a given shard index.

Parameters
shardIndexThe shard index considered
Returns
The last ledger sequence pertaining to the shard index

Definition at line 271 of file Database.h.

◆ seqToShardIndex()

std::uint32_t ripple::NodeStore::Database::seqToShardIndex ( std::uint32_t  ledgerSeq) const
noexceptinherited

Calculates the shard index for a given ledger sequence.

Parameters
ledgerSeqledger sequence
Returns
The shard index of the ledger sequence

Definition at line 283 of file Database.h.

◆ maxLedgers()

std::uint32_t ripple::NodeStore::Database::maxLedgers ( std::uint32_t  shardIndex) const
noexceptinherited

Calculates the maximum ledgers for a given shard index.

Parameters
shardIndexThe shard index considered
Returns
The maximum ledgers pertaining to the shard index
Note
The earliest shard may store less if the earliest ledger sequence truncates its beginning

Definition at line 152 of file Database.cpp.

◆ storeStats()

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

Definition at line 333 of file Database.h.

◆ importInternal()

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

Definition at line 213 of file Database.cpp.

◆ updateFetchMetrics()

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

Definition at line 349 of file Database.h.

◆ getCounters()

virtual std::optional<Backend::Counters<std::uint64_t> > ripple::NodeStore::Database::getCounters ( ) const
privatevirtualinherited

Retrieve backend read and write stats.

Note
The Counters struct is specific to and only used by CassandraBackend.

Reimplemented in ripple::NodeStore::DatabaseNodeImp.

Definition at line 401 of file Database.h.

◆ threadEntry()

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

Member Data Documentation

◆ writableBackend_

std::shared_ptr<Backend> ripple::NodeStore::DatabaseRotatingImp::writableBackend_
private

Definition at line 83 of file DatabaseRotatingImp.h.

◆ archiveBackend_

std::shared_ptr<Backend> ripple::NodeStore::DatabaseRotatingImp::archiveBackend_
private

Definition at line 84 of file DatabaseRotatingImp.h.

◆ mutex_

std::mutex ripple::NodeStore::DatabaseRotatingImp::mutex_
mutableprivate

Definition at line 85 of file DatabaseRotatingImp.h.

◆ j_

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

Definition at line 301 of file Database.h.

◆ scheduler_

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

Definition at line 302 of file Database.h.

◆ fdRequired_

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

Definition at line 303 of file Database.h.

◆ fetchHitCount_

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

Definition at line 305 of file Database.h.

◆ fetchSz_

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

Definition at line 306 of file Database.h.

◆ ledgersPerShard_

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

Definition at line 314 of file Database.h.

◆ earliestLedgerSeq_

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

Definition at line 322 of file Database.h.

◆ earliestShardIndex_

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

Definition at line 325 of file Database.h.

◆ requestBundle_

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

Definition at line 330 of file Database.h.

◆ storeCount_

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

Definition at line 357 of file Database.h.

◆ storeSz_

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

Definition at line 358 of file Database.h.

◆ fetchTotalCount_

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

Definition at line 359 of file Database.h.

◆ fetchDurationUs_

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

Definition at line 360 of file Database.h.

◆ storeDurationUs_

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

Definition at line 361 of file Database.h.

◆ readLock_

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

Definition at line 363 of file Database.h.

◆ readCondVar_

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

Definition at line 364 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 372 of file Database.h.

◆ readStopping_

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

Definition at line 374 of file Database.h.

◆ readThreads_

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

Definition at line 375 of file Database.h.

◆ runningThreads_

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

Definition at line 376 of file Database.h.