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 xrpl {
7
8namespace NodeStore {
9
10ManagerImp&
12{
13 static ManagerImp _;
14 return _;
15}
16
17void
19{
20 Throw<std::runtime_error>(
21 "Your xrpld.cfg is missing a [node_db] entry, "
22 "please see the xrpld-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{
49 std::string const type{get(parameters, "type")};
50 if (type.empty())
52
53 auto factory{find(type)};
54 if (!factory)
55 {
57 }
58
59 return factory->createInstance(NodeObject::keyBytes, parameters, burstSize, scheduler, journal);
60}
61
65 Scheduler& scheduler,
66 int readThreads,
67 Section const& config,
68 beast::Journal journal)
69{
70 auto backend{make_Backend(config, burstSize, scheduler, journal)};
71 backend->open();
72 return std::make_unique<DatabaseNodeImp>(scheduler, readThreads, std::move(backend), config, journal);
73}
74
75void
77{
79 list_.push_back(&factory);
80}
81
82void
84{
86 auto const iter =
87 std::find_if(list_.begin(), list_.end(), [&factory](Factory* other) { return other == &factory; });
88 XRPL_ASSERT(iter != list_.end(), "xrpl::NodeStore::ManagerImp::erase : valid input");
89 list_.erase(iter);
90}
91
94{
96 auto const iter = std::find_if(
97 list_.begin(), list_.end(), [&name](Factory* other) { return boost::iequals(name, other->getName()); });
98 if (iter == list_.end())
99 return nullptr;
100 return *iter;
101}
102
103//------------------------------------------------------------------------------
104
105Manager&
107{
108 return ManagerImp::instance();
109}
110
111} // namespace NodeStore
112} // namespace xrpl
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
void insert(Factory &factory) override
Add a factory.
void erase(Factory &factory) override
Remove a factory.
std::unique_ptr< Backend > make_Backend(Section const &parameters, std::size_t burstSize, Scheduler &scheduler, beast::Journal journal) override
Create a backend.
std::vector< Factory * > list_
Definition ManagerImp.h:14
static ManagerImp & instance()
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.
Factory * find(std::string const &name) override
Return a pointer to the matching factory if it exists.
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:25
T find_if(T... args)
T is_same_v
void registerNuDBFactory(Manager &manager)
void registerNullFactory(Manager &manager)
void registerMemoryFactory(Manager &manager)
void registerRocksDBFactory(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.