raft 0.1.0
Loading...
Searching...
No Matches
server.hpp
1#pragma once
2
3#include <chrono>
4#include <memory>
5
6#include "raft/errors.hpp"
7#include "raft/network.hpp"
8#include "raft/server.hpp"
9
10namespace raft::enhanced
11{
18 {
19 std::string clientID;
20 uint64_t requestID;
21 };
22
27 using GlobalCommitCallback =
28 std::function<void(std::vector<std::byte> data, bool local, bool duplicate)>;
29
32 {
33 std::vector<std::byte> data;
34 bool duplicate = false;
35 };
36
39 using LocalCommitCallback = std::function<void(tl::expected<LocalCommitInfo, Error> result)>;
40
42 using EndSessionCallback = std::function<void(tl::expected<void, Error> result)>;
43
46 {
47 std::shared_ptr<raft::Network> network;
48 std::shared_ptr<raft::Server> server;
49 std::chrono::nanoseconds commitTimeout = std::chrono::seconds(5);
50 uint64_t threadCount = 1;
51 std::optional<GlobalCommitCallback> commitCallback;
52 };
53
54 class ServerImpl;
55
68 class Server
69 {
70 public:
71 explicit Server(ServerCreateConfig config);
72 ~Server();
73
74 Server(Server const&) = delete;
75 Server& operator=(Server const&) = delete;
76 Server(Server&&) noexcept;
77 Server& operator=(Server&&) noexcept;
78
83 void commit(RequestInfo const& info,
84 const std::vector<std::byte>& value,
85 LocalCommitCallback callback);
86
90 void endSession(std::string const& clientID, EndSessionCallback callback);
91
92 void setCommitCallback(GlobalCommitCallback callback);
93 void clearCommitCallback();
94
95 private:
96 std::shared_ptr<ServerImpl> pImpl_;
97 };
98} // namespace raft::enhanced
Definition server.hpp:69
void endSession(std::string const &clientID, EndSessionCallback callback)
void commit(RequestInfo const &info, const std::vector< std::byte > &value, LocalCommitCallback callback)
Information about a committed entry.
Definition server.hpp:32
bool duplicate
Whether the entry was a duplicate.
Definition server.hpp:34
std::vector< std::byte > data
The committed data.
Definition server.hpp:33
Definition server.hpp:18
uint64_t requestID
The request ID for this request.
Definition server.hpp:20
std::string clientID
The client ID for this request.
Definition server.hpp:19
Configuration for creating an enhanced Raft server.
Definition server.hpp:46
std::optional< GlobalCommitCallback > commitCallback
The commit callback to use.
Definition server.hpp:51
uint64_t threadCount
The number of threads to use for timer management.
Definition server.hpp:50
std::shared_ptr< raft::Server > server
The underlying Raft server instance.
Definition server.hpp:48
std::chrono::nanoseconds commitTimeout
The commit timeout.
Definition server.hpp:49
std::shared_ptr< raft::Network > network
The network interface for Raft communication.
Definition server.hpp:47