20 #ifndef RIPPLE_NODESTORE_SHARD_H_INCLUDED
21 #define RIPPLE_NODESTORE_SHARD_H_INCLUDED
23 #include <ripple/app/ledger/Ledger.h>
24 #include <ripple/app/rdb/RelationalDatabase.h>
25 #include <ripple/basics/BasicConfig.h>
26 #include <ripple/basics/KeyCache.h>
27 #include <ripple/basics/MathUtilities.h>
28 #include <ripple/basics/RangeSet.h>
29 #include <ripple/basics/ThreadSafetyAnalysis.h>
30 #include <ripple/core/DatabaseCon.h>
31 #include <ripple/nodestore/NodeObject.h>
32 #include <ripple/nodestore/Scheduler.h>
33 #include <ripple/nodestore/impl/DeterministicShard.h>
35 #include <boost/filesystem.hpp>
36 #include <nudb/nudb.hpp>
76 boost::filesystem::path
const& dir,
137 [[nodiscard]] StoreLedgerResult
154 [[nodiscard]] boost::filesystem::path
const&
160 [[nodiscard]] std::chrono::steady_clock::time_point
218 return to_string(acquireInfo_->storedSeqs);
226 template <
typename... Args>
230 return callForSQL(callback, lgrSQLiteDB_->checkoutDb());
238 template <
typename... Args>
242 return callForSQL(callback, txSQLiteDB_->checkoutDb());
265 other.counter_ =
nullptr;
281 explicit operator bool() const noexcept
318 boost::filesystem::path
const dir_;
400 template <
typename... Args>
424 bool(soci::session& session,
std::uint32_t shardIndex)>
const&
const boost::filesystem::path dir_
std::uint32_t getPercentProgress() const noexcept
Returns a percent signifying how complete the current state of the shard is.
std::atomic< bool > removeOnDestroy_
void removeOnDestroy() noexcept
Enables removal of the shard directory on destruction.
StoreLedgerResult storeLedger(std::shared_ptr< Ledger const > const &srcLedger, std::shared_ptr< Ledger const > const &next)
std::optional< std::uint32_t > prepare()
bool open(std::lock_guard< std::mutex > const &lock) REQUIRES(mutex_)
bool callForLedgerSQL(std::function< bool(Args... args)> const &callback)
Invoke a callback on the ledger SQLite db.
Shard(Shard const &)=delete
Copy constructor (disallowed)
Count(std::atomic< std::uint32_t > *counter) noexcept
std::string getStoredSeqs()
std::pair< std::uint64_t, std::uint32_t > getFileInfo() const
Returns a pair where the first item describes the storage space utilized and the second item is the n...
Count(Count &&other) noexcept
Shard & operator=(Shard const &)=delete
Contains information about a fetch operation.
bool isOpen() const
Returns true if the database are open.
static const uint256 finalKey
const std::uint32_t lastSeq_
GUARDED_BY(mutex_) std GUARDED_BY(mutex_) std std::unique_ptr< Backend > backend_ GUARDED_BY(mutex_)
RangeSet< std::uint32_t > storedSeqs
std::shared_ptr< NodeObject > verifyFetch(uint256 const &hash) const
bool tryClose()
Try to close databases if not in use.
bool isLegacy() const
Returns true if shard is older, without final key data.
static constexpr std::uint32_t version
bool storeSQLite(std::shared_ptr< Ledger const > const &ledger)
TaggedCache< uint256, int, true > KeyCache
bool containsLedger(std::uint32_t ledgerSeq) const
bool storeNodeObject(std::shared_ptr< NodeObject > const &nodeObject)
void stop() noexcept
Notify shard to prepare for shutdown.
bool initSQLite(std::lock_guard< std::mutex > const &) REQUIRES(mutex_)
std::shared_ptr< NodeObject > fetchNodeObject(uint256 const &hash, FetchReport &fetchReport)
void setFileStats(std::lock_guard< std::mutex > const &) REQUIRES(mutex_)
A collection of historical shards.
constexpr std::size_t calculatePercent(std::size_t count, std::size_t total)
Calculate one number divided by another number in percentage.
const std::uint32_t firstSeq_
std::unique_ptr< DatabaseCon > SQLiteDB
const std::uint32_t maxLedgers_
A generic endpoint for log messages.
bool verifyLedger(std::shared_ptr< Ledger const > const &ledger, std::shared_ptr< Ledger const > const &next, std::shared_ptr< DeterministicShard > const &dShard) const
GUARDED_BY(mutex_) bool legacy_
Scheduling for asynchronous backend activity.
Count(Count const &)=delete
std::uint32_t index() const noexcept
bool callForSQL(std::function< bool(Args... args)> const &callback, LockedSociSession &&db)
std::atomic< std::uint32_t > progress_
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Shard::Count makeBackendCount()
bool callForTransactionSQL(std::function< bool(Args... args)> const &callback)
Invoke a callback on the transaction SQLite db.
boost::filesystem::path const & getDir() const noexcept
Count & operator=(Count const &)=delete
std::atomic< ShardState > state_
bool doCallForSQL(std::function< bool(soci::session &session)> const &callback, LockedSociSession &&db)
bool init(Scheduler &scheduler, nudb::context &context)
Initialize shard.
std::string to_string(Manifest const &m)
Format the specified manifest to a string for debugging purposes.
boost::icl::interval_set< T, std::less, ClosedInterval< T > > RangeSet
A set of closed intervals over the domain T.
bool finalize(bool writeSQLite, std::optional< uint256 > const &referenceHash)
Finalize shard by walking its ledgers, verifying each Merkle tree and creating a deterministic backen...
bool setLedgerStored(std::shared_ptr< Ledger const > const &ledger)
ShardState getState() const noexcept
const std::uint32_t index_
std::atomic< bool > stop_
std::atomic< std::uint32_t > * counter_
std::atomic< std::uint32_t > backendCount_
std::chrono::steady_clock::time_point getLastUse() const
std::int32_t getWriteLoad()
std::atomic< bool > busy_