forked from OpenAtomFoundation/pika
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpika_binlog_bgworker.h
48 lines (41 loc) · 1.52 KB
/
pika_binlog_bgworker.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
// 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_BINLOG_BGWORKER_H_
#define PIKA_BINLOG_BGWORKER_H_
#include "pika_command.h"
#include "bg_thread.h"
class BinlogBGWorker{
public:
BinlogBGWorker(int full) : binlogbg_thread_(full){
cmds_.reserve(300);
InitCmdTable(&cmds_);
}
~BinlogBGWorker() {
binlogbg_thread_.Stop();
DestoryCmdTable(cmds_);
}
Cmd* GetCmd(const std::string& opt) {
return GetCmdFromTable(opt, cmds_);
}
void Schedule(PikaCmdArgsType *argv, const std::string& raw_args, uint64_t serial, bool readonly) {
BinlogBGArg *arg = new BinlogBGArg(argv, raw_args, serial, readonly, this);
binlogbg_thread_.StartIfNeed();
binlogbg_thread_.Schedule(&DoBinlogBG, static_cast<void*>(arg));
}
static void DoBinlogBG(void* arg);
private:
std::unordered_map<std::string, Cmd*> cmds_;
pink::BGThread binlogbg_thread_;
struct BinlogBGArg {
PikaCmdArgsType *argv;
std::string raw_args;
uint64_t serial;
bool readonly; // Server readonly status at the view of binlog dispatch thread
BinlogBGWorker *myself;
BinlogBGArg(PikaCmdArgsType* _argv, const std::string& _raw, uint64_t _s, bool _readonly, BinlogBGWorker* _my) :
argv(_argv), raw_args(_raw), serial(_s), readonly(_readonly), myself(_my) {}
};
};
#endif