Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 3.9k
[fix](cloud) Check instance_id valid when use cloud_unique_id degrade format #43253#43832
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -23,6 +23,7 @@ | ||||||||
| #include <sstream> | ||||||||
| #include "common/logging.h" | ||||||||
| #include "common/string_util.h" | ||||||||
| #include "common/util.h" | ||||||||
| #include "cpp/sync_point.h" | ||||||||
| #include "meta-service/keys.h" | ||||||||
| @@ -159,6 +160,16 @@ bool ResourceManager::check_cluster_params_valid(const ClusterPB& cluster, std:: | ||||||||
| int master_num = 0; | ||||||||
| int follower_num = 0; | ||||||||
| for (auto& n : cluster.nodes()) { | ||||||||
| // check here cloud_unique_id | ||||||||
| std::string cloud_unique_id = n.cloud_unique_id(); | ||||||||
| auto [is_degrade_format, instance_id] = get_instance_id_by_cloud_unique_id(cloud_unique_id); | ||||||||
| if (config::enable_check_instance_id && is_degrade_format && | ||||||||
| !is_instance_id_registered(instance_id)) { | ||||||||
| ss << "node=" << n.DebugString() | ||||||||
| << " cloud_unique_id use degrade format, but check instance failed"; | ||||||||
| *err = ss.str(); | ||||||||
| return false; | ||||||||
| } | ||||||||
| if (ClusterPB::SQL == cluster.type() && n.has_edit_log_port() && n.edit_log_port() && | ||||||||
| n.has_node_type() && | ||||||||
| (n.node_type() == NodeInfoPB_NodeType_FE_MASTER || | ||||||||
| @@ -199,6 +210,27 @@ bool ResourceManager::check_cluster_params_valid(const ClusterPB& cluster, std:: | ||||||||
| return no_err; | ||||||||
| } | ||||||||
| std::pair<bool, std::string> ResourceManager::get_instance_id_by_cloud_unique_id( | ||||||||
| const std::string& cloud_unique_id) { | ||||||||
| auto v = split(cloud_unique_id, ':'); | ||||||||
| if (v.size() != 3) return {false, ""}; | ||||||||
| // degraded format check it | ||||||||
| int version = std::atoi(v[0].c_str()); | ||||||||
| if (version != 1) return {false, ""}; | ||||||||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: statement should be inside braces [readability-braces-around-statements]
Suggested change
| ||||||||
| return {true, v[1]}; | ||||||||
| } | ||||||||
| bool ResourceManager::is_instance_id_registered(const std::string& instance_id) { | ||||||||
| // check kv | ||||||||
| auto [c0, m0] = get_instance(nullptr, instance_id, nullptr); | ||||||||
| { TEST_SYNC_POINT_CALLBACK("is_instance_id_registered", &c0); } | ||||||||
| if (c0 != TxnErrorCode::TXN_OK) { | ||||||||
| LOG(WARNING) << "failed to check instance instance_id=" << instance_id | ||||||||
| << ", code=" << format_as(c0) << ", info=" + m0; | ||||||||
| } | ||||||||
| return c0 == TxnErrorCode::TXN_OK; | ||||||||
| } | ||||||||
| std::pair<MetaServiceCode, std::string> ResourceManager::add_cluster(const std::string& instance_id, | ||||||||
| const ClusterInfo& cluster) { | ||||||||
| std::string msg; | ||||||||
| @@ -624,7 +656,7 @@ std::pair<TxnErrorCode, std::string> ResourceManager::get_instance(std::shared_p | ||||||||
| return ec; | ||||||||
| } | ||||||||
| if (!inst_pb->ParseFromString(val)) { | ||||||||
| if (inst_pb != nullptr && !inst_pb->ParseFromString(val)) { | ||||||||
| code = TxnErrorCode::TXN_UNIDENTIFIED_ERROR; | ||||||||
| msg = "failed to parse InstanceInfoPB"; | ||||||||
| return ec; | ||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: statement should be inside braces [readability-braces-around-statements]