xrpld
Loading...
Searching...
No Matches
xrpl::SHAMapStoreImp Class Reference

#include <SHAMapStoreImp.h>

Inheritance diagram for xrpl::SHAMapStoreImp:
Collaboration diagram for xrpl::SHAMapStoreImp:

Classes

class  SavedStateDB

Public Member Functions

 SHAMapStoreImp (Application &app, NodeStore::Scheduler &scheduler, beast::Journal journal)
std::uint32_t clampFetchDepth (std::uint32_t fetchDepth) const override
std::unique_ptr< NodeStore::DatabasemakeNodeStore (int readThreads) override
LedgerIndex setCanDelete (LedgerIndex seq) override
 Highest ledger that may be deleted.
bool advisoryDelete () const override
 Whether advisory delete is enabled.
LedgerIndex getLastRotated () override
 Maximum ledger that has been deleted, or will be deleted if currently in the act of online deletion.
LedgerIndex getCanDelete () override
 Highest ledger that may be deleted.
void onLedgerClosed (std::shared_ptr< Ledger const > const &ledger) override
 Called by LedgerMaster every time a ledger validates.
void rendezvous () const override
int fdRequired () const override
 Returns the number of file descriptors that are needed.
std::optional< LedgerIndexminimumOnline () const override
 The minimum ledger to try and maintain in our database.
void start () override
void stop () override

Private Types

enum class  HealthResult { Stopping , KeepGoing }
 This is a health check for online deletion that waits until xrpld is stable before returning. More...

Private Member Functions

bool copyNode (std::uint64_t &nodeCount, SHAMapTreeNode const &node)
void run ()
void dbPaths ()
std::unique_ptr< NodeStore::BackendmakeBackendRotating (std::string path=std::string())
template<class CacheInstance>
bool freshenCache (CacheInstance &cache)
void clearSql (LedgerIndex lastRotated, std::string const &tableName, std::function< std::optional< LedgerIndex >()> const &getMinSeq, std::function< void(LedgerIndex)> const &deleteBeforeSeq)
 delete from sqlite table in batches to not lock the db excessively.
void clearCaches (LedgerIndex validatedSeq)
void freshenCaches ()
void clearPrior (LedgerIndex lastRotated)
HealthResult healthWait ()

Private Attributes

Applicationapp_
std::string const dbName_ = "state"
std::string const dbPrefix_ = "rippledb"
std::uint64_t const checkHealthInterval_ = 1000
std::atomic< LedgerIndexminimumOnline_
NodeStore::Schedulerscheduler_
beast::Journal const journal_
NodeStore::DatabaseRotatingdbRotating_ = nullptr
SavedStateDB stateDb_
std::thread thread_
bool stop_ = false
bool healthy_ = true
std::condition_variable cond_
std::condition_variable rendezvous_
std::mutex mutex_
std::shared_ptr< Ledger const > newLedger_
std::atomic< bool > working_
std::atomic< LedgerIndexcanDelete_
int fdRequired_ = 0
std::uint32_t deleteInterval_ = 0
bool advisoryDelete_ = false
std::uint32_t deleteBatch_ = 100
std::chrono::milliseconds backOff_ {100}
std::chrono::seconds ageThreshold_ {60}
std::chrono::seconds recoveryWaitTime_ {5}
 If the node is out of sync during an online_delete healthWait() call, sleep the thread for this time, and continue checking until recovery.
NetworkOPsnetOPs_ = nullptr
LedgerMasterledgerMaster_ = nullptr
FullBelowCachefullBelowCache_ = nullptr
TreeNodeCachetreeNodeCache_ = nullptr

Static Private Attributes

static std::uint32_t const kMinimumDeletionInterval = 256
static std::uint32_t const kMinimumDeletionIntervalSa = 8
static constexpr auto kNodeStoreName = "NodeStore"

Detailed Description

Definition at line 21 of file SHAMapStoreImp.h.

Member Enumeration Documentation

◆ HealthResult

enum class xrpl::SHAMapStoreImp::HealthResult
strongprivate

This is a health check for online deletion that waits until xrpld is stable before returning.

