Clio develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
BackendFactory.hpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of clio: https://github.com/XRPLF/clio
4 Copyright (c) 2022, the clio developers.
5
6 Permission to use, copy, modify, and 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#pragma once
21
22#include "data/BackendInterface.hpp"
23#include "data/CassandraBackend.hpp"
24#include "data/cassandra/SettingsProvider.hpp"
25#include "util/log/Logger.hpp"
26#include "util/newconfig/ConfigDefinition.hpp"
27
28#include <boost/algorithm/string.hpp>
29#include <boost/algorithm/string/predicate.hpp>
30
31#include <memory>
32#include <stdexcept>
33#include <string>
34
35namespace data {
36
43inline std::shared_ptr<BackendInterface>
45{
46 static util::Logger const log{"Backend"}; // NOLINT(readability-identifier-naming)
47 LOG(log.info()) << "Constructing BackendInterface";
48
49 auto const readOnly = config.get<bool>("read_only");
50
51 auto const type = config.get<std::string>("database.type");
52 std::shared_ptr<BackendInterface> backend = nullptr;
53
54 if (boost::iequals(type, "cassandra")) {
55 auto const cfg = config.getObject("database." + type);
56 backend = std::make_shared<data::cassandra::CassandraBackend>(data::cassandra::SettingsProvider{cfg}, readOnly);
57 }
58
59 if (!backend)
60 throw std::runtime_error("Invalid database type");
61
62 auto const rng = backend->hardFetchLedgerRangeNoThrow();
63 if (rng)
64 backend->setRange(rng->minSequence, rng->maxSequence);
65
66 LOG(log.info()) << "Constructed BackendInterface Successfully";
67 return backend;
68}
69} // namespace data
Provides settings for BasicCassandraBackend.
Definition SettingsProvider.hpp:35
A simple thread-safe logger for the channel specified in the constructor.
Definition Logger.hpp:110
All the config data will be stored and extracted from this class.
Definition ConfigDefinition.hpp:54
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:61
T get(std::string_view fullKey) const
Returns the specified value of given string if value exists.
Definition ConfigDefinition.hpp:108
This namespace implements the data access layer and related components.
Definition AmendmentCenter.cpp:70
std::shared_ptr< BackendInterface > makeBackend(util::config::ClioConfigDefinition const &config)
A factory function that creates the backend based on a config.
Definition BackendFactory.hpp:44