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

bool open (std::lock_guard< std::mutex > const &lock)
 
bool initSQLite (std::lock_guard< std::mutex > const &)
 
bool storeSQLite (std::shared_ptr< Ledger const > const &ledger)
 
void setFileStats (std::lock_guard< std::mutex > const &)
 
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::uint64_t fileSz_ {0}
 
std::uint32_t fdRequired_ {0}
 
std::unique_ptr< Backendbackend_
 
std::atomic< std::uint32_tbackendCount_ {0}
 
std::unique_ptr< DatabaseConlgrSQLiteDB_
 
std::unique_ptr< DatabaseContxSQLiteDB_
 
std::unique_ptr< AcquireInfoacquireInfo_
 
bool legacy_ {false}
 
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}
 
std::chrono::steady_clock::time_point lastAccess_
 

Detailed Description

Definition at line 53 of file 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 48 of file Shard.cpp.

◆ Shard() [4/4]

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

Definition at line 39 of file Shard.cpp.

◆ ~Shard()

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

Definition at line 64 of file 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 99 of file Shard.cpp.

◆ isOpen()

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

Returns true if the database are open.

Definition at line 131 of file 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 144 of file Shard.cpp.

◆ stop()

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

Notify shard to prepare for shutdown.

Definition at line 108 of file Shard.h.

◆ prepare()

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

Definition at line 188 of file Shard.cpp.

◆ storeNodeObject()

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

Definition at line 211 of file Shard.cpp.

◆ fetchNodeObject()

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

Definition at line 244 of file 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 292 of file Shard.cpp.

◆ setLedgerStored()

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

Definition at line 417 of file Shard.cpp.

◆ containsLedger()

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

Definition at line 508 of file Shard.cpp.

◆ index()

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

Definition at line 147 of file Shard.h.

◆ getDir()

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

Definition at line 153 of file Shard.h.

◆ getLastUse()

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

Definition at line 526 of file 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 533 of file Shard.cpp.

◆ getState()

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

Definition at line 168 of file 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 177 of file Shard.h.

◆ getWriteLoad()

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

Definition at line 540 of file 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 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 Shard.cpp.

◆ removeOnDestroy()

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

Enables removal of the shard directory on destruction.

Definition at line 204 of file Shard.h.

◆ getStoredSeqs()

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

Definition at line 210 of file 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 225 of file 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 237 of file Shard.h.

◆ open()

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

Definition at line 821 of file Shard.cpp.

◆ initSQLite()

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

Definition at line 948 of file Shard.cpp.

◆ storeSQLite()

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

Definition at line 1024 of file Shard.cpp.

◆ setFileStats()

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

Definition at line 1069 of file 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 1094 of file Shard.cpp.

◆ verifyFetch()

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

Definition at line 1180 of file Shard.cpp.

◆ makeBackendCount()

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

Definition at line 1218 of file Shard.cpp.

◆ callForSQL()

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

Definition at line 397 of file Shard.h.

◆ doCallForSQL() [1/2]

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

Definition at line 1241 of file 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 1249 of file Shard.cpp.

Member Data Documentation

◆ version

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

Definition at line 243 of file Shard.h.

◆ finalKey

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

Definition at line 248 of file Shard.h.

◆ app_

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

Definition at line 296 of file Shard.h.

◆ j_

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

Definition at line 297 of file Shard.h.

◆ mutex_

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

Definition at line 298 of file Shard.h.

◆ storedMutex_

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

Definition at line 299 of file Shard.h.

◆ index_

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

Definition at line 302 of file Shard.h.

◆ firstSeq_

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

Definition at line 305 of file Shard.h.

◆ lastSeq_

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

Definition at line 308 of file Shard.h.

◆ maxLedgers_

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

Definition at line 312 of file Shard.h.

◆ dir_

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

Definition at line 315 of file Shard.h.

◆ fileSz_

std::uint64_t ripple::NodeStore::Shard::fileSz_ {0}
private

Definition at line 318 of file Shard.h.

◆ fdRequired_

std::uint32_t ripple::NodeStore::Shard::fdRequired_ {0}
private

Definition at line 321 of file Shard.h.

◆ backend_

std::unique_ptr<Backend> ripple::NodeStore::Shard::backend_
private

Definition at line 324 of file Shard.h.

◆ backendCount_

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

Definition at line 326 of file Shard.h.

◆ lgrSQLiteDB_

std::unique_ptr<DatabaseCon> ripple::NodeStore::Shard::lgrSQLiteDB_
private

Definition at line 329 of file Shard.h.

◆ txSQLiteDB_

std::unique_ptr<DatabaseCon> ripple::NodeStore::Shard::txSQLiteDB_
private

Definition at line 332 of file Shard.h.

◆ acquireInfo_

std::unique_ptr<AcquireInfo> ripple::NodeStore::Shard::acquireInfo_
private

Definition at line 336 of file Shard.h.

◆ legacy_

bool ripple::NodeStore::Shard::legacy_ {false}
private

Definition at line 340 of file Shard.h.

◆ stop_

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

Definition at line 343 of file Shard.h.

◆ busy_

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

Definition at line 346 of file Shard.h.

◆ state_

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

Definition at line 349 of file Shard.h.

◆ progress_

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

Definition at line 352 of file Shard.h.

◆ removeOnDestroy_

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

Definition at line 355 of file Shard.h.

◆ lastAccess_

std::chrono::steady_clock::time_point ripple::NodeStore::Shard::lastAccess_
private

Definition at line 358 of file Shard.h.