Skip to content

Commit

Permalink
Fix Parallel Problem when check and run bg thread
Browse files Browse the repository at this point in the history
  • Loading branch information
CatKang committed Apr 19, 2016
1 parent d345e27 commit 5be1e4f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/pika.cc
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ int main(int argc, char *argv[]) {
PikaSignalSetup();
InitCmdInfoTable();

DLOG(INFO) << "Server at: " << argv[1];
DLOG(INFO) << "Server at: " << path;
g_pika_server = new PikaServer();

if (g_pika_conf->daemonize()) {
Expand Down
28 changes: 8 additions & 20 deletions src/pika_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,6 @@ void PikaServer::TryDBSync(const std::string& ip, int port, int32_t top) {
top - bgsave_info_.filenum > kDBSyncMaxGap) { //The file is not too old
// Need Bgsave first
Bgsave();
usleep(1);
}
DBSync(ip, port);
}
Expand All @@ -414,17 +413,14 @@ void PikaServer::DBSync(const std::string& ip, int port) {

// Reuse the bgsave_thread_
// Since we expect Bgsave and DBSync execute serially
if (!bgsave_thread_.is_running()) {
bgsave_thread_.StartThread();
}
bgsave_thread_.StartIfNeed();
DBSyncArg *arg = new DBSyncArg(this, ip, port);
bgsave_thread_.Schedule(&DoDBSync, static_cast<void*>(arg));
}

void PikaServer::DoDBSync(void* arg) {
DBSyncArg *ppurge = static_cast<DBSyncArg*>(arg);
PikaServer* ps = ppurge->p;
LOG(INFO) << "begin bg do dbsycn";

ps->DBSyncSendFile(ppurge->ip, ppurge->port);

Expand Down Expand Up @@ -587,13 +583,13 @@ bool PikaServer::InitBgsaveEngine() {
bool PikaServer::RunBgsaveEngine(const std::string path) {
// Backup to tmp dir
nemo::Status nemo_s = bgsave_engine_->CreateNewBackup(db().get());
LOG(INFO) << "create new backup finished.";
LOG(INFO) << "Create new backup finished.";
// Restore to bgsave dir
if (nemo_s.ok()) {
nemo_s = bgsave_engine_->RestoreDBFromBackup(
bgsave_engine_->GetLatestBackupID() + 1, path);
}
LOG(INFO) << "backup finished.";
LOG(INFO) << "Restore backup finished.";

if (!nemo_s.ok()) {
LOG(ERROR) << "backup failed :" << nemo_s.ToString();
Expand All @@ -618,12 +614,10 @@ void PikaServer::Bgsave() {
return;
}
}
LOG(ERROR) << "after prepare bgsave";
LOG(INFO) << "after prepare bgsave";

// Start new thread if needed
if (!bgsave_thread_.is_running()) {
bgsave_thread_.StartThread();
}
bgsave_thread_.StartIfNeed();
bgsave_thread_.Schedule(&DoBgsave, static_cast<void*>(this));
}

Expand Down Expand Up @@ -685,9 +679,7 @@ bool PikaServer::PurgeLogs(uint32_t to, bool manual, bool force) {
arg->manual = manual;
arg->force = force;
// Start new thread if needed
if (!purge_thread_.is_running()) {
purge_thread_.StartThread();
}
purge_thread_.StartIfNeed();
purge_thread_.Schedule(&DoPurgeLogs, static_cast<void*>(arg));
return true;
}
Expand Down Expand Up @@ -856,9 +848,7 @@ bool PikaServer::FlushAll() {
void PikaServer::PurgeDir(std::string& path) {
std::string *dir_path = new std::string(path);
// Start new thread if needed
if (!purge_thread_.is_running()) {
purge_thread_.StartThread();
}
purge_thread_.StartIfNeed();
purge_thread_.Schedule(&DoPurgeDir, static_cast<void*>(dir_path));
}

Expand Down Expand Up @@ -892,9 +882,7 @@ void PikaServer::KeyScan() {
key_scan_info_.key_scaning_ = true;
key_scan_protector_.Unlock();

if (!key_scan_thread_.is_running()) {
key_scan_thread_.StartThread();
}
key_scan_thread_.StartIfNeed();
InitKeyScan();
key_scan_thread_.Schedule(&DoKeyScan, reinterpret_cast<void*>(this));
}
Expand Down
2 changes: 1 addition & 1 deletion third/pink
Submodule pink updated from b5e509 to d2571d

0 comments on commit 5be1e4f

Please sign in to comment.