rippled
Classes | Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | List of all members
ripple::NodeStore::Shard Class Referencefinal
Collaboration diagram for ripple::NodeStore::Shard:
Collaboration graph
[legend]

Classes

struct  AcquireInfo
 
class  Count
 
struct  StoreLedgerResult
 Store a ledger. More...
 

Public Member Functions

 Shard (Shard const &)=delete
 Copy constructor (disallowed) More...
 
 Shard (Shard &&)=delete
 Move constructor (disallowed) More...
 
Shardoperator= (Shard const &)=delete
 
Shardoperator= (Shard &&)=delete
 
 Shard (Application &app, DatabaseShard const &db, std::uint32_t index, boost::filesystem::path const &dir, beast::Journal j)
 
 Shard (Application &app, DatabaseShard const &db, std::uint32_t index, beast::Journal j)
 
 ~Shard ()
 
bool init (Scheduler &scheduler, nudb::context &context)
 Initialize shard. More...
 
bool isOpen () const
 Returns true if the database are open. More...
 
bool tryClose ()
 Try to close databases if not in use. More...
 
void stop () noexcept
 Notify shard to prepare for shutdown. More...
 
std::optional< std::uint32_tprepare ()
 
bool storeNodeObject (std::shared_ptr< NodeObject > const &nodeObject)
 
std::shared_ptr< NodeObjectfetchNodeObject (uint256 const &hash, FetchReport &fetchReport)
 
StoreLedgerResult storeLedger (std::shared_ptr< Ledger const > const &srcLedger, std::shared_ptr< Ledger const > const &next)
 
bool setLedgerStored (std::shared_ptr< Ledger const > const &ledger)
 
bool containsLedger (std::uint32_t ledgerSeq) const
 
std::uint32_t index () const noexcept
 
boost::filesystem::path const & getDir () const noexcept
 
std::chrono::steady_clock::time_point getLastUse () const
 
std::pair< std::uint64_t, std::uint32_tgetFileInfo () const
 Returns a pair where the first item describes the storage space utilized and the second item is the number of file descriptors required. More...
 
ShardState getState () const noexcept
 
std::uint32_t getPercentProgress () const noexcept
 Returns a percent signifying how complete the current state of the shard is. More...
 
std::int32_t getWriteLoad ()
 
bool isLegacy () const
 Returns true if shard is older, without final key data. More...
 
bool finalize (bool writeSQLite, std::optional< uint256 > const &referenceHash)
 Finalize shard by walking its ledgers, verifying each Merkle tree and creating a deterministic backend. More...
 
void removeOnDestroy () noexcept
 Enables removal of the shard directory on destruction. More...
 
std::string getStoredSeqs ()
 
template<typename... Args>
bool callForLedgerSQL (std::function< bool(Args... args)> const &callback)
 Invoke a callback on the ledger SQLite db. More...
 
template<typename... Args>
bool callForTransactionSQL (std::function< bool(Args... args)> const &callback)
 Invoke a callback on the transaction SQLite db. More...
 

Static Public Attributes

static constexpr std::uint32_t version {2}
 
static const uint256 finalKey {0}
 

Private Member Functions

GUARDED_BY(mutex_) std GUARDED_BY(mutex_) std std::unique_ptr< Backend > backend_ GUARDED_BY (mutex_)
 
std::unique_ptr< DatabaseCon > lgrSQLiteDB_ GUARDED_BY (mutex_)
 
std::unique_ptr< DatabaseCon > txSQLiteDB_ GUARDED_BY (mutex_)
 
std::unique_ptr< AcquireInfo > acquireInfo_ GUARDED_BY (mutex_)
 
 GUARDED_BY (mutex_) bool legacy_
 
std::chrono::steady_clock::time_point lastAccess_ GUARDED_BY (mutex_)
 
bool open (std::lock_guard< std::mutex > const &lock) REQUIRES(mutex_)
 
bool initSQLite (std::lock_guard< std::mutex > const &) REQUIRES(mutex_)
 
bool storeSQLite (std::shared_ptr< Ledger const > const &ledger)
 
void setFileStats (std::lock_guard< std::mutex > const &) REQUIRES(mutex_)
 
bool verifyLedger (std::shared_ptr< Ledger const > const &ledger, std::shared_ptr< Ledger const > const &next, std::shared_ptr< DeterministicShard > const &dShard) const
 
std::shared_ptr< NodeObjectverifyFetch (uint256 const &hash) const
 
Shard::Count makeBackendCount ()
 
template<typename... Args>
bool callForSQL (std::function< bool(Args... args)> const &callback, LockedSociSession &&db)
 
bool doCallForSQL (std::function< bool(soci::session &session)> const &callback, LockedSociSession &&db)
 
