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/nodestore/Database.h>
24 #include <ripple/app/ledger/Ledger.h>
25 #include <ripple/basics/RangeSet.h>
26 #include <ripple/nodestore/Types.h>
27 
28 #include <boost/optional.hpp>
29 
30 #include <memory>
31 
32 namespace ripple {
33 namespace NodeStore {
34 
37 class DatabaseShard : public Database
38 {
39 public:
50  std::string const& name,
51  Stoppable& parent,
52  Scheduler& scheduler,
53  int readThreads,
54  Section const& config,
55  beast::Journal journal)
56  : Database(name, parent, scheduler, readThreads, config, journal)
57  {
58  }
59 
64  virtual
65  bool
66  init() = 0;
67 
79  virtual
80  boost::optional<std::uint32_t>
81  prepareLedger(std::uint32_t validLedgerSeq) = 0;
82 
88  virtual
89  bool
90  prepareShard(std::uint32_t shardIndex) = 0;
91 
96  virtual
97  void
98  removePreShard(std::uint32_t shardIndex) = 0;
99 
104  virtual
106  getPreShards() = 0;
107 
115  virtual
116  bool
117  importShard(
118  std::uint32_t shardIndex,
119  boost::filesystem::path const& srcDir) = 0;
120 
127  virtual
129  fetchLedger(uint256 const& hash, std::uint32_t seq) = 0;
130 
136  virtual
137  void
138  setStored(std::shared_ptr<Ledger const> const& ledger) = 0;
139 
144  virtual
146  getCompleteShards() = 0;
147 
152  virtual
153  void
154  validate() = 0;
155 
158  virtual
160  ledgersPerShard() const = 0;
161 
164  virtual
166  earliestShardIndex() const = 0;
167 
173  virtual
175  seqToShardIndex(std::uint32_t seq) const = 0;
176 
182  virtual
184  firstLedgerSeq(std::uint32_t shardIndex) const = 0;
185 
191  virtual
193  lastLedgerSeq(std::uint32_t shardIndex) const = 0;
194 
197  virtual
198  boost::filesystem::path const&
199  getRootDir() const = 0;
200 
202  static constexpr std::uint32_t ledgersPerShardDefault {16384u};
203 };
204 
205 constexpr
209 {
210  return (seq - 1) / ledgersPerShard;
211 }
212 
213 extern
216  Application& app,
217  Stoppable& parent,
218  Scheduler& scheduler,
219  int readThreads,
220  beast::Journal j);
221 
222 }
223 }
224 
225 #endif
ripple::NodeStore::make_ShardStore
std::unique_ptr< DatabaseShard > make_ShardStore(Application &app, Stoppable &parent, Scheduler &scheduler, int readThreads, beast::Journal j)
Definition: DatabaseShardImp.cpp:1439
ripple::Section
Holds a collection of configuration values.
Definition: BasicConfig.h:43
ripple::Application
Definition: Application.h:85
ripple::NodeStore::Database
Persistency layer for NodeObject.
Definition: Database.h:53
ripple::NodeStore::DatabaseShard::earliestShardIndex
virtual std::uint32_t earliestShardIndex() const =0
std::string
STL class.
std::shared_ptr
STL class.
ripple::NodeStore::DatabaseShard::seqToShardIndex
virtual std::uint32_t seqToShardIndex(std::uint32_t seq) const =0
Calculates the shard index for a given ledger sequence.
ripple::NodeStore::DatabaseShard::DatabaseShard
DatabaseShard(std::string const &name, Stoppable &parent, Scheduler &scheduler, int readThreads, Section const &config, beast::Journal journal)
Construct a shard store.
Definition: DatabaseShard.h:49
ripple::NodeStore::DatabaseShard::lastLedgerSeq
virtual std::uint32_t lastLedgerSeq(std::uint32_t shardIndex) const =0
Calculates the last ledger sequence for a given shard index.
ripple::NodeStore::DatabaseShard::getCompleteShards
virtual std::string getCompleteShards()=0
Query which complete shards are stored.
ripple::NodeStore::DatabaseShard::getRootDir
virtual boost::filesystem::path const & getRootDir() const =0
Returns the root database directory.
ripple::base_uint< 256 >
ripple::Stoppable
Provides an interface for starting and stopping.
Definition: Stoppable.h:200
ripple::NodeStore::seqToShardIndex
constexpr std::uint32_t seqToShardIndex(std::uint32_t seq, std::uint32_t ledgersPerShard=DatabaseShard::ledgersPerShardDefault)
Definition: DatabaseShard.h:207
ripple::NodeStore::DatabaseShard
A collection of historical shards.
Definition: DatabaseShard.h:37
beast::Journal
A generic endpoint for log messages.
Definition: Journal.h:60
std::uint32_t
ripple::NodeStore::DatabaseShard::firstLedgerSeq
virtual std::uint32_t firstLedgerSeq(std::uint32_t shardIndex) const =0
Calculates the first ledger sequence for a given shard index.
ripple::NodeStore::Scheduler
Scheduling for asynchronous backend activity.
Definition: ripple/nodestore/Scheduler.h:57
memory
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::ledgersPerShardDefault
static constexpr std::uint32_t ledgersPerShardDefault
The number of ledgers in a shard.
Definition: DatabaseShard.h:202
ripple::NodeStore::DatabaseShard::importShard
virtual bool importShard(std::uint32_t shardIndex, boost::filesystem::path const &srcDir)=0
Import a shard 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::prepareShard
virtual bool prepareShard(std::uint32_t shardIndex)=0
Prepare a shard index to be imported into the database.
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.
ripple::NodeStore::DatabaseShard::prepareLedger
virtual boost::optional< std::uint32_t > prepareLedger(std::uint32_t validLedgerSeq)=0
Prepare to store a new ledger in the shard being acquired.
ripple::NodeStore::DatabaseShard::validate
virtual void validate()=0
Verifies shard store data is valid.
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::ledgersPerShard
virtual std::uint32_t ledgersPerShard() const =0