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/basics/RangeSet.h>
25 #include <ripple/nodestore/Database.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 bool
65  init() = 0;
66 
78  virtual boost::optional<std::uint32_t>
79  prepareLedger(std::uint32_t validLedgerSeq) = 0;
80 
86  virtual bool
87  prepareShard(std::uint32_t shardIndex) = 0;
88 
93  virtual void
94  removePreShard(std::uint32_t shardIndex) = 0;
95 
100  virtual std::string
101  getPreShards() = 0;
102 
110  virtual bool
111  importShard(
112  std::uint32_t shardIndex,
113  boost::filesystem::path const& srcDir) = 0;
114 
122  fetchLedger(uint256 const& hash, std::uint32_t seq) = 0;
123 
129  virtual void
130  setStored(std::shared_ptr<Ledger const> const& ledger) = 0;
131 
136  virtual std::string
137  getCompleteShards() = 0;
138 
143  virtual void
144  validate() = 0;
145 
148  virtual std::uint32_t
149  ledgersPerShard() const = 0;
150 
153  virtual std::uint32_t
154  earliestShardIndex() const = 0;
155 
161  virtual std::uint32_t
162  seqToShardIndex(std::uint32_t seq) const = 0;
163 
169  virtual std::uint32_t
170  firstLedgerSeq(std::uint32_t shardIndex) const = 0;
171 
177  virtual std::uint32_t
178  lastLedgerSeq(std::uint32_t shardIndex) const = 0;
179 
182  virtual boost::filesystem::path const&
183  getRootDir() const = 0;
184 
186  static constexpr std::uint32_t ledgersPerShardDefault{16384u};
187 };
188 
189 constexpr std::uint32_t
191  std::uint32_t seq,
193 {
194  return (seq - 1) / ledgersPerShard;
195 }
196 
199  Application& app,
200  Stoppable& parent,
201  Scheduler& scheduler,
202  int readThreads,
203  beast::Journal j);
204 
205 } // namespace NodeStore
206 } // namespace ripple
207 
208 #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:1425
ripple::Section
Holds a collection of configuration values.
Definition: BasicConfig.h:43
ripple::Application
Definition: Application.h:97
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< Ledger >
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:190
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::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:186
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