forked from OpenAtomFoundation/pika
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pika_conf.h
422 lines (354 loc) · 9.69 KB
/
pika_conf.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
// Copyright (c) 2015-present, Qihoo, Inc. All rights reserved.
// This source code is licensed under the BSD-style license found in the
// LICENSE file in the root directory of this source tree. An additional grant
// of patent rights can be found in the PATENTS file in the same directory.
#ifndef PIKA_CONF_H_
#define PIKA_CONF_H_
#include <pthread.h>
#include "stdlib.h"
#include <string>
#include <vector>
#include "pika_define.h"
#include "../third/slash/include/slash_mutex.h"
#include "../third/slash/include/slash_string.h"
#include "../third/slash/include/base_conf.h"
typedef slash::RWLock RWLock;
// TODO: 17/3/2 by zmyer
class PikaConf : public slash::BaseConf {
public:
PikaConf(const std::string &path);
~PikaConf() { pthread_rwlock_destroy(&rwlock_); }
// Getter
//TODO: 17/3/5 by zmyer
int port() {
RWLock l(&rwlock_, false);
return port_;
}
//TODO: 17/3/5 by zmyer
std::string slaveof() {
RWLock l(&rwlock_, false);
return slaveof_;
}
//TODO: 17/3/5 by zmyer
int thread_num() {
RWLock l(&rwlock_, false);
return thread_num_;
}
//TODO: 17/3/5 by zmyer
int sync_thread_num() {
RWLock l(&rwlock_, false);
return sync_thread_num_;
}
//TODO: 17/3/5 by zmyer
int sync_buffer_size() {
RWLock l(&rwlock_, false);
return sync_buffer_size_;
}
//TODO: 17/3/5 by zmyer
std::string log_path() {
RWLock l(&rwlock_, false);
return log_path_;
}
//TODO: 17/3/5 by zmyer
int log_level() {
RWLock l(&rwlock_, false);
return log_level_;
}
// TODO: 17/3/2 by zmyer
std::string db_path() {
RWLock l(&rwlock_, false);
return db_path_;
}
// TODO: 17/3/2 by zmyer
std::string db_sync_path() {
RWLock l(&rwlock_, false);
return db_sync_path_;
}
//TODO: 17/3/5 by zmyer
int db_sync_speed() {
RWLock l(&rwlock_, false);
return db_sync_speed_;
}
//TODO: 17/3/5 by zmyer
int write_buffer_size() {
RWLock l(&rwlock_, false);
return write_buffer_size_;
}
//TODO: 17/3/5 by zmyer
int timeout() {
RWLock l(&rwlock_, false);
return timeout_;
}
//TODO: 17/3/5 by zmyer
std::string requirepass() {
RWLock l(&rwlock_, false);
return requirepass_;
}
//TODO: 17/3/5 by zmyer
std::string masterauth() {
RWLock l(&rwlock_, false);
return masterauth_;
}
//TODO: 17/3/5 by zmyer
bool slotmigrate() {
RWLock l(&rwlock_, false);
return slotmigrate_;
}
//TODO: 17/3/5 by zmyer
std::string bgsave_path() {
RWLock l(&rwlock_, false);
return bgsave_path_;
}
//TODO: 17/3/5 by zmyer
std::string bgsave_prefix() {
RWLock l(&rwlock_, false);
return bgsave_prefix_;
}
//TODO: 17/3/5 by zmyer
std::string userpass() {
RWLock l(&rwlock_, false);
return userpass_;
}
//TODO: 17/3/5 by zmyer
const std::string suser_blacklist() {
RWLock l(&rwlock_, false);
return slash::StringConcat(user_blacklist_, COMMA);
}
//TODO: 17/3/5 by zmyer
const std::vector<std::string> &vuser_blacklist() {
RWLock l(&rwlock_, false);
return user_blacklist_;
}
// TODO: 17/3/2 by zmyer
std::string compression() {
RWLock l(&rwlock_, false);
return compression_;
}
//TODO: 17/3/5 by zmyer
int target_file_size_base() {
RWLock l(&rwlock_, false);
return target_file_size_base_;
}
//TODO: 17/3/5 by zmyer
int max_background_flushes() {
RWLock l(&rwlock_, false);
return max_background_flushes_;
}
//TODO: 17/3/5 by zmyer
int max_background_compactions() {
RWLock l(&rwlock_, false);
return max_background_compactions_;
}
//TODO: 17/3/5 by zmyer
int max_cache_files() {
RWLock l(&rwlock_, false);
//最大的缓冲文件数目
return max_cache_files_;
}
//TODO: 17/3/5 by zmyer
int expire_logs_nums() {
RWLock l(&rwlock_, false);
return expire_logs_nums_;
}
//TODO: 17/3/5 by zmyer
int expire_logs_days() {
RWLock l(&rwlock_, false);
return expire_logs_days_;
}
//TODO: 17/3/5 by zmyer
std::string conf_path() {
RWLock l(&rwlock_, false);
return conf_path_;
}
//TODO: 17/3/5 by zmyer
bool readonly() {
RWLock l(&rwlock_, false);
return readonly_;
}
// TODO: 17/3/2 by zmyer
int maxclients() {
RWLock l(&rwlock_, false);
return maxclients_;
}
//TODO: 17/3/5 by zmyer
int root_connection_num() {
RWLock l(&rwlock_, false);
return root_connection_num_;
}
//TODO: 17/3/5 by zmyer
int slowlog_slower_than() {
RWLock l(&rwlock_, false);
return slowlog_log_slower_than_;
}
//TODO: 17/3/5 by zmyer
std::string network_interface() {
RWLock l(&rwlock_, false);
return network_interface_;
}
// Immutable config items, we don't use lock.
// TODO: 17/3/2 by zmyer
bool daemonize() { return daemonize_; }
//TODO: 17/3/5 by zmyer
std::string pidfile() { return pidfile_; }
//TODO: 17/3/5 by zmyer
int binlog_file_size() { return binlog_file_size_; }
// Setter
//TODO: 17/3/5 by zmyer
void SetPort(const int value) {
RWLock l(&rwlock_, true);
port_ = value;
}
//TODO: 17/3/5 by zmyer
void SetThreadNum(const int value) {
RWLock l(&rwlock_, true);
thread_num_ = value;
}
//TODO: 17/3/5 by zmyer
void SetLogLevel(const int value) {
RWLock l(&rwlock_, true);
log_level_ = value;
}
//TODO: 17/3/5 by zmyer
void SetTimeout(const int value) {
RWLock l(&rwlock_, true);
timeout_ = value;
}
//TODO: 17/3/5 by zmyer
void SetSlaveof(const std::string value) {
RWLock l(&rwlock_, true);
slaveof_ = value;
}
//TODO: 17/3/5 by zmyer
void SetBgsavePath(const std::string &value) {
RWLock l(&rwlock_, true);
bgsave_path_ = value;
if (value[value.length() - 1] != '/') {
bgsave_path_ += "/";
}
}
//TODO: 17/3/5 by zmyer
void SetBgsavePrefix(const std::string &value) {
RWLock l(&rwlock_, true);
bgsave_prefix_ = value;
}
//TODO: 17/3/5 by zmyer
void SetRequirePass(const std::string &value) {
RWLock l(&rwlock_, true);
requirepass_ = value;
}
//TODO: 17/3/5 by zmyer
void SetMasterAuth(const std::string &value) {
RWLock l(&rwlock_, true);
masterauth_ = value;
}
//TODO: 17/3/5 by zmyer
void SetSlotMigrate(const std::string &value) {
RWLock l(&rwlock_, true);
slotmigrate_ = (value == "yes") ? true : false;
}
//TODO: 17/3/5 by zmyer
void SetUserPass(const std::string &value) {
RWLock l(&rwlock_, true);
userpass_ = value;
}
//TODO: 17/3/5 by zmyer
void SetUserBlackList(const std::string &value) {
RWLock l(&rwlock_, true);
slash::StringSplit(value, COMMA, user_blacklist_);
}
//TODO: 17/3/5 by zmyer
void SetReadonly(const bool value) {
RWLock l(&rwlock_, true);
readonly_ = value;
}
//TODO: 17/3/5 by zmyer
void SetExpireLogsNums(const int value) {
RWLock l(&rwlock_, true);
expire_logs_nums_ = value;
}
//TODO: 17/3/5 by zmyer
void SetExpireLogsDays(const int value) {
RWLock l(&rwlock_, true);
expire_logs_days_ = value;
}
//TODO: 17/3/5 by zmyer
void SetMaxConnection(const int value) {
RWLock l(&rwlock_, true);
maxclients_ = value;
}
//TODO: 17/3/5 by zmyer
void SetRootConnectionNum(const int value) {
RWLock l(&rwlock_, true);
root_connection_num_ = value;
}
//TODO: 17/3/5 by zmyer
void SetSlowlogSlowerThan(const int value) {
RWLock l(&rwlock_, true);
slowlog_log_slower_than_ = value;
}
//TODO: 17/3/5 by zmyer
void SetDbSyncSpeed(const int value) {
RWLock l(&rwlock_, true);
db_sync_speed_ = value;
}
int Load();
int ConfigRewrite();
private:
//端口号
int port_;
//slave节点信息
std::string slaveof_;
//线程数目
int thread_num_;
//同步线程数目
int sync_thread_num_;
//同步缓冲区的长度
int sync_buffer_size_;
//日志路径
std::string log_path_;
//数据库的路径
std::string db_path_;
//数据同步路径
std::string db_sync_path_;
//数据库同步速率
int db_sync_speed_;
//写入缓冲区的长度
int write_buffer_size_;
//日志等级
int log_level_;
//守护进程标记
bool daemonize_;
//
bool slotmigrate_;
//超时时间
int timeout_;
std::string requirepass_;
std::string masterauth_;
std::string userpass_;
std::vector<std::string> user_blacklist_;
std::string bgsave_path_;
std::string bgsave_prefix_;
std::string pidfile_;
//char pidfile_[PIKA_WORD_SIZE];
std::string compression_;
int maxclients_;
int root_connection_num_;
int slowlog_log_slower_than_;
int expire_logs_days_;
int expire_logs_nums_;
bool readonly_;
std::string conf_path_;
int max_background_flushes_;
int max_background_compactions_;
int max_cache_files_;
std::string network_interface_;
//char username_[30];
//char password_[30];
//
// Critical configure items
//
int target_file_size_base_;
int binlog_file_size_;
pthread_rwlock_t rwlock_;
};
#endif