bool doCallForSQL (std::function< bool(soci::session &session, std::uint32_t shardIndex)> const &callback, LockedSociSession &&db)
 

Private Attributes

Applicationapp_
 
const beast::Journal j_
 
std::mutex mutex_
 
std::mutex storedMutex_
 
const std::uint32_t index_
 
const std::uint32_t firstSeq_
 
const std::uint32_t lastSeq_
 
const std::uint32_t maxLedgers_
 
const boost::filesystem::path dir_
 
std::atomic< std::uint32_tbackendCount_ {0}
 
std::atomic< bool > stop_ {false}
 
std::atomic< bool > busy_ {false}
 
std::atomic< ShardStatestate_ {ShardState::acquire}
 
std::atomic< std::uint32_tprogress_ {0}
 
std::atomic< bool > removeOnDestroy_ {false}
 

Detailed Description

Definition at line 55 of file nodestore/impl/Shard.h.

Constructor & Destructor Documentation

◆ Shard() [1/4]

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

Copy constructor (disallowed)

◆ Shard() [2/4]

ripple::NodeStore::Shard::Shard ( Shard &&  )
delete

Move constructor (disallowed)

◆ Shard() [3/4]

ripple::NodeStore::Shard::Shard ( Application app,
DatabaseShard const &  db,
std::uint32_t  index,
boost::filesystem::path const &  dir,
beast::Journal  j 
)

Definition at line 44 of file nodestore/impl/Shard.cpp.

◆ Shard() [4/4]

ripple::NodeStore::Shard::Shard ( Application app,
DatabaseShard const &  db,
std::uint32_t  index,
beast::Journal  j 
)

Definition at line 35 of file nodestore/impl/Shard.cpp.

◆ ~Shard()

ripple::NodeStore::Shard::~Shard ( )

Definition at line 60 of file nodestore/impl/Shard.cpp.

Member Function Documentation

◆ operator=() [1/2]

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

◆ operator=() [2/2]

Shard& ripple::NodeStore::Shard::operator= ( Shard &&  )
delete

◆ init()

bool ripple::NodeStore::Shard::init ( Scheduler scheduler,
nudb::context &  context 
)

Initialize shard.

Parameters
schedulerThe scheduler to use for performing asynchronous tasks.
contextThe context to use for the backend.

Definition at line 95 of file nodestore/impl/Shard.cpp.

◆ isOpen()

bool ripple::NodeStore::Shard::isOpen ( ) const

Returns true if the database are open.

Definition at line 127 of file nodestore/impl/Shard.cpp.

◆ tryClose()

bool ripple::NodeStore::Shard::tryClose ( )

Try to close databases if not in use.

Returns
true if databases were closed.

Definition at line 140 of file nodestore/impl/Shard.cpp.

◆ stop()

void ripple::NodeStore::Shard::stop ( )
noexcept

Notify shard to prepare for shutdown.

Definition at line 110 of file nodestore/impl/Shard.h.

◆ prepare()

std::optional< std::uint32_t > ripple::NodeStore::Shard::prepare ( )

Definition at line 184 of file nodestore/impl/Shard.cpp.

◆ storeNodeObject()

bool ripple::NodeStore::Shard::storeNodeObject ( std::shared_ptr< NodeObject > const &  nodeObject)

Definition at line 207 of file nodestore/impl/Shard.cpp.

◆ fetchNodeObject()

std::shared_ptr< NodeObject > ripple::NodeStore::Shard::fetchNodeObject ( uint256 const &  hash,
FetchReport fetchReport 
)

Definition at line 241 of file nodestore/impl/Shard.cpp.

◆ storeLedger()

Shard::StoreLedgerResult ripple::NodeStore::Shard::storeLedger ( std::shared_ptr< Ledger const > const &  srcLedger,
std::shared_ptr< Ledger const > const &  next 
)

Definition at line 290 of file nodestore/impl/Shard.cpp.

◆ setLedgerStored()

bool ripple::NodeStore::Shard::setLedgerStored ( std::shared_ptr< Ledger const > const &  ledger)

Definition at line 416 of file nodestore/impl/Shard.cpp.

◆ containsLedger()

bool ripple::NodeStore::Shard::containsLedger ( std::uint32_t  ledgerSeq) const

Definition at line 507 of file nodestore/impl/Shard.cpp.

◆ index()

std::uint32_t ripple::NodeStore::Shard::index ( ) const
noexcept

Definition at line 149 of file nodestore/impl/Shard.h.

◆ getDir()

boost::filesystem::path const& ripple::NodeStore::Shard::getDir ( ) const
noexcept

Definition at line 155 of file nodestore/impl/Shard.h.