It returns an indication of whether the server is stopping.

Returns
Whether the server is stopping.
Enumerator
Stopping 
KeepGoing 

Definition at line 208 of file SHAMapStoreImp.h.

Constructor & Destructor Documentation

◆ SHAMapStoreImp()

xrpl::SHAMapStoreImp::SHAMapStoreImp ( Application & app,
NodeStore::Scheduler & scheduler,
beast::Journal journal )

Definition at line 92 of file SHAMapStoreImp.cpp.

Member Function Documentation

◆ clampFetchDepth()

std::uint32_t xrpl::SHAMapStoreImp::clampFetchDepth ( std::uint32_t fetchDepth) const
overridevirtual

Implements xrpl::SHAMapStore.

Definition at line 107 of file SHAMapStoreImp.h.

◆ makeNodeStore()

std::unique_ptr< NodeStore::Database > xrpl::SHAMapStoreImp::makeNodeStore ( int readThreads)
overridevirtual

Implements xrpl::SHAMapStore.

Definition at line 166 of file SHAMapStoreImp.cpp.

◆ setCanDelete()

LedgerIndex xrpl::SHAMapStoreImp::setCanDelete ( LedgerIndex canDelete)
overridevirtual

Highest ledger that may be deleted.

Implements xrpl::SHAMapStore.

Definition at line 116 of file SHAMapStoreImp.h.

◆ advisoryDelete()

bool xrpl::SHAMapStoreImp::advisoryDelete ( ) const
overridevirtual

Whether advisory delete is enabled.

Implements xrpl::SHAMapStore.

Definition at line 124 of file SHAMapStoreImp.h.

◆ getLastRotated()

LedgerIndex xrpl::SHAMapStoreImp::getLastRotated ( )
overridevirtual

Maximum ledger that has been deleted, or will be deleted if currently in the act of online deletion.

Implements xrpl::SHAMapStore.

Definition at line 132 of file SHAMapStoreImp.h.

◆ getCanDelete()

LedgerIndex xrpl::SHAMapStoreImp::getCanDelete ( )
overridevirtual

Highest ledger that may be deleted.

Implements xrpl::SHAMapStore.

Definition at line 140 of file SHAMapStoreImp.h.

◆ onLedgerClosed()

void xrpl::SHAMapStoreImp::onLedgerClosed ( std::shared_ptr< Ledger const > const & ledger)
overridevirtual

Called by LedgerMaster every time a ledger validates.

Implements xrpl::SHAMapStore.

Definition at line 226 of file SHAMapStoreImp.cpp.

◆ rendezvous()

void xrpl::SHAMapStoreImp::rendezvous ( ) const
overridevirtual

Implements xrpl::SHAMapStore.

Definition at line 237 of file SHAMapStoreImp.cpp.

◆ fdRequired()

int xrpl::SHAMapStoreImp::fdRequired ( ) const
overridevirtual

Returns the number of file descriptors that are needed.

Implements xrpl::SHAMapStore.

Definition at line 247 of file SHAMapStoreImp.cpp.

◆ minimumOnline()

std::optional< LedgerIndex > xrpl::SHAMapStoreImp::minimumOnline ( ) const
overridevirtual

The minimum ledger to try and maintain in our database.

This defines the lower bound for attempting to acquire historical ledgers over the peer to peer network.

If online_delete is enabled, then each time online_delete executes and just prior to clearing SQL databases of historical ledgers, move the value forward to one past the greatest ledger being deleted. This minimizes fetching of ledgers that are in the process of being deleted. Without online_delete or before online_delete is executed, this value is always the minimum value persisted in the ledger database, if any.

Returns
The minimum ledger sequence to keep online based on the description above. If not set, then an unseated optional.

Implements xrpl::SHAMapStore.

Definition at line 659 of file SHAMapStoreImp.cpp.

◆ copyNode()

bool xrpl::SHAMapStoreImp::copyNode ( std::uint64_t & nodeCount,
SHAMapTreeNode const & node )
private

Definition at line 253 of file SHAMapStoreImp.cpp.

◆ run()

void xrpl::SHAMapStoreImp::run ( )
private

