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:
42 static constexpr std::chrono::milliseconds kDefaultReadInterval{1000};
43
47 static constexpr std::chrono::milliseconds kDefaultWriteInterval{1000};
48
59 std::shared_ptr<data::BackendInterface> backend,
60 std::unique_ptr<etl::WriterStateInterface> writerState,
61 std::unique_ptr<data::LedgerCacheLoadingStateInterface> cacheLoadingState,
62 std::chrono::steady_clock::duration readInterval = kDefaultReadInterval,
63 std::chrono::steady_clock::duration writeInterval = kDefaultWriteInterval
64 );
65
70
74 operator=(ClusterCommunicationService&&) = delete;
76 operator=(ClusterCommunicationService const&) = delete;
77
81 void
82 run();
83
87 void
88 stop();
89
96 struct MakeResult {
97 std::unique_ptr<ClusterCommunicationService> service;
98 std::unique_ptr<data::LedgerCacheLoadingStateInterface const>
100 };
101
114 static MakeResult
115 make(
117 std::shared_ptr<BackendInterface> backend,
118 std::shared_ptr<etl::SystemState> state
119 );
120};
121
122} // namespace cluster
Backend communication handler for cluster state synchronization.
Definition Backend.hpp:43
Decides which node in the cluster should load the ledger cache.
Definition CacheLoaderDecider.hpp:25
Service to post and read messages to/from the cluster. It uses a backend to communicate with the clus...
Definition ClusterCommunicationService.hpp:29
static constexpr std::chrono::milliseconds kDefaultWriteInterval
Default interval for writing this node's state to the cluster.
Definition ClusterCommunicationService.hpp:47
void run()
Start the service.
Definition ClusterCommunicationService.cpp:36
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:62
static constexpr std::chrono::milliseconds kDefaultReadInterval
Default interval for reading other nodes' state from the cluster.
Definition ClusterCommunicationService.hpp:42
void stop()
Stop the service.
Definition ClusterCommunicationService.cpp:56
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=kDefaultReadInterval, std::chrono::steady_clock::duration writeInterval=kDefaultWriteInterval)
Construct a new Cluster Communication Service object.
Definition ClusterCommunicationService.cpp:15
~ClusterCommunicationService() override
Destroy the service, stopping all cluster communication.
Definition ClusterCommunicationService.cpp:50
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
This namespace implements cluster coordination between Clio nodes.
Definition Backend.cpp:24
Tag type for cluster communication service implementations.
Definition Concepts.hpp:13
Result of ClusterCommunicationService::make().
Definition ClusterCommunicationService.hpp:96
std::unique_ptr< data::LedgerCacheLoadingStateInterface const > cacheLoadingState
Clone of cache loading state for use by the cache loader.
Definition ClusterCommunicationService.hpp:99
std::unique_ptr< ClusterCommunicationService > service
The constructed service.
Definition ClusterCommunicationService.hpp:97