Revision 741a55d1 include/ReplicaManager.h
include/ReplicaManager.h | ||
---|---|---|
17 | 17 |
#ifndef REPLICA_MANAGER_H_ |
18 | 18 |
#define REPLICA_MANAGER_H_ |
19 | 19 |
|
20 |
#include <xmlrpc-c/client.hpp> |
|
21 | 20 |
#include <string> |
22 | 21 |
#include <map> |
23 | 22 |
#include <vector> |
24 | 23 |
|
25 |
class LogDBRecord;
|
|
24 |
class ReplicaThread;
|
|
26 | 25 |
|
27 |
extern "C" void * replication_thread(void *arg); |
|
28 |
|
|
29 |
// ----------------------------------------------------------------------------- |
|
30 | 26 |
// ----------------------------------------------------------------------------- |
31 |
// Replication thread class |
|
32 | 27 |
// ----------------------------------------------------------------------------- |
33 |
// ----------------------------------------------------------------------------- |
|
34 |
class ReplicaThread |
|
35 |
{ |
|
36 |
public: |
|
37 |
ReplicaThread(int follower_id); |
|
38 |
|
|
39 |
virtual ~ReplicaThread(){}; |
|
40 |
|
|
41 |
/** |
|
42 |
* Main replication logic for the thread, it sends log records to followers |
|
43 |
* and handle errors |
|
44 |
*/ |
|
45 |
void do_replication(); |
|
46 |
|
|
47 |
/** |
|
48 |
* Notify this replica thread that are new records in the log to replicate |
|
49 |
*/ |
|
50 |
void add_request(); |
|
51 |
|
|
52 |
/** |
|
53 |
* Exists the replication thread |
|
54 |
*/ |
|
55 |
void finalize(); |
|
56 |
|
|
57 |
pthread_t thread_id() const |
|
58 |
{ |
|
59 |
return _thread_id; |
|
60 |
} |
|
61 |
|
|
62 |
private: |
|
63 |
/** |
|
64 |
* C linkage function to start the thread |
|
65 |
* @param arg pointer to "this" |
|
66 |
*/ |
|
67 |
friend void * replication_thread(void *arg); |
|
68 |
|
|
69 |
// ------------------------------------------------------------------------- |
|
70 |
// pthread synchronization variables |
|
71 |
// ------------------------------------------------------------------------- |
|
72 |
pthread_t _thread_id; |
|
73 |
|
|
74 |
pthread_mutex_t mutex; |
|
75 |
|
|
76 |
pthread_cond_t cond; |
|
77 |
|
|
78 |
bool _finalize; |
|
79 |
|
|
80 |
bool _pending_requests; |
|
81 |
|
|
82 |
time_t retry_timeout; |
|
83 |
|
|
84 |
static const time_t max_retry_timeout; |
|
85 |
|
|
86 |
// ------------------------------------------------------------------------- |
|
87 |
// Information of the replication target server and leader |
|
88 |
// ------------------------------------------------------------------------- |
|
89 |
int follower_id; |
|
90 |
}; |
|
91 |
|
|
92 |
// ----------------------------------------------------------------------------- |
|
93 |
// ----------------------------------------------------------------------------- |
|
94 |
// Replication Manager |
|
28 |
// Replication Manager. This is a generic replication manager it starts, stops |
|
29 |
// and send control events to replica threads. |
|
95 | 30 |
// ----------------------------------------------------------------------------- |
96 | 31 |
// ----------------------------------------------------------------------------- |
97 | 32 |
class ReplicaManager |
98 | 33 |
{ |
99 | 34 |
public: |
100 |
ReplicaManager(){}; |
|
101 |
|
|
102 |
virtual ~ReplicaManager() |
|
103 |
{ |
|
104 |
stop_replica_threads(); |
|
105 |
}; |
|
106 |
|
|
107 | 35 |
/** |
108 | 36 |
* Start the replication threads, one for each server in the zone |
109 | 37 |
*/ |
... | ... | |
137 | 65 |
*/ |
138 | 66 |
void add_replica_thread(int follower_id); |
139 | 67 |
|
68 |
protected: |
|
69 |
ReplicaManager(){}; |
|
70 |
|
|
71 |
virtual ~ReplicaManager() |
|
72 |
{ |
|
73 |
stop_replica_threads(); |
|
74 |
}; |
|
75 |
|
|
76 |
virtual ReplicaThread * thread_factory(int follower_id) = 0; |
|
77 |
|
|
140 | 78 |
private: |
141 | 79 |
/** |
142 | 80 |
* The replication thread pool |
... | ... | |
150 | 88 |
ReplicaThread * get_thread(int server_id); |
151 | 89 |
}; |
152 | 90 |
|
91 |
// ----------------------------------------------------------------------------- |
|
92 |
// ----------------------------------------------------------------------------- |
|
93 |
// RaftReplicaManager to manage the raft replication thread pool |
|
94 |
// ----------------------------------------------------------------------------- |
|
95 |
// ----------------------------------------------------------------------------- |
|
96 |
class RaftReplicaManager : public ReplicaManager |
|
97 |
{ |
|
98 |
public: |
|
99 |
RaftReplicaManager():ReplicaManager(){}; |
|
100 |
|
|
101 |
virtual ~RaftReplicaManager(){}; |
|
102 |
|
|
103 |
private: |
|
104 |
ReplicaThread * thread_factory(int follower_id); |
|
105 |
}; |
|
106 |
|
|
153 | 107 |
#endif /*REPLICA_MANAGER_H_*/ |
154 | 108 |
|
Also available in: Unified diff