forked from OpenAtomFoundation/pika
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpika_binlog_receiver_thread.cc
54 lines (47 loc) · 1.81 KB
/
pika_binlog_receiver_thread.cc
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
// 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.
#include <glog/logging.h>
#include "pink/include/pink_conn.h"
#include "include/pika_binlog_receiver_thread.h"
#include "include/pika_master_conn.h"
#include "include/pika_server.h"
#include "include/pika_command.h"
extern PikaServer* g_pika_server;
PikaBinlogReceiverThread::PikaBinlogReceiverThread(const std::set<std::string> &ips, int port,
int cron_interval)
: conn_factory_(this),
handles_(this),
serial_(0) {
cmds_.reserve(300);
InitCmdTable(&cmds_);
thread_rep_ = pink::NewHolyThread(ips, port, &conn_factory_,
cron_interval, &handles_);
thread_rep_->set_thread_name("BinlogReceiver");
}
PikaBinlogReceiverThread::~PikaBinlogReceiverThread() {
thread_rep_->StopThread();
LOG(INFO) << "BinlogReceiver thread " << thread_rep_->thread_id() << " exit!!!";
delete thread_rep_;
}
int PikaBinlogReceiverThread::StartThread() {
return thread_rep_->StartThread();
}
bool PikaBinlogReceiverThread::Handles::AccessHandle(std::string& ip) const {
if (ip == "127.0.0.1") {
ip = g_pika_server->host();
}
// if (binlog_receiver_->thread_rep_->conn_num() != 0 ||
if (!g_pika_server->ShouldAccessConnAsMaster(ip)) {
LOG(WARNING) << "BinlogReceiverThread AccessHandle failed: " << ip;
return false;
}
g_pika_server->PlusMasterConnection();
return true;
}
void PikaBinlogReceiverThread::KillBinlogSender() {
thread_rep_->KillAllConns();
// FIXME (gaodq) do in crontask ?
g_pika_server->MinusMasterConnection();
}