20 #ifndef RIPPLE_NODESTORE_DATABASESHARDIMP_H_INCLUDED
21 #define RIPPLE_NODESTORE_DATABASESHARDIMP_H_INCLUDED
23 #include <ripple/nodestore/DatabaseShard.h>
24 #include <ripple/nodestore/impl/Shard.h>
25 #include <ripple/nodestore/impl/TaskQueue.h>
27 #include <boost/asio/basic_waitable_timer.hpp>
56 boost::optional<std::uint32_t>
119 boost::filesystem::path
const&
274 Throw<std::runtime_error>(
"Shard store import not supported");
279 boost::optional<std::uint32_t>
289 ShardInfo& shardInfo,
292 boost::optional<uint256>
const& expectedHash);
347 boost::optional<PathDesignation>
353 boost::filesystem::path
std::uint32_t earliestShardIndex_
std::uint32_t ledgersPerShard_
void finalizeShard(ShardInfo &shardInfo, bool writeSQLite, std::lock_guard< std::mutex > &, boost::optional< uint256 > const &expectedHash)
std::uint32_t lastLedgerSeq(std::uint32_t shardIndex) const override
Calculates the last ledger sequence for a given shard index.
void for_each(std::function< void(std::shared_ptr< NodeObject >)> f) override
Visit every object in the database This is usually called during import.
std::uint32_t earliestShardIndex() const override
ShardInfo(std::shared_ptr< Shard > shard_, State state_)
boost::optional< std::uint32_t > prepareLedger(std::uint32_t validLedgerSeq) override
Prepare to store a new ledger in the shard being acquired.
bool storeLedger(std::shared_ptr< Ledger const > const &srcLedger) override
Copies a ledger stored in a different database to this one.
Persistency layer for NodeObject.
std::shared_ptr< NodeObject > fetch(uint256 const &hash, std::uint32_t seq) override
Fetch an object.
std::uint32_t seqToShardIndex(std::uint32_t seq) const override
Calculates the shard index for a given ledger sequence.
std::string getName() const override
Retrieve the name associated with this backend.
std::pair< std::shared_ptr< PCache >, std::shared_ptr< NCache > > getCache(std::uint32_t seq)
void removePreShard(std::uint32_t shardIndex) override
Remove a previously prepared shard index for import.
NodeObjectType
The types of node objects.
std::unique_ptr< TaskQueue > taskQueue_
void setStored(std::shared_ptr< Ledger const > const &ledger) override
Notifies the database that the given ledger has been fully acquired and stored.
boost::optional< std::uint32_t > secondLatestShardIndex_
bool prepareShard(std::uint32_t shardIndex) override
Prepare a shard index to be imported into the database.
void tune(int size, std::chrono::seconds age) override
Set the maximum number of entries and maximum cache age for both caches.
bool asyncFetch(uint256 const &hash, std::uint32_t seq, std::shared_ptr< NodeObject > &object) override
Fetch an object without waiting.
DatabaseShardImp & operator=(DatabaseShardImp const &)=delete
void sweep() override
Remove expired entries from the positive and negative caches.
int getDesiredAsyncReadCount(std::uint32_t seq) override
Get the maximum number of async reads the node store prefers.
std::uint32_t firstLedgerSeq(std::uint32_t shardIndex) const override
Calculates the first ledger sequence for a given shard index.
float getCacheHitRate() override
Get the positive cache hits to total attempts ratio.
std::uint64_t avgShardFileSz_
std::shared_ptr< NodeObject > fetchFrom(uint256 const &hash, std::uint32_t seq) override
std::string getPreShards() override
Get shard indexes being imported.
std::int32_t getWriteLoad() const override
Retrieve the estimated number of pending write operations.
std::uint32_t shardBoundaryIndex(std::lock_guard< std::mutex > const &) const
Provides an interface for starting and stopping.
std::shared_ptr< Shard > shard
boost::filesystem::path chooseHistoricalPath(std::lock_guard< std::mutex > const &) const
bool initConfig(std::lock_guard< std::mutex > &)
bool sufficientStorage(std::uint32_t numShards, PathDesignation pathDesignation, std::lock_guard< std::mutex > const &) const
std::string getCompleteShards() override
Query which complete shards are stored.
std::uint32_t ledgersPerShard() const override
std::map< std::uint32_t, ShardInfo > shards_
~DatabaseShardImp() override
boost::filesystem::path dir_
void updateStatus(std::lock_guard< std::mutex > &)
constexpr std::uint32_t seqToShardIndex(std::uint32_t seq, std::uint32_t ledgersPerShard=DatabaseShard::ledgersPerShardDefault)
void removeFailedShard(std::shared_ptr< Shard > &shard)
A collection of historical shards.
bool importShard(std::uint32_t shardIndex, boost::filesystem::path const &srcDir) override
Import a shard into the shard database.
bool checkHistoricalPaths() const
boost::optional< std::uint32_t > latestShardIndex_
A generic endpoint for log messages.
std::uint32_t earliestLedgerSeq() const
std::uint32_t acquireIndex_
Scheduling for asynchronous backend activity.
boost::optional< std::uint32_t > findAcquireIndex(std::uint32_t validLedgerSeq, std::lock_guard< std::mutex > &)
bool init() override
Initialize the database.
void store(NodeObjectType type, Blob &&data, uint256 const &hash, std::uint32_t seq) override
Store the object.
std::vector< boost::filesystem::path > historicalPaths_
boost::filesystem::path const & getRootDir() const override
Returns the root database directory.
static constexpr auto importMarker_
static constexpr std::uint32_t ledgersPerShardDefault
The number of ledgers in a shard.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
std::uint32_t maxHistoricalShards_
std::shared_ptr< Ledger > fetchLedger(uint256 const &hash, std::uint32_t seq) override
Fetch a ledger from the shard store.
std::uint32_t numHistoricalShards(std::lock_guard< std::mutex > const &lock) const
void relocateOutdatedShards(std::lock_guard< std::mutex > const &lock)
void validate() override
Verifies shard store data is valid.
DatabaseShardImp()=delete
boost::optional< PathDesignation > prepareForNewShard(std::uint32_t shardIndex, std::uint32_t numHistoricalShards, std::lock_guard< std::mutex > const &lock)
void onStop() override
Override called when the stop notification is issued.
std::unique_ptr< nudb::context > ctx_
bool storeLedgerInShard(std::shared_ptr< Shard > &shard, std::shared_ptr< Ledger const > const &ledger)