Definition at line 268 of file SHAMapStoreImp.cpp.

◆ dbPaths()

void xrpl::SHAMapStoreImp::dbPaths ( )
private

Definition at line 387 of file SHAMapStoreImp.cpp.

◆ makeBackendRotating()

std::unique_ptr< NodeStore::Backend > xrpl::SHAMapStoreImp::makeBackendRotating ( std::string path = std::string())
private

Definition at line 486 of file SHAMapStoreImp.cpp.

◆ freshenCache()

template<class CacheInstance>
bool xrpl::SHAMapStoreImp::freshenCache ( CacheInstance & cache)
private

Definition at line 170 of file SHAMapStoreImp.h.

◆ clearSql()

void xrpl::SHAMapStoreImp::clearSql ( LedgerIndex lastRotated,
std::string const & tableName,
std::function< std::optional< LedgerIndex >()> const & getMinSeq,
std::function< void(LedgerIndex)> const & deleteBeforeSeq )
private

delete from sqlite table in batches to not lock the db excessively.

Pause briefly to extend access time to other users. Call with mutex object unlocked.

Definition at line 514 of file SHAMapStoreImp.cpp.

◆ clearCaches()

void xrpl::SHAMapStoreImp::clearCaches ( LedgerIndex validatedSeq)
private

Definition at line 562 of file SHAMapStoreImp.cpp.

◆ freshenCaches()

void xrpl::SHAMapStoreImp::freshenCaches ( )
private

Definition at line 572 of file SHAMapStoreImp.cpp.

◆ clearPrior()

void xrpl::SHAMapStoreImp::clearPrior ( LedgerIndex lastRotated)
private

Definition at line 581 of file SHAMapStoreImp.cpp.

◆ healthWait()

SHAMapStoreImp::HealthResult xrpl::SHAMapStoreImp::healthWait ( )
nodiscardprivate

Definition at line 623 of file SHAMapStoreImp.cpp.

◆ start()

void xrpl::SHAMapStoreImp::start ( )
overridevirtual

Implements xrpl::SHAMapStore.

Definition at line 214 of file SHAMapStoreImp.h.

◆ stop()

void xrpl::SHAMapStoreImp::stop ( )
overridevirtual

Implements xrpl::SHAMapStore.

Definition at line 645 of file SHAMapStoreImp.cpp.

Member Data Documentation

◆ app_

Application& xrpl::SHAMapStoreImp::app_
private

Definition at line 53 of file SHAMapStoreImp.h.

◆ dbName_

std::string const xrpl::SHAMapStoreImp::dbName_ = "state"
private

Definition at line 56 of file SHAMapStoreImp.h.

◆ dbPrefix_

std::string const xrpl::SHAMapStoreImp::dbPrefix_ = "rippledb"
private

Definition at line 58 of file SHAMapStoreImp.h.

◆ checkHealthInterval_

std::uint64_t const xrpl::SHAMapStoreImp::checkHealthInterval_ = 1000
private

Definition at line 60 of file SHAMapStoreImp.h.

◆ kMinimumDeletionInterval

std::uint32_t const xrpl::SHAMapStoreImp::kMinimumDeletionInterval = 256
staticprivate

Definition at line 62 of file SHAMapStoreImp.h.

◆ kMinimumDeletionIntervalSa

std::uint32_t const xrpl::SHAMapStoreImp::kMinimumDeletionIntervalSa = 8
staticprivate

Definition at line 64 of file SHAMapStoreImp.h.

◆ minimumOnline_

std::atomic<LedgerIndex> xrpl::SHAMapStoreImp::minimumOnline_
private

Definition at line 66 of file SHAMapStoreImp.h.

◆ scheduler_

NodeStore::Scheduler& xrpl::SHAMapStoreImp::scheduler_
private

Definition at line 68 of file SHAMapStoreImp.h.

◆ journal_

beast::Journal const xrpl::SHAMapStoreImp::journal_
private

Definition at line 69 of file SHAMapStoreImp.h.

◆ dbRotating_

NodeStore::DatabaseRotating* xrpl::SHAMapStoreImp::dbRotating_ = nullptr
private

