rippled
Classes | Public Types | 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 Types

enum  State { State::acquire, State::complete, State::finalizing, State::final }
 

Public Member Functions

 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 ()
 Notify shard to prepare for shutdown. More...
 
boost::optional< std::uint32_tprepare ()
 
bool storeNodeObject (std::shared_ptr< NodeObject > const &nodeObject)
 
std::shared_ptr< NodeObjectfetchNodeObject (uint256 const &hash, FetchReport &fetchReport)
 
bool fetchNodeObjectFromCache (uint256 const &hash, std::shared_ptr< NodeObject > &nodeObject)
 
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
 
void sweep ()
 
std::uint32_t index () const
 
boost::filesystem::path const & getDir () const
 
int getDesiredAsyncReadCount ()
 
float getCacheHitRate ()
 
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...
 
State getState () const
 
std::int32_t getWriteLoad ()
 
bool isLegacy () const
 Returns true if shard is older, without final key data. More...
 
bool finalize (bool const writeSQLite, boost::optional< uint256 > const &referenceHash)
 Finalize shard by walking its ledgers and verifying each Merkle tree. More...
 
void removeOnDestroy ()
 Enables removal of the shard directory on destruction. More...
 

Static Public Attributes

static constexpr State acquire = State::acquire
 
static constexpr State complete = State::complete
 
static constexpr State finalizing = State::finalizing
 
static constexpr State final = State::final
 
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, std::lock_guard< std::mutex > const &)
 
void setFileStats (std::lock_guard< std::mutex > const &)
 
bool verifyLedger (std::shared_ptr< Ledger const > const &ledger, std::shared_ptr< Ledger const > const &next) const
 
std::shared_ptr< NodeObjectverifyFetch (uint256 const &hash) const
 
Shard::Count makeBackendCount ()
 

Private Attributes

Applicationapp_
 
const beast::Journal j_
 
std::mutex mutex_
 
const std::uint32_t index_
 
const std::uint32_t firstSeq_
 
const std::uint32_t lastSeq_
 
const std::uint32_t maxLedgers_
 
std::unique_ptr< PCachepCache_
 
std::unique_ptr< NCachenCache_
 
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< Statestate_ {State::acquire}
 
std::atomic< bool > removeOnDestroy_ {false}
 
std::chrono::steady_clock::time_point lastAccess_
 

Detailed Description

Definition at line 51 of file Shard.h.

Member Enumeration Documentation

◆ State

Enumerator
acquire 
complete 
finalizing 
final 

Definition at line 54 of file Shard.h.

Constructor & Destructor Documentation

◆ Shard() [1/2]

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

Definition at line 45 of file Shard.cpp.

◆ Shard() [2/2]

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

Definition at line 36 of file Shard.cpp.

◆ ~Shard()

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

Definition at line 63 of file Shard.cpp.

Member Function Documentation

◆ 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 98 of file Shard.cpp.

◆ isOpen()

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

Returns true if the database are open.

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

◆ stop()

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

Notify shard to prepare for shutdown.

Definition at line 104 of file Shard.h.

◆ prepare()

boost::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 247 of file Shard.cpp.

◆ fetchNodeObjectFromCache()

bool ripple::NodeStore::Shard::fetchNodeObjectFromCache ( uint256 const &  hash,
std::shared_ptr< NodeObject > &  nodeObject 
)

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

◆ setLedgerStored()

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

Definition at line 460 of file Shard.cpp.

◆ containsLedger()

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

Definition at line 513 of file Shard.cpp.

◆ sweep()

void ripple::NodeStore::Shard::sweep ( )

Definition at line 531 of file Shard.cpp.

◆ index()

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

Definition at line 151 of file Shard.h.

◆ getDir()

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

Definition at line 157 of file Shard.h.

◆ getDesiredAsyncReadCount()

int ripple::NodeStore::Shard::getDesiredAsyncReadCount ( )

Definition at line 550 of file Shard.cpp.

◆ getCacheHitRate()

float ripple::NodeStore::Shard::getCacheHitRate ( )

Definition at line 559 of file Shard.cpp.

◆ getLastUse()

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

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

◆ getState()

State ripple::NodeStore::Shard::getState ( ) const

Definition at line 178 of file Shard.h.

◆ getWriteLoad()

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

Definition at line 582 of file Shard.cpp.

◆ isLegacy()

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

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

Definition at line 591 of file Shard.cpp.

◆ finalize()

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

Finalize shard by walking its ledgers and verifying each Merkle tree.

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 598 of file Shard.cpp.

◆ removeOnDestroy()

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

Enables removal of the shard directory on destruction.

Definition at line 206 of file Shard.h.

◆ open()

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

Definition at line 851 of file Shard.cpp.

◆ initSQLite()

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

Definition at line 1001 of file Shard.cpp.

◆ storeSQLite()

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

Definition at line 1075 of file Shard.cpp.

◆ setFileStats()

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

Definition at line 1245 of file Shard.cpp.

◆ verifyLedger()

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

Definition at line 1270 of file Shard.cpp.

◆ verifyFetch()

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

Definition at line 1351 of file Shard.cpp.

◆ makeBackendCount()

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

Definition at line 1389 of file Shard.cpp.

Member Data Documentation

◆ acquire

constexpr State ripple::NodeStore::Shard::acquire = State::acquire
staticconstexpr

Definition at line 61 of file Shard.h.

◆ complete

constexpr State ripple::NodeStore::Shard::complete = State::complete
staticconstexpr

Definition at line 62 of file Shard.h.

◆ finalizing

constexpr State ripple::NodeStore::Shard::finalizing = State::finalizing
staticconstexpr

Definition at line 63 of file Shard.h.

◆ final

constexpr State ripple::NodeStore::Shard::final = State::final
staticconstexpr

Definition at line 64 of file Shard.h.

◆ version

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

Definition at line 212 of file Shard.h.

◆ finalKey

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

Definition at line 217 of file Shard.h.

◆ app_

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

Definition at line 264 of file Shard.h.

◆ j_

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

Definition at line 265 of file Shard.h.

◆ mutex_

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

Definition at line 266 of file Shard.h.

◆ index_

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

Definition at line 269 of file Shard.h.

◆ firstSeq_

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

Definition at line 272 of file Shard.h.

◆ lastSeq_

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

Definition at line 275 of file Shard.h.

◆ maxLedgers_

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

Definition at line 279 of file Shard.h.

◆ pCache_

std::unique_ptr<PCache> ripple::NodeStore::Shard::pCache_
private

Definition at line 282 of file Shard.h.

◆ nCache_

std::unique_ptr<NCache> ripple::NodeStore::Shard::nCache_
private

Definition at line 285 of file Shard.h.

◆ dir_

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

Definition at line 288 of file Shard.h.

◆ fileSz_

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

Definition at line 291 of file Shard.h.

◆ fdRequired_

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

Definition at line 294 of file Shard.h.

◆ backend_

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

Definition at line 297 of file Shard.h.

◆ backendCount_

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

Definition at line 299 of file Shard.h.

◆ lgrSQLiteDB_

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

Definition at line 302 of file Shard.h.

◆ txSQLiteDB_

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

Definition at line 305 of file Shard.h.

◆ acquireInfo_

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

Definition at line 309 of file Shard.h.

◆ legacy_

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

Definition at line 313 of file Shard.h.

◆ stop_

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

Definition at line 316 of file Shard.h.

◆ state_

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

Definition at line 318 of file Shard.h.

◆ removeOnDestroy_

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

Definition at line 321 of file Shard.h.

◆ lastAccess_

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

Definition at line 324 of file Shard.h.