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  prepareShards(std::vector<std::uint32_t> const& shardIndexes) = 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 
141  virtual std::uint32_t
142  ledgersPerShard() const = 0;
143 
146  virtual std::uint32_t
147  earliestShardIndex() const = 0;
148 
154  virtual std::uint32_t
155  seqToShardIndex(std::uint32_t seq) const = 0;
156 
162  virtual std::uint32_t
163  firstLedgerSeq(std::uint32_t shardIndex) const = 0;
164 
170  virtual std::uint32_t
171  lastLedgerSeq(std::uint32_t shardIndex) const = 0;
172 
175  virtual boost::filesystem::path const&
176  getRootDir() const = 0;
177 
179  static constexpr std::uint32_t ledgersPerShardDefault{16384u};
180 };
181 
182 constexpr std::uint32_t
184  std::uint32_t ledgerSeq,
186 {
187  return (ledgerSeq - 1) / ledgersPerShard;
188 }
189 
192  Application& app,
193  Stoppable& parent,
194  Scheduler& scheduler,
195  int readThreads,
196  beast::Journal j);
197 
198 } // namespace NodeStore
199 } // namespace ripple
200 
201 #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:1952
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
std::vector
STL class.
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:201
ripple::NodeStore::DatabaseShard
A collection of historical shards.
Definition: DatabaseShard.h:37
beast::Journal
A generic endpoint for log messages.
Definition: Journal.h:58
ripple::NodeStore::seqToShardIndex
constexpr std::uint32_t seqToShardIndex(std::uint32_t ledgerSeq, std::uint32_t ledgersPerShard=DatabaseShard::ledgersPerShardDefault)
Definition: DatabaseShard.h:183
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:61
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.
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:179
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::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::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