From 31c3d24fdf15be3dcdd232a8fbf73512ff0dad1a Mon Sep 17 00:00:00 2001 From: Doodle <13706157+critical27@users.noreply.github.com> Date: Tue, 21 Jul 2020 18:22:41 +0800 Subject: [PATCH] fix meta can't be stopped (#2240) * fix meta can't be stopped * address comments --- src/daemons/MetaDaemon.cpp | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/daemons/MetaDaemon.cpp b/src/daemons/MetaDaemon.cpp index 5f0b658ed32..ad58b654931 100644 --- a/src/daemons/MetaDaemon.cpp +++ b/src/daemons/MetaDaemon.cpp @@ -48,6 +48,7 @@ DEFINE_bool(daemonize, true, "Whether run as a daemon process"); DECLARE_bool(check_leader); static std::unique_ptr gServer; +static std::unique_ptr gKVStore; static void signalHandler(int sig); static Status setupSignalHandler(); @@ -210,8 +211,8 @@ int main(int argc, char *argv[]) { return EXIT_FAILURE; } - auto kvstore = initKV(peersRet.value(), localhost); - if (kvstore == nullptr) { + gKVStore = initKV(peersRet.value(), localhost); + if (gKVStore == nullptr) { LOG(ERROR) << "Init kv failed!"; return EXIT_FAILURE; } @@ -222,7 +223,7 @@ int main(int argc, char *argv[]) { pool->start(FLAGS_meta_http_thread_num, "http thread pool"); auto webSvc = std::make_unique(); - status = initWebService(webSvc.get(), kvstore.get(), helper.get(), pool.get()); + status = initWebService(webSvc.get(), gKVStore.get(), helper.get(), pool.get()); if (!status.ok()) { LOG(ERROR) << "Init web service failed: " << status; return EXIT_FAILURE; @@ -230,7 +231,7 @@ int main(int argc, char *argv[]) { { nebula::meta::JobManager* jobMgr = nebula::meta::JobManager::getInstance(); - if (!jobMgr->init(kvstore.get())) { + if (!jobMgr->init(gKVStore.get())) { LOG(ERROR) << "Init job manager failed"; return EXIT_FAILURE; } @@ -240,16 +241,16 @@ int main(int argc, char *argv[]) { /** * Only leader part needed. */ - auto ret = kvstore->partLeader(nebula::meta::kDefaultSpaceId, - nebula::meta::kDefaultPartId); + auto ret = gKVStore->partLeader(nebula::meta::kDefaultSpaceId, + nebula::meta::kDefaultPartId); if (!nebula::ok(ret)) { LOG(ERROR) << "Part leader get failed"; return EXIT_FAILURE; } if (nebula::value(ret) == localhost) { LOG(INFO) << "Check and init root user"; - if (!nebula::meta::RootUserMan::isUserExists(kvstore.get())) { - if(!nebula::meta::RootUserMan::initRootUser(kvstore.get())) { + if (!nebula::meta::RootUserMan::isUserExists(gKVStore.get())) { + if (!nebula::meta::RootUserMan::initRootUser(gKVStore.get())) { LOG(ERROR) << "Init root user failed"; return EXIT_FAILURE; } @@ -264,7 +265,7 @@ int main(int argc, char *argv[]) { return EXIT_FAILURE; } - auto handler = std::make_shared(kvstore.get(), gClusterId); + auto handler = std::make_shared(gKVStore.get(), gClusterId); LOG(INFO) << "The meta deamon start on " << localhost; try { gServer = std::make_unique(); @@ -304,6 +305,10 @@ void signalHandler(int sig) { auto gJobMgr = nebula::meta::JobManager::getInstance(); gJobMgr->shutDown(); } + if (gKVStore) { + gKVStore->stop(); + gKVStore.reset(); + } break; default: FLOG_ERROR("Signal %d(%s) received but ignored", sig, ::strsignal(sig));