rippled
Loading...
Searching...
No Matches
ManagerImp.cpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2012, 2013 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#include <xrpl/nodestore/detail/DatabaseNodeImp.h>
21#include <xrpl/nodestore/detail/ManagerImp.h>
22
23#include <boost/algorithm/string/predicate.hpp>
24
25namespace ripple {
26
27namespace NodeStore {
28
29ManagerImp&
31{
32 static ManagerImp _;
33 return _;
34}
35
36void
38{
39 Throw<std::runtime_error>(
40 "Your rippled.cfg is missing a [node_db] entry, "
41 "please see the rippled-example.cfg file!");
42}
43
44// We shouldn't rely on global variables for lifetime management because their
45// lifetime is not well-defined. ManagerImp may get destroyed before the Factory
46// classes, and then, calling Manager::instance().erase() in the destructors of
47// the Factory classes is an undefined behaviour.
48void
50void
52void
54void
56
64
67 Section const& parameters,
69 Scheduler& scheduler,
70 beast::Journal journal)
71{
72 std::string const type{get(parameters, "type")};
73 if (type.empty())
75
76 auto factory{find(type)};
77 if (!factory)
78 {
80 }
81
82 return factory->createInstance(
83 NodeObject::keyBytes, parameters, burstSize, scheduler, journal);
84}
85
89 Scheduler& scheduler,
90 int readThreads,
91 Section const& config,
92 beast::Journal journal)
93{
94 auto backend{make_Backend(config, burstSize, scheduler, journal)};
95 backend->open();
97 scheduler, readThreads, std::move(backend), config, journal);
98}
99
100void
102{
104 list_.push_back(&factory);
105}
106
107void
109{
111 auto const iter =
112 std::find_if(list_.begin(), list_.end(), [&factory](Factory* other) {
113 return other == &factory;
114 });
115 XRPL_ASSERT(
116 iter != list_.end(),
117 "ripple::NodeStore::ManagerImp::erase : valid input");
118 list_.erase(iter);
119}
120
121Factory*
123{
125 auto const iter =
126 std::find_if(list_.begin(), list_.end(), [&name](Factory* other) {
127 return boost::iequals(name, other->getName());
128 });
129 if (iter == list_.end())
130 return nullptr;
131 return *iter;
132}
133
134//------------------------------------------------------------------------------
135
136Manager&
138{
139 return ManagerImp::instance();
140}
141
142} // namespace NodeStore
143} // namespace ripple
A generic endpoint for log messages.
Definition Journal.h:60
static constexpr std::size_t keyBytes
Definition NodeObject.h:52
Base class for backend factories.
Definition Factory.h:36
Factory * find(std::string const &name) override
Return a pointer to the matching factory if it exists.
std::vector< Factory * > list_
Definition ManagerImp.h:33
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:32
static Manager & instance()
Returns the instance of the manager singleton.
Scheduling for asynchronous backend activity.
Holds a collection of configuration values.
Definition BasicConfig.h:45
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:25
T get(Section const &section, std::string const &name, T const &defaultValue=T{})
Retrieve a key/value pair from a section.