◆ getLastUse()

std::chrono::steady_clock::time_point ripple::NodeStore::Shard::getLastUse ( ) const

Definition at line 525 of file nodestore/impl/Shard.cpp.

◆ getFileInfo()

std::pair< std::uint64_t, std::uint32_t > ripple::NodeStore::Shard::getFileInfo ( ) const

Returns a pair where the first item describes the storage space utilized and the second item is the number of file descriptors required.

Definition at line 532 of file nodestore/impl/Shard.cpp.

◆ getState()

ShardState ripple::NodeStore::Shard::getState ( ) const
noexcept

Definition at line 170 of file nodestore/impl/Shard.h.

◆ getPercentProgress()

std::uint32_t ripple::NodeStore::Shard::getPercentProgress ( ) const
noexcept

Returns a percent signifying how complete the current state of the shard is.

Definition at line 179 of file nodestore/impl/Shard.h.

◆ getWriteLoad()

std::int32_t ripple::NodeStore::Shard::getWriteLoad ( )

Definition at line 539 of file nodestore/impl/Shard.cpp.

◆ isLegacy()

bool ripple::NodeStore::Shard::isLegacy ( ) const

Returns true if shard is older, without final key data.

Definition at line 549 of file nodestore/impl/Shard.cpp.

◆ finalize()

bool ripple::NodeStore::Shard::finalize ( bool  writeSQLite,
std::optional< uint256 > const &  referenceHash 
)

Finalize shard by walking its ledgers, verifying each Merkle tree and creating a deterministic backend.

Parameters
writeSQLiteIf true, SQLite entries will be rewritten using verified backend data.
referenceHashIf present, this hash must match the hash of the last ledger in the shard.

Definition at line 556 of file nodestore/impl/Shard.cpp.

◆ removeOnDestroy()

void ripple::NodeStore::Shard::removeOnDestroy ( )
noexcept

Enables removal of the shard directory on destruction.

Definition at line 206 of file nodestore/impl/Shard.h.

◆ getStoredSeqs()

std::string ripple::NodeStore::Shard::getStoredSeqs ( )

Definition at line 212 of file nodestore/impl/Shard.h.

◆ callForLedgerSQL()

template<typename... Args>
bool ripple::NodeStore::Shard::callForLedgerSQL ( std::function< bool(Args... args)> const &  callback)

Invoke a callback on the ledger SQLite db.

Parameters
callbackCallback function to call.
Returns
Value returned by callback function.

Definition at line 228 of file nodestore/impl/Shard.h.

◆ callForTransactionSQL()

template<typename... Args>
bool ripple::NodeStore::Shard::callForTransactionSQL ( std::function< bool(Args... args)> const &  callback)

Invoke a callback on the transaction SQLite db.

Parameters
callbackCallback function to call.
Returns
Value returned by callback function.

Definition at line 240 of file nodestore/impl/Shard.h.

◆ GUARDED_BY() [1/6]

GUARDED_BY (mutex_) std GUARDED_BY (mutex_) std std::unique_ptr<Backend> backend_ ripple::NodeStore::Shard::GUARDED_BY ( mutex_  )
private

◆ GUARDED_BY() [2/6]

std::unique_ptr<DatabaseCon> lgrSQLiteDB_ ripple::NodeStore::Shard::GUARDED_BY ( mutex_  )
private

◆ GUARDED_BY() [3/6]

std::unique_ptr<DatabaseCon> txSQLiteDB_ ripple::NodeStore::Shard::GUARDED_BY ( mutex_  )
private

◆ GUARDED_BY() [4/6]

std::unique_ptr<AcquireInfo> acquireInfo_ ripple::NodeStore::Shard::GUARDED_BY ( mutex_  )
private

◆ GUARDED_BY() [5/6]

ripple::NodeStore::Shard::GUARDED_BY ( mutex_  )
private

Definition at line 344 of file nodestore/impl/Shard.h.

◆ GUARDED_BY() [6/6]

std::chrono::steady_clock::time_point lastAccess_ ripple::NodeStore::Shard::GUARDED_BY ( mutex_  )
private

◆ open()

bool ripple::NodeStore::Shard::open ( std::lock_guard< std::mutex > const &  lock)
private

Definition at line 831 of file nodestore/impl/Shard.cpp.

◆ initSQLite()

bool ripple::NodeStore::Shard::initSQLite ( std::lock_guard< std::mutex > const &  )
private

Definition at line 958 of file nodestore/impl/Shard.cpp.

◆ storeSQLite()

bool ripple::NodeStore::Shard::storeSQLite ( std::shared_ptr< Ledger const > const &  ledger)
private

