Clio  develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
ClusterCommunicationService.hpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of clio: https://github.com/XRPLF/clio
4 Copyright (c) 2025, 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 "cluster/Backend.hpp"
23#include "cluster/Concepts.hpp"
24#include "cluster/Metrics.hpp"
25#include "cluster/WriterDecider.hpp"
26#include "data/BackendInterface.hpp"
27#include "etl/WriterState.hpp"
28
29#include <boost/asio/cancellation_signal.hpp>
30#include <boost/asio/spawn.hpp>
31#include <boost/asio/strand.hpp>
32#include <boost/asio/thread_pool.hpp>
33#include <boost/uuid/uuid.hpp>
34
35#include <chrono>
36#include <memory>
37
38namespace cluster {
39
44 // TODO: Use util::async::CoroExecutionContext after https://github.com/XRPLF/clio/issues/1973 is implemented
45 boost::asio::thread_pool ctx_{1};
46 Backend backend_;
47 Metrics metrics_;
48 WriterDecider writerDecider_;
49
50public:
51 static constexpr std::chrono::milliseconds kDEFAULT_READ_INTERVAL{1000};
52 static constexpr std::chrono::milliseconds kDEFAULT_WRITE_INTERVAL{1000};
53
63 std::shared_ptr<data::BackendInterface> backend,
64 std::unique_ptr<etl::WriterStateInterface> writerState,
65 std::chrono::steady_clock::duration readInterval = kDEFAULT_READ_INTERVAL,
66 std::chrono::steady_clock::duration writeInterval = kDEFAULT_WRITE_INTERVAL
67 );
68
70
74 operator=(ClusterCommunicationService&&) = delete;
76 operator=(ClusterCommunicationService const&) = delete;
77
81 void
82 run();
83
87 void
88 stop();
89};
90
91} // namespace cluster
Backend communication handler for cluster state synchronization.
Definition Backend.hpp:55
ClusterCommunicationService(std::shared_ptr< data::BackendInterface > backend, std::unique_ptr< etl::WriterStateInterface > writerState, 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:32
void run()
Start the service.
Definition ClusterCommunicationService.cpp:44
void stop()
Stop the service.
Definition ClusterCommunicationService.cpp:61
Manages Prometheus metrics for cluster communication and node tracking.
Definition Metrics.hpp:39
Decides which node in the cluster should be the writer based on cluster state.
Definition WriterDecider.hpp:43
Tag type for cluster communication service implementations.
Definition Concepts.hpp:32