Definition at line 70 of file SHAMapStoreImp.h.

◆ stateDb_

SavedStateDB xrpl::SHAMapStoreImp::stateDb_
private

Definition at line 71 of file SHAMapStoreImp.h.

◆ thread_

std::thread xrpl::SHAMapStoreImp::thread_
private

Definition at line 72 of file SHAMapStoreImp.h.

◆ stop_

bool xrpl::SHAMapStoreImp::stop_ = false
private

Definition at line 73 of file SHAMapStoreImp.h.

◆ healthy_

bool xrpl::SHAMapStoreImp::healthy_ = true
private

Definition at line 74 of file SHAMapStoreImp.h.

◆ cond_

std::condition_variable xrpl::SHAMapStoreImp::cond_
mutableprivate

Definition at line 75 of file SHAMapStoreImp.h.

◆ rendezvous_

std::condition_variable xrpl::SHAMapStoreImp::rendezvous_
mutableprivate

Definition at line 76 of file SHAMapStoreImp.h.

◆ mutex_

std::mutex xrpl::SHAMapStoreImp::mutex_
mutableprivate

Definition at line 77 of file SHAMapStoreImp.h.

◆ newLedger_

std::shared_ptr<Ledger const> xrpl::SHAMapStoreImp::newLedger_
private

Definition at line 78 of file SHAMapStoreImp.h.

◆ working_

std::atomic<bool> xrpl::SHAMapStoreImp::working_
private

Definition at line 79 of file SHAMapStoreImp.h.

◆ canDelete_

std::atomic<LedgerIndex> xrpl::SHAMapStoreImp::canDelete_
private

Definition at line 80 of file SHAMapStoreImp.h.

◆ fdRequired_

int xrpl::SHAMapStoreImp::fdRequired_ = 0
private

Definition at line 81 of file SHAMapStoreImp.h.

◆ deleteInterval_

std::uint32_t xrpl::SHAMapStoreImp::deleteInterval_ = 0
private

Definition at line 83 of file SHAMapStoreImp.h.

◆ advisoryDelete_

bool xrpl::SHAMapStoreImp::advisoryDelete_ = false
private

Definition at line 84 of file SHAMapStoreImp.h.

◆ deleteBatch_

std::uint32_t xrpl::SHAMapStoreImp::deleteBatch_ = 100
private

Definition at line 85 of file SHAMapStoreImp.h.

◆ backOff_

std::chrono::milliseconds xrpl::SHAMapStoreImp::backOff_ {100}
private

Definition at line 86 of file SHAMapStoreImp.h.

◆ ageThreshold_

std::chrono::seconds xrpl::SHAMapStoreImp::ageThreshold_ {60}
private

Definition at line 87 of file SHAMapStoreImp.h.

◆ recoveryWaitTime_

std::chrono::seconds xrpl::SHAMapStoreImp::recoveryWaitTime_ {5}
private

If the node is out of sync during an online_delete healthWait() call, sleep the thread for this time, and continue checking until recovery.

See also: "recovery_wait_seconds" in xrpld-example.cfg

Definition at line 92 of file SHAMapStoreImp.h.

◆ netOPs_

NetworkOPs* xrpl::SHAMapStoreImp::netOPs_ = nullptr
private

Definition at line 96 of file SHAMapStoreImp.h.

◆ ledgerMaster_

LedgerMaster* xrpl::SHAMapStoreImp::ledgerMaster_ = nullptr
private

Definition at line 97 of file SHAMapStoreImp.h.

◆ fullBelowCache_

FullBelowCache* xrpl::SHAMapStoreImp::fullBelowCache_ = nullptr
private

Definition at line 98 of file SHAMapStoreImp.h.

◆ treeNodeCache_

TreeNodeCache* xrpl::SHAMapStoreImp::treeNodeCache_ = nullptr
private

Definition at line 99 of file SHAMapStoreImp.h.

◆ kNodeStoreName

auto xrpl::SHAMapStoreImp::kNodeStoreName = "NodeStore"
staticconstexprprivate

Definition at line 101 of file SHAMapStoreImp.h.