rippled
DatabaseShard.h
1 //------------------------------------------------------------------------------
2 /*
3  This file is part of rippled: https://github.com/ripple/rippled
4  Copyright (c) 2012, 2017 Ripple Labs Inc.
5 
6  Permission to use, copy, modify, and/or distribute this software for any
7  purpose with or without fee is hereby granted, provided that the above
8  copyright notice and this permission notice appear in all copies.
9 
10  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18 //==============================================================================
19 
20 #ifndef RIPPLE_NODESTORE_DATABASESHARD_H_INCLUDED
21 #define RIPPLE_NODESTORE_DATABASESHARD_H_INCLUDED
22 
23 #include <ripple/app/ledger/Ledger.h>
24 #include <ripple/core/SociDB.h>
25 #include <ripple/nodestore/Database.h>
26 #include <ripple/nodestore/ShardInfo.h>
27 #include <ripple/nodestore/Types.h>
28 
29 #include <memory>
30 #include <optional>
31 
32 namespace ripple {
33 namespace NodeStore {
34 
37 class DatabaseShard : public Database
38 {
39 public:
48  Scheduler& scheduler,
49  int readThreads,
50  Section const& config,
51  beast::Journal journal)
52  : Database(scheduler, readThreads, config, journal)
53  {
54  }
55 
60  [[nodiscard]] virtual bool
61  init() = 0;
62 
75  [[nodiscard]] virtual std::optional<std::uint32_t>
76  prepareLedger(std::uint32_t validLedgerSeq) = 0;
77 
83  [[nodiscard]] virtual bool
84  prepareShards(std::vector<std::uint32_t> const& shardIndexes) = 0;
85 
90  virtual void
91  removePreShard(std::uint32_t shardIndex) = 0;
92 
97  [[nodiscard]] virtual std::string
98  getPreShards() = 0;
99 
109  [[nodiscard]] virtual bool
110  importShard(
111  std::uint32_t shardIndex,
112  boost::filesystem::path const& srcDir) = 0;
113 
120  [[nodiscard]] virtual std::shared_ptr<Ledger>
121  fetchLedger(uint256 const& hash, std::uint32_t seq) = 0;
122 
128  virtual void
129  setStored(std::shared_ptr<Ledger const> const& ledger) = 0;
130 
136  virtual bool
138  LedgerIndex ledgerSeq,
139  std::function<bool(soci::session& session)> const& callback) = 0;
140 
146  virtual bool
148  std::uint32_t shardIndex,
149  std::function<bool(soci::session& session)> const& callback) = 0;
150 
156  virtual bool
158  LedgerIndex ledgerSeq,
159  std::function<bool(soci::session& session)> const& callback) = 0;
160 
166  virtual bool
168  std::uint32_t shardIndex,
169  std::function<bool(soci::session& session)> const& callback) = 0;
170 
182  virtual bool
184  std::optional<std::uint32_t> minShardIndex,
186  bool(soci::session& session, std::uint32_t shardIndex)> const&
187  callback) = 0;
188 
200  virtual bool
202  std::optional<std::uint32_t> minShardIndex,
204  bool(soci::session& session, std::uint32_t shardIndex)> const&
205  callback) = 0;
206 
218  virtual bool
220  std::optional<std::uint32_t> maxShardIndex,
222  bool(soci::session& session, std::uint32_t shardIndex)> const&
223  callback) = 0;
224 
236  virtual bool
238  std::optional<std::uint32_t> maxShardIndex,
240  bool(soci::session& session, std::uint32_t shardIndex)> const&
241  callback) = 0;
242 
247  [[nodiscard]] virtual std::unique_ptr<ShardInfo>
248  getShardInfo() const = 0;
249 
252  [[nodiscard]] virtual boost::filesystem::path const&
253  getRootDir() const = 0;
254 
259  virtual Json::Value
260  getDatabaseImportStatus() const = 0;
261 
265  virtual Json::Value
266  startNodeToShard() = 0;
267 
271  virtual Json::Value
272  stopNodeToShard() = 0;
273 
280  getDatabaseImportSequence() const = 0;
281 
284  [[nodiscard]] virtual size_t
285  getNumTasks() const = 0;
286 };
287 
290  Application& app,
291  Scheduler& scheduler,
292  int readThreads,
293  beast::Journal j);
294 
295 } // namespace NodeStore
296 } // namespace ripple
297 
298 #endif
ripple::Section
Holds a collection of configuration values.
Definition: BasicConfig.h:42
ripple::Application
Definition: Application.h:115
ripple::NodeStore::make_ShardStore
std::unique_ptr< DatabaseShard > make_ShardStore(Application &app, Scheduler &scheduler, int readThreads, beast::Journal j)
Definition: DatabaseShardImp.cpp:2236
ripple::NodeStore::DatabaseShard::callForLedgerSQLByLedgerSeq
virtual bool callForLedgerSQLByLedgerSeq(LedgerIndex ledgerSeq, std::function< bool(soci::session &session)> const &callback)=0
Invoke a callback on the SQLite db holding the corresponding ledger.
ripple::NodeStore::DatabaseShard::getNumTasks
virtual size_t getNumTasks() const =0
Returns the number of queued tasks.
ripple::NodeStore::Database
Persistency layer for NodeObject.
Definition: Database.h:51
std::string
STL class.
std::shared_ptr< Ledger >
std::vector
STL class.
ripple::NodeStore::DatabaseShard::getDatabaseImportStatus
virtual Json::Value getDatabaseImportStatus() const =0
Returns a JSON object detailing the status of an ongoing database import if one is running,...
ripple::NodeStore::DatabaseShard::callForLedgerSQLByShardIndex
virtual bool callForLedgerSQLByShardIndex(std::uint32_t shardIndex, std::function< bool(soci::session &session)> const &callback)=0
Invoke a callback on the ledger SQLite db for the corresponding shard.
ripple::NodeStore::DatabaseShard::callForTransactionSQLByLedgerSeq
virtual bool callForTransactionSQLByLedgerSeq(LedgerIndex ledgerSeq, std::function< bool(soci::session &session)> const &callback)=0
Invoke a callback on the transaction SQLite db for the corresponding ledger.
std::function
ripple::NodeStore::DatabaseShard::getRootDir
virtual boost::filesystem::path const & getRootDir() const =0
Returns the root database directory.
ripple::NodeStore::DatabaseShard::prepareLedger
virtual std::optional< std::uint32_t > prepareLedger(std::uint32_t validLedgerSeq)=0
Prepare to store a new ledger in the shard being acquired.
ripple::NodeStore::DatabaseShard::getDatabaseImportSequence
virtual std::optional< std::uint32_t > getDatabaseImportSequence() const =0
Returns the first ledger sequence of the shard currently being imported from the NodeStore.
ripple::base_uint< 256 >
ripple::NodeStore::DatabaseShard::iterateLedgerSQLsBack
virtual bool iterateLedgerSQLsBack(std::optional< std::uint32_t > maxShardIndex, std::function< bool(soci::session &session, std::uint32_t shardIndex)> const &callback)=0
iterateLedgerSQLsBack Checks out ledger databases for all shards in descending order starting from gi...
ripple::NodeStore::DatabaseShard::iterateLedgerSQLsForward
virtual bool iterateLedgerSQLsForward(std::optional< std::uint32_t > minShardIndex, std::function< bool(soci::session &session, std::uint32_t shardIndex)> const &callback)=0
iterateLedgerSQLsForward Checks out ledger databases for all shards in ascending order starting from ...
ripple::NodeStore::DatabaseShard::callForTransactionSQLByShardIndex
virtual bool callForTransactionSQLByShardIndex(std::uint32_t shardIndex, std::function< bool(soci::session &session)> const &callback)=0
Invoke a callback on the transaction SQLite db for the corresponding shard.
ripple::NodeStore::DatabaseShard
A collection of historical shards.
Definition: DatabaseShard.h:37
beast::Journal
A generic endpoint for log messages.
Definition: Journal.h:58
std::uint32_t
ripple::NodeStore::Scheduler
Scheduling for asynchronous backend activity.
Definition: ripple/nodestore/Scheduler.h:60
ripple::NodeStore::DatabaseShard::prepareShards
virtual bool prepareShards(std::vector< std::uint32_t > const &shardIndexes)=0
Prepare one or more shard indexes to be imported into the database.
ripple::NodeStore::DatabaseShard::iterateTransactionSQLsBack
virtual bool iterateTransactionSQLsBack(std::optional< std::uint32_t > maxShardIndex, std::function< bool(soci::session &session, std::uint32_t shardIndex)> const &callback)=0
iterateTransactionSQLsBack Checks out transaction databases for all shards in descending order starti...
memory
ripple::NodeStore::DatabaseShard::stopNodeToShard
virtual Json::Value stopNodeToShard()=0
Terminates a NodeStore to ShardStore import and returns the result in a JSON object.
ripple::NodeStore::DatabaseShard::fetchLedger
virtual std::shared_ptr< Ledger > fetchLedger(uint256 const &hash, std::uint32_t seq)=0
Fetch a ledger from the shard store.
ripple::NodeStore::DatabaseShard::importShard
virtual bool importShard(std::uint32_t shardIndex, boost::filesystem::path const &srcDir)=0
Import a shard from the shard archive handler into the shard database.
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::NodeStore::DatabaseShard::setStored
virtual void setStored(std::shared_ptr< Ledger const > const &ledger)=0
Notifies the database that the given ledger has been fully acquired and stored.
ripple::NodeStore::DatabaseShard::getPreShards
virtual std::string getPreShards()=0
Get shard indexes being imported.
ripple::NodeStore::DatabaseShard::init
virtual bool init()=0
Initialize the database.
optional
ripple::NodeStore::DatabaseShard::DatabaseShard
DatabaseShard(Scheduler &scheduler, int readThreads, Section const &config, beast::Journal journal)
Construct a shard store.
Definition: DatabaseShard.h:47
ripple::NodeStore::DatabaseShard::removePreShard
virtual void removePreShard(std::uint32_t shardIndex)=0
Remove a previously prepared shard index for import.
std::unique_ptr
STL class.
ripple::NodeStore::DatabaseShard::startNodeToShard
virtual Json::Value startNodeToShard()=0
Initiates a NodeStore to ShardStore import and returns the result in a JSON object.
ripple::NodeStore::DatabaseShard::getShardInfo
virtual std::unique_ptr< ShardInfo > getShardInfo() const =0
Query information about shards held.
ripple::NodeStore::DatabaseShard::iterateTransactionSQLsForward
virtual bool iterateTransactionSQLsForward(std::optional< std::uint32_t > minShardIndex, std::function< bool(soci::session &session, std::uint32_t shardIndex)> const &callback)=0
iterateTransactionSQLsForward Checks out transaction databases for all shards in ascending order star...
Json::Value
Represents a JSON value.
Definition: json_value.h:145