diff --git a/src/clients/meta/MetaClient.cpp b/src/clients/meta/MetaClient.cpp index 3d08c9cfe18..32c5ee7c15b 100644 --- a/src/clients/meta/MetaClient.cpp +++ b/src/clients/meta/MetaClient.cpp @@ -86,6 +86,7 @@ MetaClient::MetaClient(std::shared_ptr ioThreadPool } MetaClient::~MetaClient() { + notifyStop(); stop(); delete sessionMap_.load(); delete killedPlans_.load(); @@ -142,13 +143,18 @@ bool MetaClient::waitForMetadReady(int count, int retryIntervalSecs) { return ready_; } -void MetaClient::stop() { +void MetaClient::notifyStop() { if (bgThread_ != nullptr) { bgThread_->stop(); + } + isRunning_ = false; +} + +void MetaClient::stop() { + if (bgThread_ != nullptr) { bgThread_->wait(); bgThread_.reset(); } - isRunning_ = false; } void MetaClient::heartBeatThreadFunc() { diff --git a/src/clients/meta/MetaClient.h b/src/clients/meta/MetaClient.h index 22814b05fb0..e94b58d4c47 100644 --- a/src/clients/meta/MetaClient.h +++ b/src/clients/meta/MetaClient.h @@ -240,6 +240,8 @@ class MetaClient { bool waitForMetadReady(int count = -1, int retryIntervalSecs = FLAGS_heartbeat_interval_secs); + void notifyStop(); + void stop(); void registerListener(MetaChangedListener* listener) { diff --git a/src/mock/MockCluster.h b/src/mock/MockCluster.h index a9d72a5ebfd..45493ce4aec 100644 --- a/src/mock/MockCluster.h +++ b/src/mock/MockCluster.h @@ -95,9 +95,11 @@ class MockCluster { void stop() { if (metaClient_) { + metaClient_->notifyStop(); metaClient_->stop(); } if (lMetaClient_) { + metaClient_->notifyStop(); lMetaClient_->stop(); } if (metaKV_) { diff --git a/src/storage/StorageServer.cpp b/src/storage/StorageServer.cpp index 66b697031c3..e0a449cf734 100644 --- a/src/storage/StorageServer.cpp +++ b/src/storage/StorageServer.cpp @@ -363,6 +363,9 @@ void StorageServer::notifyStop() { serverStatus_ = STATUS_STOPPED; cvStop_.notify_one(); } + if (metaClient_) { + metaClient_->notifyStop(); + } } void StorageServer::stop() { @@ -396,7 +399,7 @@ void StorageServer::stop() { taskMgr_->shutdown(); } if (metaClient_) { - metaClient_->stop(); + metaClient_->notifyStop(); } if (kvstore_) { kvstore_.reset(); diff --git a/src/tools/storage-perf/StoragePerfTool.cpp b/src/tools/storage-perf/StoragePerfTool.cpp index ae95292ee85..f507c06237c 100644 --- a/src/tools/storage-perf/StoragePerfTool.cpp +++ b/src/tools/storage-perf/StoragePerfTool.cpp @@ -142,6 +142,7 @@ class Perf { t.join(); } + mClient_->notifyStop(); mClient_->stop(); threadPool_->stop(); LOG(INFO) << "Total time cost " << duration.elapsedInMSec() << "ms, "