rippled
DeterministicShard.h
1 //------------------------------------------------------------------------------
2 /*
3  This file is part of rippled: https://github.com/ripple/rippled
4  Copyright (c) 2020 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_DETERMINISTICSHARD_H_INCLUDED
21 #define RIPPLE_NODESTORE_DETERMINISTICSHARD_H_INCLUDED
22 
23 #include <ripple/nodestore/DatabaseShard.h>
24 #include <ripple/nodestore/DummyScheduler.h>
25 #include <nudb/nudb.hpp>
26 #include <set>
27 
28 namespace ripple {
29 namespace NodeStore {
30 
41 {
42  constexpr static std::uint32_t maxMemObjsDefault = 16384u;
43  constexpr static std::uint32_t maxMemObjsTest = 16u;
44 
45  /* "SHRD" in ASCII */
46  constexpr static std::uint64_t deterministicType = 0x5348524400000000ll;
47 
48 private:
49  DeterministicShard(DeterministicShard const&) = delete;
51  operator=(DeterministicShard const&) = delete;
52 
61  Application& app,
62  boost::filesystem::path const& dir,
63  std::uint32_t index,
64  beast::Journal j);
65 
75  bool
76  init(Serializer const& finalKey);
77 
78 public:
80 
83  void
85  {
86  close(false);
87  }
88 
89  [[nodiscard]] boost::filesystem::path const&
90  getDir() const
91  {
92  return dir_;
93  }
94 
102  [[nodiscard]] bool
103  store(std::shared_ptr<NodeObject> const& nodeObject);
104 
105 private:
111  void
112  close(bool cancel);
113 
114  // Application reference
116 
117  // Shard Index
119 
120  // Path to temporary database files
121  boost::filesystem::path const dir_;
122 
123  // Dummy scheduler for deterministic write
125 
126  // NuDB context
128 
129  // NuDB key/value store for node objects
131 
132  // Journal
134 
135  // Current number of in-cache objects
137 
138  // Maximum number of in-cache objects
140 
143  Application& app,
144  boost::filesystem::path const& shardDir,
145  std::uint32_t shardIndex,
146  Serializer const& finalKey,
147  beast::Journal j);
148 };
149 
165  Application& app,
166  boost::filesystem::path const& shardDir,
167  std::uint32_t shardIndex,
168  Serializer const& finalKey,
169  beast::Journal j);
170 
171 } // namespace NodeStore
172 } // namespace ripple
173 
174 #endif
ripple::NodeStore::DummyScheduler
Simple NodeStore Scheduler that just peforms the tasks synchronously.
Definition: DummyScheduler.h:29
ripple::Application
Definition: Application.h:115
ripple::NodeStore::DeterministicShard::~DeterministicShard
~DeterministicShard()
Definition: DeterministicShard.cpp:52
ripple::NodeStore::DeterministicShard::DeterministicShard
DeterministicShard(DeterministicShard const &)=delete
ripple::NodeStore::DeterministicShard::deterministicType
constexpr static std::uint64_t deterministicType
Definition: DeterministicShard.h:46
std::shared_ptr< NodeObject >
ripple::NodeStore::DeterministicShard::init
bool init(Serializer const &finalKey)
Initializes the deterministic shard.
Definition: DeterministicShard.cpp:58
ripple::NodeStore::DeterministicShard::backend_
std::shared_ptr< Backend > backend_
Definition: DeterministicShard.h:130
ripple::NodeStore::DeterministicShard::store
bool store(std::shared_ptr< NodeObject > const &nodeObject)
Store a node object in memory.
Definition: DeterministicShard.cpp:191
ripple::NodeStore::make_DeterministicShard
std::shared_ptr< DeterministicShard > make_DeterministicShard(Application &app, boost::filesystem::path const &shardDir, std::uint32_t shardIndex, Serializer const &finalKey, beast::Journal j)
Creates shared pointer to deterministic shard and initializes it.
Definition: DeterministicShard.cpp:151
ripple::NodeStore::DeterministicShard::make_DeterministicShard
friend std::shared_ptr< DeterministicShard > make_DeterministicShard(Application &app, boost::filesystem::path const &shardDir, std::uint32_t shardIndex, Serializer const &finalKey, beast::Journal j)
Creates shared pointer to deterministic shard and initializes it.
Definition: DeterministicShard.cpp:151
ripple::NodeStore::DeterministicShard::j_
const beast::Journal j_
Definition: DeterministicShard.h:133
ripple::NodeStore::DeterministicShard::ctx_
std::unique_ptr< nudb::context > ctx_
Definition: DeterministicShard.h:127
ripple::NodeStore::DeterministicShard::index_
const std::uint32_t index_
Definition: DeterministicShard.h:118
ripple::NodeStore::DeterministicShard
DeterministicShard class.
Definition: DeterministicShard.h:40
ripple::NodeStore::DeterministicShard::operator=
DeterministicShard & operator=(DeterministicShard const &)=delete
ripple::NodeStore::DeterministicShard::scheduler_
DummyScheduler scheduler_
Definition: DeterministicShard.h:124
ripple::NodeStore::DeterministicShard::curMemObjs_
std::uint32_t curMemObjs_
Definition: DeterministicShard.h:136
ripple::NodeStore::DeterministicShard::app_
Application & app_
Definition: DeterministicShard.h:115
ripple::NodeStore::DeterministicShard::maxMemObjsDefault
constexpr static std::uint32_t maxMemObjsDefault
Definition: DeterministicShard.h:42
beast::Journal
A generic endpoint for log messages.
Definition: Journal.h:58
std::uint32_t
ripple::NodeStore::DeterministicShard::maxMemObjsTest
constexpr static std::uint32_t maxMemObjsTest
Definition: DeterministicShard.h:43
ripple::Serializer
Definition: Serializer.h:39
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::NodeStore::DeterministicShard::dir_
const boost::filesystem::path dir_
Definition: DeterministicShard.h:121
ripple::NodeStore::DeterministicShard::close
void close()
Finalizes and closes the shard.
Definition: DeterministicShard.h:84
ripple::NodeStore::DeterministicShard::maxMemObjs_
const std::uint32_t maxMemObjs_
Definition: DeterministicShard.h:139
ripple::NodeStore::DeterministicShard::getDir
boost::filesystem::path const & getDir() const
Definition: DeterministicShard.h:90
std::unique_ptr< nudb::context >
set