rippled
|
A collection of historical shards. More...
Public Member Functions | |
DatabaseShard (Scheduler &scheduler, int readThreads, Section const &config, beast::Journal journal) | |
Construct a shard store. More... | |
virtual bool | init ()=0 |
Initialize the database. More... | |
virtual std::optional< std::uint32_t > | prepareLedger (std::uint32_t validLedgerSeq)=0 |
Prepare to store a new ledger in the shard being acquired. More... | |
virtual bool | prepareShards (std::vector< std::uint32_t > const &shardIndexes)=0 |
Prepare one or more shard indexes to be imported into the database. More... | |
virtual void | removePreShard (std::uint32_t shardIndex)=0 |
Remove a previously prepared shard index for import. More... | |
virtual std::string | getPreShards ()=0 |
Get shard indexes being imported. More... | |
virtual bool | importShard (std::uint32_t shardIndex, boost::filesystem::path const &srcDir)=0 |
Import a shard from the shard archive handler into the shard database. More... | |
virtual std::shared_ptr< Ledger > | fetchLedger (uint256 const &hash, std::uint32_t seq)=0 |
Fetch a ledger from the shard store. More... | |
virtual void | setStored (std::shared_ptr< Ledger const > const &ledger)=0 |
Notifies the database that the given ledger has been fully acquired and stored. More... | |
virtual bool | callForLedgerSQLByLedgerSeq (LedgerIndex ledgerSeq, std::function< bool(soci::session &session)> const &callback)=0 |
Invoke a callback on the SQLite db holding the corresponding ledger. More... | |
virtual bool | callForLedgerSQLByShardIndex (std::uint32_t shardIndex, std::function< bool(soci::session &session)> const &callback)=0 |
Invoke a callback on the ledger SQLite db for the corresponding shard. More... | |
virtual bool | callForTransactionSQLByLedgerSeq (LedgerIndex ledgerSeq, std::function< bool(soci::session &session)> const &callback)=0 |
Invoke a callback on the transaction SQLite db for the corresponding ledger. More... | |
virtual bool | callForTransactionSQLByShardIndex (std::uint32_t shardIndex, std::function< bool(soci::session &session)> const &callback)=0 |
Invoke a callback on the transaction SQLite db for the corresponding shard. More... | |
virtual bool | iterateLedgerSQLsForward (std::optional< std::uint32_t > minShardIndex, std::function< bool(soci::session &session, std::uint32_t shardIndex)> const &callback)=0 |
iterateLedgerSQLsForward Checks out ledger databases for all shards in ascending order starting from given shard index until shard with the largest index visited or callback returned false. More... | |
virtual bool | iterateTransactionSQLsForward (std::optional< std::uint32_t > minShardIndex, std::function< bool(soci::session &session, std::uint32_t shardIndex)> const &callback)=0 |
iterateTransactionSQLsForward Checks out transaction databases for all shards in ascending order starting from given shard index until shard with the largest index visited or callback returned false. More... | |
virtual bool | iterateLedgerSQLsBack (std::optional< std::uint32_t > maxShardIndex, std::function< bool(soci::session &session, std::uint32_t shardIndex)> const &callback)=0 |
iterateLedgerSQLsBack Checks out ledger databases for all shards in descending order starting from given shard index until shard with the smallest index visited or callback returned false. More... | |
virtual bool | iterateTransactionSQLsBack (std::optional< std::uint32_t > maxShardIndex, std::function< bool(soci::session &session, std::uint32_t shardIndex)> const &callback)=0 |
iterateTransactionSQLsBack Checks out transaction databases for all shards in descending order starting from given shard index until shard with the smallest index visited or callback returned false. More... | |
virtual std::unique_ptr< ShardInfo > | getShardInfo () const =0 |
Query information about shards held. More... | |
virtual boost::filesystem::path const & | getRootDir () const =0 |
Returns the root database directory. More... | |
virtual Json::Value | getDatabaseImportStatus () const =0 |
Returns a JSON object detailing the status of an ongoing database import if one is running, otherwise an error object. More... | |
virtual Json::Value | startNodeToShard ()=0 |
Initiates a NodeStore to ShardStore import and returns the result in a JSON object. More... | |
virtual Json::Value | stopNodeToShard ()=0 |
Terminates a NodeStore to ShardStore import and returns the result in a JSON object. More... | |
virtual std::optional< std::uint32_t > | getDatabaseImportSequence () const =0 |
Returns the first ledger sequence of the shard currently being imported from the NodeStore. More... | |
virtual size_t | getNumTasks () const =0 |
Returns the number of queued tasks. More... | |
virtual std::string | getName () const =0 |
Retrieve the name associated with this backend. More... | |
virtual void | importDatabase (Database &source)=0 |
Import objects from another database. More... | |
virtual std::int32_t | getWriteLoad () const =0 |
Retrieve the estimated number of pending write operations. More... | |
virtual void | store (NodeObjectType type, Blob &&data, uint256 const &hash, std::uint32_t ledgerSeq)=0 |
Store the object. More... | |
virtual bool | isSameDB (std::uint32_t s1, std::uint32_t s2)=0 |
virtual void | sync ()=0 |
std::shared_ptr< NodeObject > | fetchNodeObject (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... | |
virtual bool | storeLedger (std::shared_ptr< Ledger const > const &srcLedger)=0 |
Store a ledger from a different database. More... | |
virtual void | sweep ()=0 |
Remove expired entries from the positive and negative caches. 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_ |
Scheduler & | scheduler_ |
int | fdRequired_ {0} |
std::atomic< std::uint32_t > | fetchHitCount_ {0} |
std::atomic< std::uint32_t > | fetchSz_ {0} |
const std::uint32_t | ledgersPerShard_ |
const std::uint32_t | earliestLedgerSeq_ |
const std::uint32_t | earliestShardIndex_ |
const int | requestBundle_ |
Private Member Functions | |
virtual std::shared_ptr< NodeObject > | fetchNodeObject (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. More... | |
virtual std::optional< Backend::Counters< std::uint64_t > > | getCounters () const |
Retrieve backend read and write stats. More... | |
void | threadEntry () |
Private Attributes | |
std::atomic< std::uint64_t > | storeCount_ {0} |
std::atomic< std::uint64_t > | storeSz_ {0} |
std::atomic< std::uint64_t > | fetchTotalCount_ {0} |
std::atomic< std::uint64_t > | fetchDurationUs_ {0} |
std::atomic< std::uint64_t > | storeDurationUs_ {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 |
A collection of historical shards.
Definition at line 37 of file DatabaseShard.h.
ripple::NodeStore::DatabaseShard::DatabaseShard | ( | Scheduler & | scheduler, |
int | readThreads, | ||
Section const & | config, | ||
beast::Journal | journal | ||
) |
Construct a shard store.
scheduler | The scheduler to use for performing asynchronous tasks |
readThreads | The number of asynchronous read threads to create |
config | The shard configuration section for the database |
journal | Destination for logging output |
Definition at line 47 of file DatabaseShard.h.
|
pure virtual |
Initialize the database.
true
if the database initialized without error Implemented in ripple::NodeStore::DatabaseShardImp.
|
pure virtual |
Prepare to store a new ledger in the shard being acquired.
validLedgerSeq | The sequence of the maximum valid ledgers |
Implemented in ripple::NodeStore::DatabaseShardImp.
|
pure virtual |
Prepare one or more shard indexes to be imported into the database.
shardIndexes | Shard indexes to be prepared for import |
Implemented in ripple::NodeStore::DatabaseShardImp.
|
pure virtual |
Remove a previously prepared shard index for import.
shardIndex | Shard index to be removed from import |
Implemented in ripple::NodeStore::DatabaseShardImp.
|
pure virtual |
Get shard indexes being imported.
Implemented in ripple::NodeStore::DatabaseShardImp.
|
pure virtual |
Import a shard from the shard archive handler into the shard database.
This differs from 'importDatabase' which imports the contents of the NodeStore
shardIndex | Shard index to import |
srcDir | The directory to import from |
Implemented in ripple::NodeStore::DatabaseShardImp.
|
pure virtual |
Fetch a ledger from the shard store.
hash | The key of the ledger to retrieve |
seq | The sequence of the ledger |
Implemented in ripple::NodeStore::DatabaseShardImp.
|
pure virtual |
Notifies the database that the given ledger has been fully acquired and stored.
ledger | The stored ledger to be marked as complete |
Implemented in ripple::NodeStore::DatabaseShardImp.
|
pure virtual |
Invoke a callback on the SQLite db holding the corresponding ledger.
Implemented in ripple::NodeStore::DatabaseShardImp.
|
pure virtual |
Invoke a callback on the ledger SQLite db for the corresponding shard.
Implemented in ripple::NodeStore::DatabaseShardImp.
|
pure virtual |
Invoke a callback on the transaction SQLite db for the corresponding ledger.
Implemented in ripple::NodeStore::DatabaseShardImp.
|
pure virtual |
Invoke a callback on the transaction SQLite db for the corresponding shard.
Implemented in ripple::NodeStore::DatabaseShardImp.
|
pure virtual |
iterateLedgerSQLsForward Checks out ledger databases for all shards in ascending order starting from given shard index until shard with the largest index visited or callback returned false.
For each visited shard calls given callback function passing shard index and session with the database to it.
minShardIndex | Start shard index to visit or none if all shards should be visited. |
callback | Callback function to call. |
Implemented in ripple::NodeStore::DatabaseShardImp.
|
pure virtual |
iterateTransactionSQLsForward Checks out transaction databases for all shards in ascending order starting from given shard index until shard with the largest index visited or callback returned false.
For each visited shard calls given callback function passing shard index and session with the database to it.
minShardIndex | Start shard index to visit or none if all shards should be visited. |
callback | Callback function to call. |
Implemented in ripple::NodeStore::DatabaseShardImp.
|
pure virtual |
iterateLedgerSQLsBack Checks out ledger databases for all shards in descending order starting from given shard index until shard with the smallest index visited or callback returned false.
For each visited shard calls given callback function passing shard index and session with the database to it.
maxShardIndex | Start shard index to visit or none if all shards should be visited. |
callback | Callback function to call. |
Implemented in ripple::NodeStore::DatabaseShardImp.
|
pure virtual |
iterateTransactionSQLsBack Checks out transaction databases for all shards in descending order starting from given shard index until shard with the smallest index visited or callback returned false.
For each visited shard calls given callback function passing shard index and session with the database to it.
maxShardIndex | Start shard index to visit or none if all shards should be visited. |
callback | Callback function to call. |
Implemented in ripple::NodeStore::DatabaseShardImp.
|
pure virtual |
Query information about shards held.
Implemented in ripple::NodeStore::DatabaseShardImp.
|
pure virtual |
Returns the root database directory.
Implemented in ripple::NodeStore::DatabaseShardImp.
|
pure virtual |
Returns a JSON object detailing the status of an ongoing database import if one is running, otherwise an error object.
Implemented in ripple::NodeStore::DatabaseShardImp.
|
pure virtual |
Initiates a NodeStore to ShardStore import and returns the result in a JSON object.
Implemented in ripple::NodeStore::DatabaseShardImp.
|
pure virtual |
Terminates a NodeStore to ShardStore import and returns the result in a JSON object.
Implemented in ripple::NodeStore::DatabaseShardImp.
|
pure virtual |
Returns the first ledger sequence of the shard currently being imported from the NodeStore.
Implemented in ripple::NodeStore::DatabaseShardImp.
|
pure virtual |
Returns the number of queued tasks.
Implemented in ripple::NodeStore::DatabaseShardImp.
|
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::DatabaseShardImp, ripple::NodeStore::DatabaseNodeImp, and ripple::NodeStore::DatabaseRotatingImp.
|
pure virtualinherited |
Import objects from another database.
Implemented in ripple::NodeStore::DatabaseShardImp, ripple::NodeStore::DatabaseNodeImp, and ripple::NodeStore::DatabaseRotatingImp.
|
pure virtualinherited |
Retrieve the estimated number of pending write operations.
This is used for diagnostics.
Implemented in ripple::NodeStore::DatabaseShardImp, ripple::NodeStore::DatabaseNodeImp, and ripple::NodeStore::DatabaseRotatingImp.
|
pure virtualinherited |
Store the object.
The caller's Blob parameter is overwritten.
type | The type of object. |
data | The payload of the object. The caller's variable is overwritten. |
hash | The 256-bit hash of the payload data. |
ledgerSeq | The sequence of the ledger the object belongs to. |
true
if the object was stored? Implemented in ripple::NodeStore::DatabaseNodeImp, ripple::NodeStore::DatabaseRotatingImp, and ripple::NodeStore::DatabaseShardImp.
|
pure virtualinherited |
|
pure virtualinherited |
|
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.
hash | The key of the object to retrieve. |
ledgerSeq | The sequence of the ledger where the object is stored. |
fetchType | the type of fetch, synchronous or asynchronous. |
Definition at line 252 of file Database.cpp.
|
privatepure virtualinherited |
|
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
hash | The key of the object to retrieve |
ledgerSeq | The sequence of the ledger where the object is stored, used by the shard store. |
callback | Callback function when read completes |
Reimplemented in ripple::NodeStore::DatabaseNodeImp.
Definition at line 198 of file Database.cpp.
|
pure virtualinherited |
Store a ledger from a different database.
srcLedger | The ledger to store. |
Implemented in ripple::NodeStore::DatabaseNodeImp, ripple::NodeStore::DatabaseShardImp, and ripple::NodeStore::DatabaseRotatingImp.
|
protectedinherited |
Definition at line 279 of file Database.cpp.
|
pure virtualinherited |
Remove expired entries from the positive and negative caches.
Implemented in ripple::NodeStore::DatabaseNodeImp, ripple::NodeStore::DatabaseShardImp, and ripple::NodeStore::DatabaseRotatingImp.
|
inherited |
Gather statistics pertaining to read and write activities.
obj | Json object reference into which to place counters. |
Definition at line 182 of file Database.h.
|
inherited |
Definition at line 188 of file Database.h.
|
inherited |
Definition at line 194 of file Database.h.
|
inherited |
Definition at line 200 of file Database.h.
|
inherited |
Definition at line 206 of file Database.h.
|
inherited |
Definition at line 378 of file Database.cpp.
|
inherited |
Returns the number of file descriptors the database expects to need.
Definition at line 216 of file Database.h.
|
virtualinherited |
Reimplemented in ripple::NodeStore::DatabaseShardImp.
Definition at line 165 of file Database.cpp.
|
inherited |
Definition at line 146 of file Database.cpp.
|
noexceptinherited |
Definition at line 230 of file Database.h.
|
noexceptinherited |
Definition at line 238 of file Database.h.
|
noexceptinherited |
Definition at line 246 of file Database.h.
|
noexceptinherited |
Calculates the first ledger sequence for a given shard index.
shardIndex | The shard index considered |
Definition at line 257 of file Database.h.
|
noexceptinherited |
Calculates the last ledger sequence for a given shard index.
shardIndex | The shard index considered |
Definition at line 271 of file Database.h.
|
noexceptinherited |
Calculates the shard index for a given ledger sequence.
ledgerSeq | ledger sequence |
Definition at line 283 of file Database.h.
|
noexceptinherited |
Calculates the maximum ledgers for a given shard index.
shardIndex | The shard index considered |
Definition at line 152 of file Database.cpp.
|
protectedinherited |
Definition at line 333 of file Database.h.
|
protectedinherited |
Definition at line 213 of file Database.cpp.
|
protectedinherited |
Definition at line 349 of file Database.h.
|
privatepure virtualinherited |
Visit every object in the database This is usually called during import.
Implemented in ripple::NodeStore::DatabaseShardImp, ripple::NodeStore::DatabaseNodeImp, and ripple::NodeStore::DatabaseRotatingImp.
|
privatevirtualinherited |
Retrieve backend read and write stats.
Reimplemented in ripple::NodeStore::DatabaseNodeImp.
Definition at line 401 of file Database.h.
|
privateinherited |
|
protectedinherited |
Definition at line 301 of file Database.h.
|
protectedinherited |
Definition at line 302 of file Database.h.
|
protectedinherited |
Definition at line 303 of file Database.h.
|
protectedinherited |
Definition at line 305 of file Database.h.
|
protectedinherited |
Definition at line 306 of file Database.h.
|
protectedinherited |
Definition at line 314 of file Database.h.
|
protectedinherited |
Definition at line 322 of file Database.h.
|
protectedinherited |
Definition at line 325 of file Database.h.
|
protectedinherited |
Definition at line 330 of file Database.h.
|
privateinherited |
Definition at line 357 of file Database.h.
|
privateinherited |
Definition at line 358 of file Database.h.
|
privateinherited |
Definition at line 359 of file Database.h.
|
privateinherited |
Definition at line 360 of file Database.h.
|
privateinherited |
Definition at line 361 of file Database.h.
|
mutableprivateinherited |
Definition at line 363 of file Database.h.
|
privateinherited |
Definition at line 364 of file Database.h.
|
privateinherited |
Definition at line 372 of file Database.h.
|
privateinherited |
Definition at line 374 of file Database.h.
|
privateinherited |
Definition at line 375 of file Database.h.
|
privateinherited |
Definition at line 376 of file Database.h.