rippled
Loading...
Searching...
No Matches
DatabaseNodeImp.h
1#ifndef XRPL_NODESTORE_DATABASENODEIMP_H_INCLUDED
2#define XRPL_NODESTORE_DATABASENODEIMP_H_INCLUDED
3
4#include <xrpl/basics/TaggedCache.h>
5#include <xrpl/basics/chrono.h>
6#include <xrpl/nodestore/Database.h>
7
8namespace ripple {
9namespace NodeStore {
10
12{
13public:
14 DatabaseNodeImp() = delete;
17 operator=(DatabaseNodeImp const&) = delete;
18
20 Scheduler& scheduler,
21 int readThreads,
23 Section const& config,
25 : Database(scheduler, readThreads, config, j)
26 , backend_(std::move(backend))
27 {
28 std::optional<int> cacheSize, cacheAge;
29
30 if (config.exists("cache_size"))
31 {
32 cacheSize = get<int>(config, "cache_size");
33 if (cacheSize.value() < 0)
34 {
35 Throw<std::runtime_error>(
36 "Specified negative value for cache_size");
37 }
38 }
39
40 if (config.exists("cache_age"))
41 {
42 cacheAge = get<int>(config, "cache_age");
43 if (cacheAge.value() < 0)
44 {
45 Throw<std::runtime_error>(
46 "Specified negative value for cache_age");
47 }
48 }
49
50 if (cacheSize != 0 || cacheAge != 0)
51 {
53 "DatabaseNodeImp",
54 cacheSize.value_or(0),
55 std::chrono::minutes(cacheAge.value_or(0)),
56 stopwatch(),
57 j);
58 }
59
60 XRPL_ASSERT(
62 "ripple::NodeStore::DatabaseNodeImp::DatabaseNodeImp : non-null "
63 "backend");
64 }
65
67 {
68 stop();
69 }
70
72 getName() const override
73 {
74 return backend_->getName();
75 }
76
78 getWriteLoad() const override
79 {
80 return backend_->getWriteLoad();
81 }
82
83 void
84 importDatabase(Database& source) override
85 {
86 importInternal(*backend_.get(), source);
87 }
88
89 void
90 store(NodeObjectType type, Blob&& data, uint256 const& hash, std::uint32_t)
91 override;
92
93 bool
95 {
96 // only one database
97 return true;
98 }
99
100 void
101 sync() override
102 {
103 backend_->sync();
104 }
105
107 fetchBatch(std::vector<uint256> const& hashes);
108
109 void
111 uint256 const& hash,
112 std::uint32_t ledgerSeq,
113 std::function<void(std::shared_ptr<NodeObject> const&)>&& callback)
114 override;
115
116 void
117 sweep() override;
118
119private:
120 // Cache for database objects. This cache is not always initialized. Check
121 // for null before using.
123 // Persistent key/value storage
125
128 uint256 const& hash,
130 FetchReport& fetchReport,
131 bool duplicate) override;
132
133 void
135 {
136 backend_->for_each(f);
137 }
138};
139
140} // namespace NodeStore
141} // namespace ripple
142
143#endif
A generic endpoint for log messages.
Definition Journal.h:41
DatabaseNodeImp(Scheduler &scheduler, int readThreads, std::shared_ptr< Backend > backend, Section const &config, beast::Journal j)
bool isSameDB(std::uint32_t, std::uint32_t) override
std::shared_ptr< Backend > backend_
std::string getName() const override
Retrieve the name associated with this backend.
void importDatabase(Database &source) override
Import objects from another database.
std::shared_ptr< TaggedCache< uint256, NodeObject > > cache_
DatabaseNodeImp(DatabaseNodeImp const &)=delete
std::vector< std::shared_ptr< NodeObject > > fetchBatch(std::vector< uint256 > const &hashes)
void store(NodeObjectType type, Blob &&data, uint256 const &hash, std::uint32_t) override
Store the object.
void for_each(std::function< void(std::shared_ptr< NodeObject >)> f) override
Visit every object in the database This is usually called during import.
void asyncFetch(uint256 const &hash, std::uint32_t ledgerSeq, std::function< void(std::shared_ptr< NodeObject > const &)> &&callback) override
Fetch an object without waiting.
std::int32_t getWriteLoad() const override
Retrieve the estimated number of pending write operations.
std::shared_ptr< NodeObject > fetchNodeObject(uint256 const &hash, std::uint32_t, FetchReport &fetchReport, bool duplicate) override
DatabaseNodeImp & operator=(DatabaseNodeImp const &)=delete
void sweep() override
Remove expired entries from the positive and negative caches.
Persistency layer for NodeObject.
Definition Database.h:32
void importInternal(Backend &dstBackend, Database &srcDB)
Definition Database.cpp:180
Scheduling for asynchronous backend activity.
Holds a collection of configuration values.
Definition BasicConfig.h:26
bool exists(std::string const &name) const
Returns true if a key with the given name exists.
T is_same_v
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
NodeObjectType
The types of node objects.
Definition NodeObject.h:13
Stopwatch & stopwatch()
Returns an instance of a wall clock.
Definition chrono.h:100
STL namespace.
Contains information about a fetch operation.
T value(T... args)
T value_or(T... args)