rippled
Loading...
Searching...
No Matches
ManagerImp.cpp
1#include <xrpl/nodestore/detail/DatabaseNodeImp.h>
2#include <xrpl/nodestore/detail/ManagerImp.h>
3
4#include <boost/algorithm/string/predicate.hpp>
5
6namespace ripple {
7
8namespace NodeStore {
9
10ManagerImp&
12{
13 static ManagerImp _;
14 return _;
15}
16
17void
19{
20 Throw<std::runtime_error>(
21 "Your rippled.cfg is missing a [node_db] entry, "
22 "please see the rippled-example.cfg file!");
23}
24
25// We shouldn't rely on global variables for lifetime management because their
26// lifetime is not well-defined. ManagerImp may get destroyed before the Factory
27// classes, and then, calling Manager::instance().erase() in the destructors of
28// the Factory classes is an undefined behaviour.
29void
31void
33void
35void
37
45
48 Section const& parameters,
50 Scheduler& scheduler,
51 beast::Journal journal)
52{
53 std::string const type{get(parameters, "type")};
54 if (type.empty())
56
57 auto factory{find(type)};
58 if (!factory)
59 {
61 }
62
63 return factory->createInstance(
64 NodeObject::keyBytes, parameters, burstSize, scheduler, journal);
65}
66
70 Scheduler& scheduler,
71 int readThreads,
72 Section const& config,
73 beast::Journal journal)
74{
75 auto backend{make_Backend(config, burstSize, scheduler, journal)};
76 backend->open();
78 scheduler, readThreads, std::move(backend), config, journal);
79}
80
81void
83{
85 list_.push_back(&factory);
86}
87
88void
90{
92 auto const iter =
93 std::find_if(list_.begin(), list_.end(), [&factory](Factory* other) {
94 return other == &factory;
95 });
96 XRPL_ASSERT(
97 iter != list_.end(),
98 "ripple::NodeStore::ManagerImp::erase : valid input");
99 list_.erase(iter);
100}
101
102Factory*
104{
106 auto const iter =
107 std::find_if(list_.begin(), list_.end(), [&name](Factory* other) {
108 return boost::iequals(name, other->getName());
109 });
110 if (iter == list_.end())
111 return nullptr;
112 return *iter;
113}
114
115//------------------------------------------------------------------------------
116
117Manager&
119{
120 return ManagerImp::instance();
121}
122
123} // namespace NodeStore
124} // namespace ripple
A generic endpoint for log messages.
Definition Journal.h:41
static constexpr std::size_t keyBytes
Definition NodeObject.h:33
Base class for backend factories.
Definition Factory.h:17
Factory * find(std::string const &name) override
Return a pointer to the matching factory if it exists.
std::vector< Factory * > list_
Definition ManagerImp.h:14
std::unique_ptr< Database > make_Database(std::size_t burstSize, Scheduler &scheduler, int readThreads, Section const &config, beast::Journal journal) override
Construct a NodeStore database.
static ManagerImp & instance()
void insert(Factory &factory) override
Add a factory.
std::unique_ptr< Backend > make_Backend(Section const &parameters, std::size_t burstSize, Scheduler &scheduler, beast::Journal journal) override
Create a backend.
void erase(Factory &factory) override
Remove a factory.
Singleton for managing NodeStore factories and back ends.
Definition Manager.h:13
static Manager & instance()
Returns the instance of the manager singleton.
Scheduling for asynchronous backend activity.
Holds a collection of configuration values.
Definition BasicConfig.h:26
T find_if(T... args)
T is_same_v
void registerRocksDBFactory(Manager &manager)
void registerNuDBFactory(Manager &manager)
void registerMemoryFactory(Manager &manager)
void registerNullFactory(Manager &manager)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
T get(Section const &section, std::string const &name, T const &defaultValue=T{})
Retrieve a key/value pair from a section.