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

sync from ent repo for supportting show hosts storage listener #4984

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
7 changes: 5 additions & 2 deletions src/clients/meta/MetaClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2500,7 +2500,8 @@ folly::Future<StatusOr<bool>> 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);
}
Expand Down Expand Up @@ -2557,7 +2558,9 @@ folly::Future<StatusOr<bool>> 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());
Expand Down
23 changes: 12 additions & 11 deletions src/interface/meta.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
18 changes: 10 additions & 8 deletions src/meta/processors/admin/HBProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@ void HBProcessor::process(const cpp2::HBReq& req) {

std::vector<kvstore::KV> 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
Expand Down Expand Up @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion src/meta/processors/job/StorageJobExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/meta/processors/listener/ListenerProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions src/meta/processors/parts/ListHostsProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/meta/test/JobManagerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<cpp2::JobType> notStoppableJob{
cpp2::JobType::COMPACT,
Expand Down
2 changes: 1 addition & 1 deletion src/meta/test/MetaClientTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1666,7 +1666,7 @@ TEST(MetaClientTest, ListenerTest) {
GraphSpaceID space = ret.value();
std::vector<HostAddr> 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();
Expand Down
1 change: 1 addition & 0 deletions src/parser/parser.yy
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions src/parser/test/ParserTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/storage/StorageServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down