diff --git a/src/clients/meta/MetaClient.cpp b/src/clients/meta/MetaClient.cpp index ddaa64fd897..75979fb1a10 100644 --- a/src/clients/meta/MetaClient.cpp +++ b/src/clients/meta/MetaClient.cpp @@ -2500,7 +2500,8 @@ folly::Future> MetaClient::heartbeat() { req.host_ref() = options_.localHost_; req.role_ref() = options_.role_; req.git_info_sha_ref() = options_.gitInfoSHA_; - if (options_.role_ == cpp2::HostRole::STORAGE) { + if (options_.role_ == cpp2::HostRole::STORAGE || + options_.role_ == cpp2::HostRole::STORAGE_LISTENER) { if (options_.clusterId_.load() == 0) { options_.clusterId_ = FileBasedClusterIdMan::getClusterIdFromFile(FLAGS_cluster_id_path); } @@ -2557,7 +2558,9 @@ folly::Future> MetaClient::heartbeat() { std::move(req), [](auto client, auto request) { return client->future_heartBeat(request); }, [this](cpp2::HBResp&& resp) -> bool { - if (options_.role_ == cpp2::HostRole::STORAGE && options_.clusterId_.load() == 0) { + if ((options_.role_ == cpp2::HostRole::STORAGE || + options_.role_ == cpp2::HostRole::STORAGE_LISTENER) && + options_.clusterId_.load() == 0) { LOG(INFO) << "Persist the cluster Id from metad " << resp.get_cluster_id(); if (FileBasedClusterIdMan::persistInFile(resp.get_cluster_id(), FLAGS_cluster_id_path)) { options_.clusterId_.store(resp.get_cluster_id()); diff --git a/src/interface/meta.thrift b/src/interface/meta.thrift index 95b661b84a4..93c236509ad 100644 --- a/src/interface/meta.thrift +++ b/src/interface/meta.thrift @@ -469,11 +469,12 @@ struct DropHostsReq { enum ListHostType { // nebula 1.0 show hosts, show leader, partition info - ALLOC = 0x00, - GRAPH = 0x01, - META = 0x02, - STORAGE = 0x03, - AGENT = 0x04, + ALLOC = 0x00, + GRAPH = 0x01, + META = 0x02, + STORAGE = 0x03, + AGENT = 0x04, + STORAGE_LISTENER = 0x05, } (cpp.enum_strict) struct ListHostsReq { @@ -547,12 +548,12 @@ struct HBResp { } enum HostRole { - GRAPH = 0x00, - META = 0x01, - STORAGE = 0x02, - LISTENER = 0x03, - AGENT = 0x04, - UNKNOWN = 0x05 + GRAPH = 0x00, + META = 0x01, + STORAGE = 0x02, + STORAGE_LISTENER = 0x03, + AGENT = 0x04, + UNKNOWN = 0x05 } (cpp.enum_strict) struct LeaderInfo { diff --git a/src/meta/processors/admin/HBProcessor.cpp b/src/meta/processors/admin/HBProcessor.cpp index 2f0b4dee83f..18ea3caf6c3 100644 --- a/src/meta/processors/admin/HBProcessor.cpp +++ b/src/meta/processors/admin/HBProcessor.cpp @@ -35,13 +35,15 @@ void HBProcessor::process(const cpp2::HBReq& req) { std::vector data; folly::SharedMutex::WriteHolder holder(LockUtils::lock()); - if (role == cpp2::HostRole::STORAGE) { - if (!ActiveHostsMan::machineRegisted(kvstore_, host)) { - LOG(INFO) << "Machine " << host << " is not registed"; - handleErrorCode(nebula::cpp2::ErrorCode::E_MACHINE_NOT_FOUND); - setLeaderInfo(); - onFinished(); - return; + if (role == cpp2::HostRole::STORAGE || role == cpp2::HostRole::STORAGE_LISTENER) { + if (role == cpp2::HostRole::STORAGE) { + if (!ActiveHostsMan::machineRegisted(kvstore_, host)) { + LOG(INFO) << "Machine " << host << " is not registed"; + handleErrorCode(nebula::cpp2::ErrorCode::E_MACHINE_NOT_FOUND); + setLeaderInfo(); + onFinished(); + return; + } } // set or check storaged's cluster id @@ -82,7 +84,7 @@ void HBProcessor::process(const cpp2::HBReq& req) { } // update host dir info - if (req.get_role() == cpp2::HostRole::STORAGE || req.get_role() == cpp2::HostRole::GRAPH) { + if (role == cpp2::HostRole::STORAGE || role == cpp2::HostRole::GRAPH) { if (req.dir_ref().has_value()) { LOG(INFO) << folly::sformat("Update host {} dir info, root path: {}, data path size: {}", host.toString(), diff --git a/src/meta/processors/job/StorageJobExecutor.cpp b/src/meta/processors/job/StorageJobExecutor.cpp index 3ca00036368..122f3e8b9c1 100644 --- a/src/meta/processors/job/StorageJobExecutor.cpp +++ b/src/meta/processors/job/StorageJobExecutor.cpp @@ -103,7 +103,7 @@ ErrOrHosts StorageJobExecutor::getListenerHost(GraphSpaceID space, cpp2::Listene auto activeHostsRet = ActiveHostsMan::getActiveHosts(kvstore_, FLAGS_heartbeat_interval_secs * FLAGS_expired_time_factor, - cpp2::HostRole::LISTENER); + cpp2::HostRole::STORAGE_LISTENER); if (!nebula::ok(activeHostsRet)) { return nebula::error(activeHostsRet); } diff --git a/src/meta/processors/listener/ListenerProcessor.cpp b/src/meta/processors/listener/ListenerProcessor.cpp index 4eacfec4055..82ec3549ade 100644 --- a/src/meta/processors/listener/ListenerProcessor.cpp +++ b/src/meta/processors/listener/ListenerProcessor.cpp @@ -120,7 +120,7 @@ void ListListenerProcessor::process(const cpp2::ListListenerReq& req) { auto activeHostsRet = ActiveHostsMan::getActiveHosts(kvstore_, FLAGS_heartbeat_interval_secs * FLAGS_expired_time_factor, - cpp2::HostRole::LISTENER); + cpp2::HostRole::STORAGE_LISTENER); if (!nebula::ok(activeHostsRet)) { handleErrorCode(nebula::error(activeHostsRet)); onFinished(); diff --git a/src/meta/processors/parts/ListHostsProcessor.cpp b/src/meta/processors/parts/ListHostsProcessor.cpp index 2c5855618c8..01cddbed0cb 100644 --- a/src/meta/processors/parts/ListHostsProcessor.cpp +++ b/src/meta/processors/parts/ListHostsProcessor.cpp @@ -30,6 +30,8 @@ static cpp2::HostRole toHostRole(cpp2::ListHostType type) { return cpp2::HostRole::STORAGE; case cpp2::ListHostType::AGENT: return cpp2::HostRole::AGENT; + case cpp2::ListHostType::STORAGE_LISTENER: + return cpp2::HostRole::STORAGE_LISTENER; default: return cpp2::HostRole::UNKNOWN; } diff --git a/src/meta/test/JobManagerTest.cpp b/src/meta/test/JobManagerTest.cpp index f149c300285..19c63e0ac26 100644 --- a/src/meta/test/JobManagerTest.cpp +++ b/src/meta/test/JobManagerTest.cpp @@ -752,7 +752,7 @@ TEST_F(JobManagerTest, NotStoppableJob) { }; initListener(); - TestUtils::setupHB(kv_.get(), {listener}, cpp2::HostRole::LISTENER, "sha"); + TestUtils::setupHB(kv_.get(), {listener}, cpp2::HostRole::STORAGE_LISTENER, "sha"); std::vector notStoppableJob{ cpp2::JobType::COMPACT, diff --git a/src/meta/test/MetaClientTest.cpp b/src/meta/test/MetaClientTest.cpp index affb25e7a26..d8cf7fc606a 100644 --- a/src/meta/test/MetaClientTest.cpp +++ b/src/meta/test/MetaClientTest.cpp @@ -1666,7 +1666,7 @@ TEST(MetaClientTest, ListenerTest) { GraphSpaceID space = ret.value(); std::vector listenerHosts = {{"1", 0}, {"1", 1}, {"1", 2}, {"1", 3}}; { - TestUtils::setupHB(kv, listenerHosts, cpp2::HostRole::LISTENER, gitInfoSha()); + TestUtils::setupHB(kv, listenerHosts, cpp2::HostRole::STORAGE_LISTENER, gitInfoSha()); auto addRet = client->addListener(space, cpp2::ListenerType::ELASTICSEARCH, listenerHosts).get(); ASSERT_TRUE(addRet.ok()) << addRet.status(); diff --git a/src/parser/parser.yy b/src/parser/parser.yy index bfd06536385..7ef811740d7 100644 --- a/src/parser/parser.yy +++ b/src/parser/parser.yy @@ -3470,6 +3470,7 @@ list_host_type | KW_META { $$ = meta::cpp2::ListHostType::META; } | KW_STORAGE { $$ = meta::cpp2::ListHostType::STORAGE; } | KW_AGENT { $$ = meta::cpp2::ListHostType::AGENT; } + | KW_STORAGE KW_LISTENER { $$ = meta::cpp2::ListHostType::STORAGE_LISTENER; } ; config_module_enum diff --git a/src/parser/test/ParserTest.cpp b/src/parser/test/ParserTest.cpp index 44a06b291a5..2cb7c6a18ab 100644 --- a/src/parser/test/ParserTest.cpp +++ b/src/parser/test/ParserTest.cpp @@ -1513,6 +1513,11 @@ TEST_F(ParserTest, AdminOperation) { auto result = parse(query); ASSERT_TRUE(result.ok()) << result.status(); } + { + std::string query = "SHOW HOSTS storage listener"; + auto result = parse(query); + ASSERT_TRUE(result.ok()) << result.status(); + } { std::string query = "SHOW SPACES"; auto result = parse(query); diff --git a/src/storage/StorageServer.cpp b/src/storage/StorageServer.cpp index 3407ccc35ff..4fef2b0d3b8 100644 --- a/src/storage/StorageServer.cpp +++ b/src/storage/StorageServer.cpp @@ -164,7 +164,7 @@ bool StorageServer::start() { options.role_ = nebula::meta::cpp2::HostRole::STORAGE; // If listener path is specified, it will start as a listener if (!listenerPath_.empty()) { - options.role_ = nebula::meta::cpp2::HostRole::LISTENER; + options.role_ = nebula::meta::cpp2::HostRole::STORAGE_LISTENER; } options.gitInfoSHA_ = gitInfoSha(); options.rootPath_ = boost::filesystem::current_path().string();