-
Notifications
You must be signed in to change notification settings - Fork 0
/
msgiddbd.h
147 lines (112 loc) · 3.41 KB
/
msgiddbd.h
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#pragma once
/* for logfiles */
struct segment_local /* 272 bytes per struct */
{
fileid_t fileid; /* 32 */
date_t date; /* 32 */
segment_size_t size; /* 32 */
segment_no_t segment; /* 16 */
msgid_len_t msgid_len; /* 8 */
int8_t reserved; /* 8 alignment bits */
msgid_t msgid[256];
} __attribute__ ((packed));
/* temporary local storage for sorting before send */
struct segment_local_p /* as above, but a pointer for msgid */
{
fileid_t fileid; /* 32 */
date_t date; /* 32 */
segment_size_t size; /* 32 */
segment_no_t segment; /* 16 */
msgid_len_t msgid_len; /* 8 */
msgid_t *msgid_p; /* 8 */
};
/* persistent data that we need to remember across restarts */
/* this is stored in file DATABASE_PERSISTENT_DATA (pd.dat) */
/* we pad it to 4k so more can be added and it should carry on working */
/* also note it's completely unused atm ;) - left code in for future re-use */
struct persistent_data_header
{
file_magic_t magic; /* 64 */
} __attribute__ ((packed));
struct persistent_data
{
fd_t fd;
mmap_t m;
struct persistent_data_header *h;
} __attribute__ ((packed));
/* keep track of which msgiddbds we are connected to; this is allocated to
* MAX_MSGIDDBDS_CONNECTED and used in a 1:1 mapping between
* cfg->remotes:serverX as g->masters[X] */
struct master
{
pthread_t thread;
bool thread_running;
char id[128];
/* fd=0 signifies not connected */
fd_t fd;
FILE *stream;
/* keep track of our master's logfile/position */
char log_file[128];
ssize_t log_pos;
/* from masters.ini; is this master actually turned on? */
bool enabled;
/* keep count of the number of rows we've done since connecting to
* this master */
uint64_t segments_replicated;
};
/* we use an array of these to keep track of other msgiddbd's connected to us */
struct slave
{
/* use zero here to indicate unconnected member */
fd_t fd;
/* server identification (local:id cfg value) - these should be
* unique amongst the array; ie only one connection to a server */
char id[128];
bool in_live_replication;
bool stop_replicating; /* be_a_slave_cmd_reader sets this on 'STOP' */
struct Queue *incoming_rows;
/* where is the slave in replication? */
char log_file[128];
ssize_t log_pos;
};
/* global struct to dump everything that needs accessing everywhere */
struct ShareData
{
uint8_t inserts_enabled;
time_t time_start;
uint32_t open_clients;
uint64_t total_clients;
uint64_t last_stat_time;
uint64_t segments_inserted, segments_selected;
/* number of segments read/executed from all masters since start */
uint64_t segments_replicated;
//dictionary *cfg;
struct
{
/* these are all just pointers unless otherwise noted */
char *file;
char *local_id;
char *dbroot;
char *port;
char *stats_port;
} cfg;
struct Queue *threads_to_reap;
struct Queue *replicated_log_entries;
struct Queue *incoming_clients;
uint32_t client_handler_count;
struct tables *t;
struct logfile *l; /* the current logfile being written to */
pthread_mutex_t L_logfile_rotation;
struct persistent_data *pd;
/* allocated to MAX_MSGIDDBDS_CONNECTED */
struct slave *slaves;
struct master *masters;
int32_t signal;
bool time_to_die;
};
/* global anonymous struct so that the signal handler can see threads */
struct
{
pthread_t listener, sighandler, replication_master,
reaper, stats_listen;
} threads;