Skip to content

Commit

Permalink
bugfix:add delay before try metasync if disconnect with Master (OpenA…
Browse files Browse the repository at this point in the history
  • Loading branch information
kernelai authored and whoiami committed Mar 20, 2020
1 parent 596281b commit 2a6b1f0
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 6 deletions.
1 change: 0 additions & 1 deletion include/pika_rm.h
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,6 @@ class PikaReplicaManager {

PikaReplClient* pika_repl_client_;
PikaReplServer* pika_repl_server_;
int last_meta_sync_timestamp_;
};

#endif // PIKA_RM_H
3 changes: 3 additions & 0 deletions include/pika_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ class PikaServer {
bool AllPartitionConnectSuccess();
bool LoopPartitionStateMachine();
void SetLoopPartitionStateMachine(bool need_loop);
int GetMetaSyncTimestamp();
void UpdateMetaSyncTimestamp();

/*
* PikaClientProcessor Process Task
Expand Down Expand Up @@ -351,6 +353,7 @@ class PikaServer {
int master_port_;
int repl_state_;
int role_;
int last_meta_sync_timestamp_;
bool loop_partition_state_machine_;
bool force_full_sync_;
pthread_rwlock_t state_protector_; //protect below, use for master-slave mode
Expand Down
2 changes: 2 additions & 0 deletions src/pika_repl_client_thread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ void PikaReplClientThread::ReplClientHandle::FdClosedHandle(int fd, const std::s
LOG(WARNING) << "Master conn disconnect : " << ip_port << " try reconnect";
g_pika_server->ResetMetaSyncStatus();
}
g_pika_server->UpdateMetaSyncTimestamp();
};

void PikaReplClientThread::ReplClientHandle::FdTimeoutHandle(int fd, const std::string& ip_port) const {
Expand All @@ -47,5 +48,6 @@ void PikaReplClientThread::ReplClientHandle::FdTimeoutHandle(int fd, const std::
&& g_pika_rm->CheckSlaveDBConnect()) { // if state machine in error state, no retry
LOG(WARNING) << "Master conn timeout : " << ip_port << " try reconnect";
g_pika_server->ResetMetaSyncStatus();
g_pika_server->UpdateMetaSyncTimestamp();
}
};
8 changes: 3 additions & 5 deletions src/pika_rm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -627,8 +627,7 @@ int SyncWindow::Remainings() {

/* PikaReplicaManger */

PikaReplicaManager::PikaReplicaManager()
: last_meta_sync_timestamp_(0) {
PikaReplicaManager::PikaReplicaManager() {
std::set<std::string> ips;
ips.insert("0.0.0.0");
int port = g_pika_conf->port() + kPortShiftReplServer;
Expand Down Expand Up @@ -973,11 +972,10 @@ Status PikaReplicaManager::DeactivateSyncSlavePartition(const PartitionInfo& p_i

Status PikaReplicaManager::SendMetaSyncRequest() {
Status s;
int now = time(NULL);
if (now - last_meta_sync_timestamp_ >= PIKA_META_SYNC_MAX_WAIT_TIME) {
if (time(NULL) - g_pika_server->GetMetaSyncTimestamp() >= PIKA_META_SYNC_MAX_WAIT_TIME) {
s = pika_repl_client_->SendMetaSync();
if (s.ok()) {
last_meta_sync_timestamp_ = now;
g_pika_server->UpdateMetaSyncTimestamp();
}
}
return s;
Expand Down
13 changes: 13 additions & 0 deletions src/pika_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ PikaServer::PikaServer() :
master_port_(0),
repl_state_(PIKA_REPL_NO_CONNECT),
role_(PIKA_ROLE_SINGLE),
last_meta_sync_timestamp_(0),
loop_partition_state_machine_(false),
force_full_sync_(false),
slowlog_entry_id_(0) {
Expand Down Expand Up @@ -832,6 +833,7 @@ void PikaServer::RemoveMaster() {
g_pika_rm->CloseReplClientConn(master_ip_, master_port_ + kPortShiftReplServer);
g_pika_rm->LostConnection(master_ip_, master_port_);
loop_partition_state_machine_ = false;
UpdateMetaSyncTimestamp();
LOG(INFO) << "Remove Master Success, ip_port: " << master_ip_ << ":" << master_port_;
}

Expand Down Expand Up @@ -921,6 +923,17 @@ void PikaServer::SetLoopPartitionStateMachine(bool need_loop) {
loop_partition_state_machine_ = need_loop;
}

int PikaServer::GetMetaSyncTimestamp() {
slash::RWLock sp_l(&state_protector_, false);
return last_meta_sync_timestamp_;

}

void PikaServer::UpdateMetaSyncTimestamp() {
slash::RWLock sp_l(&state_protector_, true);
last_meta_sync_timestamp_ = time(NULL);
}

void PikaServer::ScheduleClientPool(pink::TaskFunc func, void* arg) {
pika_client_processor_->SchedulePool(func, arg);
}
Expand Down

0 comments on commit 2a6b1f0

Please sign in to comment.