Clio  develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
ClusterCommunicationService.hpp
1#pragma once
2
3#include "cluster/Backend.hpp"
4#include "cluster/CacheLoaderDecider.hpp"
5#include "cluster/Concepts.hpp"
6#include "cluster/Metrics.hpp"
7#include "cluster/WriterDecider.hpp"
8#include "data/BackendInterface.hpp"
9#include "data/LedgerCacheLoadingState.hpp"
10#include "etl/SystemState.hpp"
11#include "etl/WriterState.hpp"
12#include "util/config/ConfigDefinition.hpp"
13
14#include <boost/asio/cancellation_signal.hpp>
15#include <boost/asio/spawn.hpp>
16#include <boost/asio/strand.hpp>
17#include <boost/asio/thread_pool.hpp>
18#include <boost/uuid/uuid.hpp>
19
20#include <chrono>
21#include <memory>
22
23namespace cluster {
24
30 // TODO: Use util::async::CoroExecutionContext after https://github.com/XRPLF/clio/issues/1973
31 // is implemented
32 boost::asio::thread_pool ctx_{1};
33 Backend backend_;
34 Metrics metrics_;
35 WriterDecider writerDecider_;
36 CacheLoaderDecider cacheLoaderDecider_;
37
38public:
39 static constexpr std::chrono::milliseconds kDEFAULT_READ_INTERVAL{1000};
40 static constexpr std::chrono::milliseconds kDEFAULT_WRITE_INTERVAL{1000};
41
52 std::shared_ptr<data::BackendInterface> backend,
53 std::unique_ptr<etl::WriterStateInterface> writerState,
54 std::unique_ptr<data::LedgerCacheLoadingStateInterface> cacheLoadingState,
55 std::chrono::steady_clock::duration readInterval = kDEFAULT_READ_INTERVAL,
56 std::chrono::steady_clock::duration writeInterval = kDEFAULT_WRITE_INTERVAL
57 );
58
60
64 operator=(ClusterCommunicationService&&) = delete;
66 operator=(ClusterCommunicationService const&) = delete;
67
71 void
72 run();
73
77 void
78 stop();
79
86 struct MakeResult {
87 std::unique_ptr<ClusterCommunicationService> service;
88 std::unique_ptr<data::LedgerCacheLoadingStateInterface const>
90 };
91
104 static MakeResult
105 make(
107 std::shared_ptr<BackendInterface> backend,
108 std::shared_ptr<etl::SystemState> state
109 );
110};
111
112} // namespace cluster
Backend communication handler for cluster state synchronization.
Definition Backend.hpp:37
Decides which node in the cluster should load the ledger cache.
Definition CacheLoaderDecider.hpp:25
void run()
Start the service.
Definition ClusterCommunicationService.cpp:37
static MakeResult make(util::config::ClioConfigDefinition const &config, std::shared_ptr< BackendInterface > backend, std::shared_ptr< etl::SystemState > state)
Factory method: construct the service and return a cache loading state for the caller.
Definition ClusterCommunicationService.cpp:63
void stop()
Stop the service.
Definition ClusterCommunicationService.cpp:57
ClusterCommunicationService(std::shared_ptr< data::BackendInterface > backend, std::unique_ptr< etl::WriterStateInterface > writerState, std::unique_ptr< data::LedgerCacheLoadingStateInterface > cacheLoadingState, std::chrono::steady_clock::duration readInterval=kDEFAULT_READ_INTERVAL, std::chrono::steady_clock::duration writeInterval=kDEFAULT_WRITE_INTERVAL)
Construct a new Cluster Communication Service object.
Definition ClusterCommunicationService.cpp:16
Manages Prometheus metrics for cluster communication and node tracking.
Definition Metrics.hpp:20
Decides which node in the cluster should be the writer based on cluster state.
Definition WriterDecider.hpp:64
All the config data will be stored and extracted from this class.
Definition ConfigDefinition.hpp:31
Tag type for cluster communication service implementations.
Definition Concepts.hpp:13
Result of ClusterCommunicationService::make().
Definition ClusterCommunicationService.hpp:86
std::unique_ptr< data::LedgerCacheLoadingStateInterface const > cacheLoadingState
Clone of cache loading state for use by the cache loader.
Definition ClusterCommunicationService.hpp:89
std::unique_ptr< ClusterCommunicationService > service
The constructed service.
Definition ClusterCommunicationService.hpp:87