-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[fix](brpc_client_cache) resolve hostname in DNS cache before passing to brpc (#40074) #40786
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -71,11 +71,26 @@ Status transmit_block_httpv2(ExecEnv* exec_env, std::unique_ptr<Closure> closure | |||||
| TNetworkAddress brpc_dest_addr) { | ||||||
| RETURN_IF_ERROR(request_embed_attachment_contain_blockv2(closure->request_.get(), closure)); | ||||||
|
|
||||||
| std::string host = brpc_dest_addr.hostname; | ||||||
| auto dns_cache = ExecEnv::GetInstance()->dns_cache(); | ||||||
|
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: 'auto dns_cache' can be declared as 'auto *dns_cache' [readability-qualified-auto]
Suggested change
|
||||||
| if (dns_cache == nullptr) { | ||||||
| LOG(WARNING) << "DNS cache is not initialized, skipping hostname resolve"; | ||||||
| } else if (!is_valid_ip(brpc_dest_addr.hostname)) { | ||||||
| Status status = dns_cache->get(brpc_dest_addr.hostname, &host); | ||||||
| if (!status.ok()) { | ||||||
| LOG(WARNING) << "failed to get ip from host " << brpc_dest_addr.hostname << ": " | ||||||
| << status.to_string(); | ||||||
| return Status::InternalError("failed to get ip from host {}", brpc_dest_addr.hostname); | ||||||
| } | ||||||
| } | ||||||
| //format an ipv6 address | ||||||
| std::string brpc_url = get_brpc_http_url(brpc_dest_addr.hostname, brpc_dest_addr.port); | ||||||
|
|
||||||
| std::shared_ptr<PBackendService_Stub> brpc_http_stub = | ||||||
| exec_env->brpc_internal_client_cache()->get_new_client_no_cache(brpc_url, "http"); | ||||||
| if (brpc_http_stub == nullptr) { | ||||||
| return Status::InternalError("failed to open brpc http client to {}", brpc_url); | ||||||
| } | ||||||
| closure->cntl_->http_request().uri() = | ||||||
| brpc_url + "/PInternalServiceImpl/transmit_block_by_http"; | ||||||
| closure->cntl_->http_request().set_method(brpc::HTTP_METHOD_POST); | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -700,11 +700,30 @@ void VNodeChannel::try_send_pending_block(RuntimeState* state) { | |||||
| return; | ||||||
| } | ||||||
|
|
||||||
| std::string host = _node_info.host; | ||||||
| auto dns_cache = ExecEnv::GetInstance()->dns_cache(); | ||||||
|
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: 'auto dns_cache' can be declared as 'auto *dns_cache' [readability-qualified-auto]
Suggested change
|
||||||
| if (dns_cache == nullptr) { | ||||||
| LOG(WARNING) << "DNS cache is not initialized, skipping hostname resolve"; | ||||||
| } else if (!is_valid_ip(_node_info.host)) { | ||||||
| Status status = dns_cache->get(_node_info.host, &host); | ||||||
| if (!status.ok()) { | ||||||
| LOG(WARNING) << "failed to get ip from host " << _node_info.host << ": " | ||||||
| << status.to_string(); | ||||||
| _send_block_callback->clear_in_flight(); | ||||||
| return; | ||||||
| } | ||||||
| } | ||||||
| //format an ipv6 address | ||||||
| std::string brpc_url = get_brpc_http_url(_node_info.host, _node_info.brpc_port); | ||||||
| std::string brpc_url = get_brpc_http_url(host, _node_info.brpc_port); | ||||||
| std::shared_ptr<PBackendService_Stub> _brpc_http_stub = | ||||||
| _state->exec_env()->brpc_internal_client_cache()->get_new_client_no_cache(brpc_url, | ||||||
| "http"); | ||||||
| if (_brpc_http_stub == nullptr) { | ||||||
| cancel(fmt::format("{}, failed to open brpc http client to {}", channel_info(), | ||||||
| brpc_url)); | ||||||
| _send_block_callback->clear_in_flight(); | ||||||
| return; | ||||||
| } | ||||||
| _send_block_callback->cntl_->http_request().uri() = | ||||||
| brpc_url + "/PInternalServiceImpl/tablet_writer_add_block_by_http"; | ||||||
| _send_block_callback->cntl_->http_request().set_method(brpc::HTTP_METHOD_POST); | ||||||
|
|
||||||
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: 'auto dns_cache' can be declared as 'auto *dns_cache' [readability-qualified-auto]