From ad46f18c97c29ffad2ebc411459a4584009fc37a Mon Sep 17 00:00:00 2001 From: liuyu <52276794+liuyu85cn@users.noreply.github.com> Date: Tue, 4 Jan 2022 15:10:33 +0800 Subject: [PATCH 1/2] add notifyStop() for metaClient --- src/clients/meta/MetaClient.cpp | 10 ++++++++-- src/clients/meta/MetaClient.h | 2 ++ src/mock/MockCluster.h | 2 ++ src/storage/StorageServer.cpp | 6 +++++- src/tools/storage-perf/StoragePerfTool.cpp | 1 + 5 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/clients/meta/MetaClient.cpp b/src/clients/meta/MetaClient.cpp index 48413c7fd21..0bf11de756c 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 7103c88e6c7..3a45cf3cce2 100644 --- a/src/clients/meta/MetaClient.h +++ b/src/clients/meta/MetaClient.h @@ -239,6 +239,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 1e898df72a3..3da26b8d0ec 100644 --- a/src/mock/MockCluster.h +++ b/src/mock/MockCluster.h @@ -94,9 +94,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..edaf896f1b9 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,8 @@ void StorageServer::stop() { taskMgr_->shutdown(); } if (metaClient_) { - metaClient_->stop(); + metaClient_->notifyStop(); + // metaClient_->stop(); } 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, " From e5786f1c9749b6e2449c61567f3ee9ec2e98826a Mon Sep 17 00:00:00 2001 From: liuyu <52276794+liuyu85cn@users.noreply.github.com> Date: Wed, 5 Jan 2022 17:29:58 +0800 Subject: [PATCH 2/2] do clean --- src/storage/StorageServer.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/storage/StorageServer.cpp b/src/storage/StorageServer.cpp index edaf896f1b9..e0a449cf734 100644 --- a/src/storage/StorageServer.cpp +++ b/src/storage/StorageServer.cpp @@ -400,7 +400,6 @@ void StorageServer::stop() { } if (metaClient_) { metaClient_->notifyStop(); - // metaClient_->stop(); } if (kvstore_) { kvstore_.reset();