-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[enhancement](cloud) improve FE RPC retry and MetaService connection handling #59698
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -63,7 +63,16 @@ void ThriftRpcHelper::setup(ExecEnv* exec_env) { | |
| template <typename T> | ||
| Status ThriftRpcHelper::rpc(const std::string& ip, const int32_t port, | ||
| std::function<void(ClientConnection<T>&)> callback, int timeout_ms) { | ||
| TNetworkAddress address = make_network_address(ip, port); | ||
| return rpc<T>([ip, port]() { return make_network_address(ip, port); }, callback, timeout_ms); | ||
| } | ||
|
|
||
| template <typename T> | ||
| Status ThriftRpcHelper::rpc(std::function<TNetworkAddress()> address_provider, | ||
| std::function<void(ClientConnection<T>&)> callback, int timeout_ms) { | ||
| TNetworkAddress address = address_provider(); | ||
| if (address.hostname.empty() || address.port == 0) { | ||
| return Status::Error<ErrorCode::SERVICE_UNAVAILABLE>("FE address is not available"); | ||
| } | ||
| Status status; | ||
| DBUG_EXECUTE_IF("thriftRpcHelper.rpc.error", { timeout_ms = 30000; }); | ||
| ClientConnection<T> client(_s_exec_env->get_client_cache<T>(), address, timeout_ms, &status); | ||
|
|
@@ -85,15 +94,36 @@ Status ThriftRpcHelper::rpc(const std::string& ip, const int32_t port, | |
| #endif | ||
| std::this_thread::sleep_for( | ||
| std::chrono::milliseconds(config::thrift_client_retry_interval_ms)); | ||
| status = client.reopen(timeout_ms); | ||
| if (!status.ok()) { | ||
| TNetworkAddress retry_address = address_provider(); | ||
| if (retry_address.hostname.empty() || retry_address.port == 0) { | ||
| return Status::Error<ErrorCode::SERVICE_UNAVAILABLE>("FE address is not available"); | ||
| } | ||
| if (retry_address.hostname != address.hostname || retry_address.port != address.port) { | ||
| #ifndef ADDRESS_SANITIZER | ||
| LOG(INFO) << "retrying call frontend service with new address=" << retry_address; | ||
| #endif | ||
| Status retry_status; | ||
| ClientConnection<T> retry_client(_s_exec_env->get_client_cache<T>(), retry_address, | ||
| timeout_ms, &retry_status); | ||
| if (!retry_status.ok()) { | ||
| #ifndef ADDRESS_SANITIZER | ||
| LOG(WARNING) << "Connect frontend failed, address=" << retry_address | ||
|
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. ditto |
||
| << ", status=" << retry_status; | ||
| #endif | ||
| return retry_status; | ||
| } | ||
| callback(retry_client); | ||
| } else { | ||
| status = client.reopen(timeout_ms); | ||
| if (!status.ok()) { | ||
| #ifndef ADDRESS_SANITIZER | ||
| LOG(WARNING) << "client reopen failed. address=" << address | ||
| << ", status=" << status; | ||
| LOG(WARNING) << "client reopen failed. address=" << address | ||
| << ", status=" << status; | ||
| #endif | ||
| return status; | ||
| return status; | ||
| } | ||
| callback(client); | ||
| } | ||
| callback(client); | ||
| } | ||
| } catch (apache::thrift::TException& e) { | ||
| #ifndef ADDRESS_SANITIZER | ||
|
|
@@ -104,8 +134,8 @@ Status ThriftRpcHelper::rpc(const std::string& ip, const int32_t port, | |
| std::chrono::milliseconds(config::thrift_client_retry_interval_ms * 2)); | ||
| // just reopen to disable this connection | ||
| static_cast<void>(client.reopen(timeout_ms)); | ||
| return Status::RpcError("failed to call frontend service, FE address={}:{}, reason: {}", ip, | ||
| port, e.what()); | ||
| return Status::RpcError("failed to call frontend service, FE address={}:{}, reason: {}", | ||
| address.hostname, address.port, e.what()); | ||
| } | ||
| return Status::OK(); | ||
| } | ||
|
|
@@ -114,6 +144,10 @@ template Status ThriftRpcHelper::rpc<FrontendServiceClient>( | |
| const std::string& ip, const int32_t port, | ||
| std::function<void(ClientConnection<FrontendServiceClient>&)> callback, int timeout_ms); | ||
|
|
||
| template Status ThriftRpcHelper::rpc<FrontendServiceClient>( | ||
| std::function<TNetworkAddress()> address_provider, | ||
| std::function<void(ClientConnection<FrontendServiceClient>&)> callback, int timeout_ms); | ||
|
|
||
| template Status ThriftRpcHelper::rpc<BackendServiceClient>( | ||
| const std::string& ip, const int32_t port, | ||
| std::function<void(ClientConnection<BackendServiceClient>&)> callback, int timeout_ms); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
why not just log without check
ifndef address?