Clio
develop
The XRP Ledger API server.
Theme:
Default
Round
Robot
Toggle main menu visibility
Loading...
Searching...
No Matches
BackendFactory.hpp
1
#pragma once
2
3
#include "data/BackendInterface.hpp"
4
#include "data/CassandraBackend.hpp"
5
#include "data/KeyspaceBackend.hpp"
6
#include "data/LedgerCacheInterface.hpp"
7
#include "data/cassandra/SettingsProvider.hpp"
8
#include "util/config/ConfigDefinition.hpp"
9
#include "util/log/Logger.hpp"
10
11
#include <boost/algorithm/string.hpp>
12
#include <boost/algorithm/string/predicate.hpp>
13
14
#include <memory>
15
#include <stdexcept>
16
#include <string>
17
18
namespace
data
{
19
27
inline
std::shared_ptr<BackendInterface>
28
makeBackend
(
util::config::ClioConfigDefinition
const
& config,
data::LedgerCacheInterface
& cache)
29
{
30
using namespace
cassandra::impl;
31
static
util::Logger
const
log{
"Backend"
};
// NOLINT(readability-identifier-naming)
32
LOG(log.
info
()) <<
"Constructing BackendInterface"
;
33
34
auto
const
readOnly = config.
get
<
bool
>(
"read_only"
);
35
36
auto
const
type = config.
get
<std::string>(
"database.type"
);
37
std::shared_ptr<BackendInterface> backend =
nullptr
;
38
39
if
(boost::iequals(type,
"cassandra"
)) {
40
auto
const
cfg = config.
getObject
(
"database."
+ type);
41
if
(providerFromString(cfg.getValueView(
"provider"
).asString()) == Provider::Keyspace) {
42
backend = std::make_shared<data::cassandra::KeyspaceBackend>(
43
data::cassandra::SettingsProvider
{cfg}, cache, readOnly
44
);
45
}
else
{
46
backend = std::make_shared<data::cassandra::CassandraBackend>(
47
data::cassandra::SettingsProvider
{cfg}, cache, readOnly
48
);
49
}
50
}
51
52
if
(!backend)
53
throw
std::runtime_error(
"Invalid database type"
);
54
55
auto
const
rng = backend->hardFetchLedgerRangeNoThrow();
56
if
(rng)
57
backend->setRange(rng->minSequence, rng->maxSequence);
58
59
LOG(log.
info
()) <<
"Constructed BackendInterface Successfully"
;
60
return
backend;
61
}
62
}
// namespace data
data::LedgerCacheInterface
Cache for an entire ledger.
Definition
LedgerCacheInterface.hpp:21
data::cassandra::SettingsProvider
Provides settings for BasicCassandraBackend.
Definition
SettingsProvider.hpp:17
util::Logger
A simple thread-safe logger for the channel specified in the constructor.
Definition
Logger.hpp:78
util::Logger::info
Pump info(std::source_location const &loc=std::source_location::current()) const
Interface for logging at Severity::NFO severity.
Definition
Logger.cpp:499
util::config::ClioConfigDefinition
All the config data will be stored and extracted from this class.
Definition
ConfigDefinition.hpp:31
util::config::ClioConfigDefinition::getObject
ObjectView getObject(std::string_view prefix, std::optional< std::size_t > idx=std::nullopt) const
Returns the ObjectView specified with the prefix.
Definition
ConfigDefinition.cpp:44
util::config::ClioConfigDefinition::get
T get(std::string_view fullKey) const
Returns the specified value of given string if value exists.
Definition
ConfigDefinition.hpp:85
data
This namespace implements the data access layer and related components.
Definition
AmendmentCenter.cpp:56
data::makeBackend
std::shared_ptr< BackendInterface > makeBackend(util::config::ClioConfigDefinition const &config, data::LedgerCacheInterface &cache)
A factory function that creates the backend based on a config.
Definition
BackendFactory.hpp:28
src
data
BackendFactory.hpp
Generated by
1.17.0