Definition at line 1034 of file nodestore/impl/Shard.cpp.

◆ setFileStats()

void ripple::NodeStore::Shard::setFileStats ( std::lock_guard< std::mutex > const &  )
private

Definition at line 1081 of file nodestore/impl/Shard.cpp.

◆ verifyLedger()

bool ripple::NodeStore::Shard::verifyLedger ( std::shared_ptr< Ledger const > const &  ledger,
std::shared_ptr< Ledger const > const &  next,
std::shared_ptr< DeterministicShard > const &  dShard 
) const
private

Definition at line 1106 of file nodestore/impl/Shard.cpp.

◆ verifyFetch()

std::shared_ptr< NodeObject > ripple::NodeStore::Shard::verifyFetch ( uint256 const &  hash) const
private

Definition at line 1192 of file nodestore/impl/Shard.cpp.

◆ makeBackendCount()

Shard::Count ripple::NodeStore::Shard::makeBackendCount ( )
private

Definition at line 1231 of file nodestore/impl/Shard.cpp.

◆ callForSQL()

template<typename... Args>
bool ripple::NodeStore::Shard::callForSQL ( std::function< bool(Args... args)> const &  callback,
LockedSociSession &&  db 
)
private

Definition at line 402 of file nodestore/impl/Shard.h.

◆ doCallForSQL() [1/2]

bool ripple::NodeStore::Shard::doCallForSQL ( std::function< bool(soci::session &session)> const &  callback,
LockedSociSession &&  db 
)
private

Definition at line 1254 of file nodestore/impl/Shard.cpp.

◆ doCallForSQL() [2/2]

bool ripple::NodeStore::Shard::doCallForSQL ( std::function< bool(soci::session &session, std::uint32_t shardIndex)> const &  callback,
LockedSociSession &&  db 
)
private

Definition at line 1262 of file nodestore/impl/Shard.cpp.

Member Data Documentation

◆ version

constexpr std::uint32_t ripple::NodeStore::Shard::version {2}
staticconstexpr

Definition at line 246 of file nodestore/impl/Shard.h.

◆ finalKey

const uint256 ripple::NodeStore::Shard::finalKey {0}
static

Definition at line 251 of file nodestore/impl/Shard.h.

◆ app_

Application& ripple::NodeStore::Shard::app_
private

Definition at line 299 of file nodestore/impl/Shard.h.

◆ j_

const beast::Journal ripple::NodeStore::Shard::j_
private

Definition at line 300 of file nodestore/impl/Shard.h.

◆ mutex_

std::mutex ripple::NodeStore::Shard::mutex_
mutableprivate

Definition at line 301 of file nodestore/impl/Shard.h.

◆ storedMutex_

std::mutex ripple::NodeStore::Shard::storedMutex_
mutableprivate

Definition at line 302 of file nodestore/impl/Shard.h.

◆ index_

const std::uint32_t ripple::NodeStore::Shard::index_
private

Definition at line 305 of file nodestore/impl/Shard.h.

◆ firstSeq_

const std::uint32_t ripple::NodeStore::Shard::firstSeq_
private

Definition at line 308 of file nodestore/impl/Shard.h.

◆ lastSeq_

const std::uint32_t ripple::NodeStore::Shard::lastSeq_
private

Definition at line 311 of file nodestore/impl/Shard.h.

◆ maxLedgers_

const std::uint32_t ripple::NodeStore::Shard::maxLedgers_
private

Definition at line 315 of file nodestore/impl/Shard.h.

◆ dir_

const boost::filesystem::path ripple::NodeStore::Shard::dir_
private

Definition at line 318 of file nodestore/impl/Shard.h.

◆ backendCount_

std::atomic<std::uint32_t> ripple::NodeStore::Shard::backendCount_ {0}
private

Definition at line 329 of file nodestore/impl/Shard.h.

◆ stop_

std::atomic<bool> ripple::NodeStore::Shard::stop_ {false}
private

Definition at line 347 of file nodestore/impl/Shard.h.

◆ busy_

std::atomic<bool> ripple::NodeStore::Shard::busy_ {false}
private

Definition at line 350 of file nodestore/impl/Shard.h.

◆ state_

std::atomic<ShardState> ripple::NodeStore::Shard::state_ {ShardState::acquire}
private

Definition at line 353 of file nodestore/impl/Shard.h.

◆ progress_

std::atomic<std::uint32_t> ripple::NodeStore::Shard::progress_ {0}
private

Definition at line 356 of file nodestore/impl/Shard.h.

◆ removeOnDestroy_

std::atomic<bool> ripple::NodeStore::Shard::removeOnDestroy_ {false}
private

Definition at line 359 of file nodestore/impl/Shard.h.