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>
85 boost::filesystem::path
const&
150 std::function<
bool(soci::session& session)>
const& callback)
override;
155 std::function<
bool(soci::session& session)>
const& callback)
override;
160 std::function<
bool(soci::session& session)>
const& callback)
override;
165 std::function<
bool(soci::session& session)>
const& callback)
override;
171 bool(soci::session& session,
std::uint32_t shardIndex)>
const&
178 bool(soci::session& session,
std::uint32_t shardIndex)>
const&
185 bool(soci::session& session,
std::uint32_t shardIndex)>
const&
192 bool(soci::session& session,
std::uint32_t shardIndex)>
const&
307 bool duplicate)
override;
312 Throw<std::runtime_error>(
"Import from shard store not supported");
380 boost::filesystem::path
bool iterateLedgerSQLsForward(std::optional< std::uint32_t > minShardIndex, std::function< bool(soci::session &session, std::uint32_t shardIndex)> const &callback) override
iterateLedgerSQLsForward Checks out ledger databases for all shards in ascending order starting from ...
void for_each(std::function< void(std::shared_ptr< NodeObject >)> f) override
Visit every object in the database This is usually called during import.
bool storeLedger(std::shared_ptr< Ledger const > const &srcLedger) override
Store a ledger from a different database.
Persistency layer for NodeObject.
std::map< std::uint32_t, std::shared_ptr< Shard > > shards_
bool callForLedgerSQLByLedgerSeq(LedgerIndex ledgerSeq, std::function< bool(soci::session &session)> const &callback) override
Invoke a callback on the SQLite db holding the corresponding ledger.
std::string getName() const override
Retrieve the name associated with this backend.
void removePreShard(std::uint32_t shardIndex) override
Remove a previously prepared shard index for import.
NodeObjectType
The types of node objects.
void setStored(std::shared_ptr< Ledger const > const &ledger) override
Notifies the database that the given ledger has been fully acquired and stored.
DatabaseImportStatus(std::uint32_t const earliestIndex, std::uint32_t const latestIndex, std::uint32_t const currentIndex)
Contains information about a fetch operation.
std::optional< std::uint32_t > getDatabaseImportSequence() const override
Returns the first ledger sequence of the shard currently being imported from the NodeStore.
DatabaseShardImp & operator=(DatabaseShardImp const &)=delete
void importDatabase(Database &source) override
Import the application local node store.
std::thread databaseImporter_
const std::uint32_t openFinalLimit_
bool iterateShardsForward(std::optional< std::uint32_t > minShardIndex, std::function< bool(Shard &shard)> const &visit)
iterateShardsForward Visits all shards starting from given in ascending order and calls given callbac...
void sweep() override
Remove expired entries from the positive and negative caches.
Json::Value stopNodeToShard() override
Terminates a NodeStore to ShardStore import and returns the result in a JSON object.
Json::Value getDatabaseImportStatus() const override
Returns a JSON object detailing the status of an ongoing database import if one is running,...
std::optional< std::uint32_t > secondLatestShardIndex_
std::uint64_t avgShardFileSz_
bool callForTransactionSQLByLedgerSeq(LedgerIndex ledgerSeq, std::function< bool(soci::session &session)> const &callback) override
Invoke a callback on the transaction SQLite db for the corresponding ledger.
void updatePeers(std::lock_guard< std::mutex > const &lock) const
std::string getPreShards() override
Get shard indexes being imported.
std::unique_ptr< DatabaseImportStatus > databaseImportStatus_
std::int32_t getWriteLoad() const override
Retrieve the estimated number of pending write operations.
std::optional< std::uint32_t > findAcquireIndex(std::uint32_t validLedgerSeq, std::lock_guard< std::mutex > const &)
bool iterateTransactionSQLsBack(std::optional< std::uint32_t > maxShardIndex, std::function< bool(soci::session &session, std::uint32_t shardIndex)> const &callback) override
iterateTransactionSQLsBack Checks out transaction databases for all shards in descending order starti...
std::atomic_bool haltDatabaseImport_
std::uint32_t currentIndex
boost::filesystem::path chooseHistoricalPath(std::lock_guard< std::mutex > const &) const
bool sufficientStorage(std::uint32_t numShards, PathDesignation pathDesignation, std::lock_guard< std::mutex > const &) const
std::shared_ptr< NodeObject > fetchNodeObject(uint256 const &hash, std::uint32_t ledgerSeq, FetchReport &fetchReport, bool duplicate) override
bool isSameDB(std::uint32_t s1, std::uint32_t s2) override
bool callForLedgerSQLByShardIndex(std::uint32_t const shardIndex, std::function< bool(soci::session &session)> const &callback) override
Invoke a callback on the ledger SQLite db for the corresponding shard.
boost::filesystem::path dir_
void removeFailedShard(std::shared_ptr< Shard > &shard)
A collection of historical shards.
size_t getNumTasks() const override
Returns the number of queued tasks.
bool importShard(std::uint32_t shardIndex, boost::filesystem::path const &srcDir) override
Import a shard from the shard archive handler into the shard database.
void store(NodeObjectType type, Blob &&data, uint256 const &hash, std::uint32_t ledgerSeq) override
Store the object.
bool initConfig(std::lock_guard< std::mutex > const &)
std::optional< std::uint32_t > latestShardIndex_
A generic endpoint for log messages.
std::uint32_t acquireIndex_
Scheduling for asynchronous backend activity.
Json::Value startNodeToShard() override
Initiates a NodeStore to ShardStore import and returns the result in a JSON object.
std::uint32_t latestIndex
std::set< std::uint32_t > preparedIndexes_
bool init() override
Initialize the database.
std::vector< boost::filesystem::path > historicalPaths_
boost::filesystem::path const & getRootDir() const override
Returns the root database directory.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
bool checkHistoricalPaths(std::lock_guard< std::mutex > const &) const
std::uint32_t maxHistoricalShards_
std::weak_ptr< Shard > currentShard
bool callForTransactionSQLByShardIndex(std::uint32_t const shardIndex, std::function< bool(soci::session &session)> const &callback) override
Invoke a callback on the transaction SQLite db for the corresponding shard.
std::shared_ptr< Ledger > fetchLedger(uint256 const &hash, std::uint32_t ledgerSeq) override
Fetch a ledger from the shard store.
std::uint32_t seqToShardIndex(std::uint32_t ledgerSeq) const noexcept
Calculates the shard index for a given ledger sequence.
bool iterateShardsBack(std::optional< std::uint32_t > maxShardIndex, std::function< bool(Shard &shard)> const &visit)
iterateShardsBack Visits all shards starting from given in descending order and calls given callback ...
std::uint32_t numHistoricalShards(std::lock_guard< std::mutex > const &lock) const
void relocateOutdatedShards(std::lock_guard< std::mutex > const &lock)
bool iterateLedgerSQLsBack(std::optional< std::uint32_t > maxShardIndex, std::function< bool(soci::session &session, std::uint32_t shardIndex)> const &callback) override
iterateLedgerSQLsBack Checks out ledger databases for all shards in descending order starting from gi...
std::uint32_t shardBoundaryIndex() const
bool prepareShards(std::vector< std::uint32_t > const &shardIndexes) override
Prepare one or more shard indexes to be imported into the database.
void startDatabaseImportThread(std::lock_guard< std::mutex > const &)
bool setStoredInShard(std::shared_ptr< Shard > &shard, std::shared_ptr< Ledger const > const &ledger)
void finalizeShard(std::shared_ptr< Shard > &shard, bool writeSQLite, std::optional< uint256 > const &expectedHash)
DatabaseShardImp()=delete
static constexpr auto databaseImportMarker_
std::uint32_t earliestIndex
std::optional< PathDesignation > prepareForNewShard(std::uint32_t shardIndex, std::uint32_t numHistoricalShards, std::lock_guard< std::mutex > const &lock)
bool iterateTransactionSQLsForward(std::optional< std::uint32_t > minShardIndex, std::function< bool(soci::session &session, std::uint32_t shardIndex)> const &callback) override
iterateTransactionSQLsForward Checks out transaction databases for all shards in ascending order star...
std::optional< std::uint32_t > prepareLedger(std::uint32_t validLedgerSeq) override
Prepare to store a new ledger in the shard being acquired.
std::unique_ptr< nudb::context > ctx_
std::unique_ptr< ShardInfo > getShardInfo() const override
Query information about shards held.