Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simplify storage SIGINT signal handler #3437

Merged
merged 2 commits into from
Dec 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
kikimo marked this conversation as resolved.
Show resolved Hide resolved
}
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