Skip to content

Commit

Permalink
sigal handler will only call a trigger
Browse files Browse the repository at this point in the history
  • Loading branch information
liuyu85cn committed Dec 8, 2021
1 parent dd06a53 commit a668c1c
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/daemons/StorageDaemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ void signalHandler(int sig) {
case SIGTERM:
FLOG_INFO("Signal %d(%s) received, stopping this server", sig, ::strsignal(sig));
if (gStorageServer) {
gStorageServer->stop();
gStorageServer->notifyStop();
}
break;
default:
Expand Down
25 changes: 25 additions & 0 deletions src/storage/StorageServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,15 +305,40 @@ bool StorageServer::start() {
internalStorageSvcStatus_.load() != STATUS_RUNNING) {
return false;
}
{
std::lock_guard<std::mutex> lkStop(muStop_);
if (serverStatus_ != STATUS_UNINITIALIZED) {
// stop() called during start()
return false;
}
serverStatus_ = STATUS_RUNNING;
}
return true;
}

void StorageServer::waitUntilStop() {
{
std::unique_lock<std::mutex> lkStop(muStop_);
while (serverStatus_ == STATUS_RUNNING) {
cvStop_.wait(lkStop);
}
}

this->stop();

adminThread_->join();
storageThread_->join();
internalStorageThread_->join();
}

void StorageServer::notifyStop() {
std::unique_lock<std::mutex> lkStop(muStop_);
if (serverStatus_ == STATUS_RUNNING) {
serverStatus_ = STATUS_STOPPED;
cvStop_.notify_one();
}
}

void StorageServer::stop() {
if (adminSvcStatus_.load() == ServiceStatus::STATUS_STOPPED &&
storageSvcStatus_.load() == ServiceStatus::STATUS_STOPPED &&
Expand Down
7 changes: 7 additions & 0 deletions src/storage/StorageServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ class StorageServer final {

void stop();

// used for signal handler to set an internal stop flag
void notifyStop();

void waitUntilStop();

private:
Expand Down Expand Up @@ -88,6 +91,10 @@ class StorageServer final {
std::unique_ptr<TransactionManager> txnMan_{nullptr};
// used for communicate between one storaged to another
std::unique_ptr<InternalStorageClient> interClient_;

ServiceStatus serverStatus_{STATUS_UNINITIALIZED};
std::mutex muStop_;
std::condition_variable cvStop_;
};

} // namespace storage
Expand Down
1 change: 1 addition & 0 deletions src/storage/transaction/TransactionManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ bool TransactionManager::start() {
}

void TransactionManager::stop() {
exec_->stop();
resumeThread_->stop();
resumeThread_->wait();
}
Expand Down

0 comments on commit a668c1c

Please sign in to comment.