-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.hpp
More file actions
35 lines (32 loc) · 939 Bytes
/
Copy pathserver.hpp
File metadata and controls
35 lines (32 loc) · 939 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#pragma once
#include <string>
#include <unordered_map>
#include <shared_mutex>
#include "thread_pool.hpp"
#include "wal.hpp"
#include "raft.hpp"
#include "consistent_hash.hpp"
class Server {
public:
Server(int port, size_t num_threads, const std::string& wal_file, int node_id, const std::string& node_name);
~Server();
void run();
void add_cluster_node(const std::string& node_name);
Raft& get_raft();
private:
int port_;
std::string node_name_;
int server_fd_;
int epoll_fd_;
std::unordered_map<std::string, std::string> store_;
std::shared_mutex store_mutex_;
ThreadPool thread_pool_;
WAL wal_;
Raft raft_;
ConsistentHash ring_;
void setup_server();
void set_non_blocking(int fd);
void handle_new_connection();
void handle_client_data(int client_fd);
void process_command(int client_fd, const std::string& command);
};