forked from OpenAtomFoundation/pikiwidb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpika_auxiliary_thread.cc
52 lines (44 loc) · 1.51 KB
/
pika_auxiliary_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
// Copyright (c) 2019-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 "include/pika_define.h"
#include "include/pika_auxiliary_thread.h"
#include "include/pika_rm.h"
#include "include/pika_server.h"
extern PikaServer* g_pika_server;
extern std::unique_ptr<PikaReplicaManager> g_pika_rm;
using namespace std::chrono_literals;
PikaAuxiliaryThread::~PikaAuxiliaryThread() {
StopThread();
LOG(INFO) << "PikaAuxiliary thread " << thread_id() << " exit!!!";
}
void* PikaAuxiliaryThread::ThreadMain() {
while (!should_stop()) {
if (g_pika_server->ShouldMetaSync()) {
g_pika_rm->SendMetaSyncRequest();
} else if (g_pika_server->MetaSyncDone()) {
g_pika_rm->RunSyncSlaveDBStateMachine();
}
pstd::Status s = g_pika_rm->CheckSyncTimeout(pstd::NowMicros());
if (!s.ok()) {
LOG(WARNING) << s.ToString();
}
g_pika_server->CheckLeaderProtectedMode();
// TODO(whoiami) timeout
s = g_pika_server->TriggerSendBinlogSync();
if (!s.ok()) {
LOG(WARNING) << s.ToString();
}
// send to peer
int res = g_pika_server->SendToPeer();
if (res == 0) {
// sleep 100 ms
std::unique_lock lock(mu_);
cv_.wait_for(lock, 100ms);
} else {
// LOG_EVERY_N(INFO, 1000) << "Consume binlog number " << res;
}
}
return nullptr;
}