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 
43 {
44 public:
46 
47  DeterministicShard(DeterministicShard const&) = delete;
49  operator=(DeterministicShard const&) = delete;
50 
60  Application& app,
61  DatabaseShard const& db,
62  std::uint32_t index,
63  uint256 const& lastHash,
64  beast::Journal j);
65 
67 
72  bool
73  init();
74 
80  void
81  close(bool cancel = false);
82 
87  void
88  store(nodeptr nobj);
89 
92  void
93  flush();
94 
95 private:
96  // Count hash of shard parameters: lashHash, firstSeq, lastSeq, index
97  uint160
98  hash(const uint256& lastHash) const;
99 
100  // Get n-th 64-bit portion of shard parameters's hash
102  digest(int n) const;
103 
104  // If database inited
105  bool inited_;
106 
107  // Sorted set of stored and not flushed objects
109 
110  // Application reference
112 
113  // Shard database
115 
116  // Shard Index
118 
119  // Hash used for digests
120  uint160 const hash_;
121 
122  // Path to temporary database files
123  boost::filesystem::path const tempdir_;
124 
125  // Path to final database files
126  boost::filesystem::path const finaldir_;
127 
128  // Dummy scheduler for deterministic write
130 
131  // NuDB context
133 
134  // NuDB key/value store for node objects
136 
137  // Journal
139 };
140 
141 } // namespace NodeStore
142 } // namespace ripple
143 
144 #endif
ripple::NodeStore::DummyScheduler
Simple NodeStore Scheduler that just peforms the tasks synchronously.
Definition: DummyScheduler.h:29
ripple::Application
Definition: Application.h:97
ripple::NodeStore::DeterministicShard::~DeterministicShard
~DeterministicShard()
Definition: DeterministicShard.cpp:54
ripple::NodeStore::DeterministicShard::DeterministicShard
DeterministicShard(DeterministicShard const &)=delete
ripple::NodeStore::DeterministicShard::flush
void flush()
Flush all objects from memory pool to shard.
Definition: DeterministicShard.cpp:192
std::shared_ptr< NodeObject >
ripple::NodeStore::DeterministicShard::backend_
std::shared_ptr< Backend > backend_
Definition: DeterministicShard.h:135
ripple::NodeStore::DeterministicShard::inited_
bool inited_
Definition: DeterministicShard.h:105
ripple::NodeStore::DeterministicShard::digest
std::uint64_t digest(int n) const
Definition: DeterministicShard.cpp:76
ripple::NodeStore::DeterministicShard::tempdir_
const boost::filesystem::path tempdir_
Definition: DeterministicShard.h:123
ripple::NodeStore::DeterministicShard::store
void store(nodeptr nobj)
Store the object into memory pool.
Definition: DeterministicShard.cpp:183
ripple::NodeStore::DeterministicShard::close
void close(bool cancel=false)
Finalizes and closes the shard.
Definition: DeterministicShard.cpp:163
std::function
ripple::NodeStore::DeterministicShard::hash
uint160 hash(const uint256 &lastHash) const
Definition: DeterministicShard.cpp:60
ripple::NodeStore::DeterministicShard::j_
const beast::Journal j_
Definition: DeterministicShard.h:138
ripple::NodeStore::DeterministicShard::hash_
const uint160 hash_
Definition: DeterministicShard.h:120
ripple::NodeStore::DeterministicShard::ctx_
std::unique_ptr< nudb::context > ctx_
Definition: DeterministicShard.h:132
ripple::NodeStore::DeterministicShard::init
bool init()
Initializes the deterministic shard.
Definition: DeterministicShard.cpp:100
ripple::NodeStore::DeterministicShard::index_
const std::uint32_t index_
Definition: DeterministicShard.h:117
ripple::base_uint< 256 >
ripple::NodeStore::DeterministicShard
DeterministicShard class.
Definition: DeterministicShard.h:42
ripple::NodeStore::DeterministicShard::operator=
DeterministicShard & operator=(DeterministicShard const &)=delete
ripple::NodeStore::DeterministicShard::finaldir_
const boost::filesystem::path finaldir_
Definition: DeterministicShard.h:126
ripple::NodeStore::DeterministicShard::scheduler_
DummyScheduler scheduler_
Definition: DeterministicShard.h:129
ripple::NodeStore::DeterministicShard::app_
Application & app_
Definition: DeterministicShard.h:111
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
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::NodeStore::DeterministicShard::db_
DatabaseShard const & db_
Definition: DeterministicShard.h:114
std::unique_ptr< nudb::context >
set
ripple::NodeStore::DeterministicShard::nodeset_
std::set< nodeptr, std::function< bool(nodeptr, nodeptr)> > nodeset_
Definition: DeterministicShard.h:108
ripple::NodeStore::DeterministicShard::nodeptr
std::shared_ptr< NodeObject > nodeptr
Definition: DeterministicShard.h:45