-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Add support for retrying on a different cluster #25625
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
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
116 changes: 116 additions & 0 deletions
116
presto-main-base/src/main/java/com/facebook/presto/server/RetryConfig.java
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 |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| /* | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package com.facebook.presto.server; | ||
|
|
||
| import com.facebook.airlift.configuration.Config; | ||
| import com.facebook.airlift.configuration.ConfigDescription; | ||
| import com.facebook.presto.common.ErrorCode; | ||
| import com.facebook.presto.spi.StandardErrorCode; | ||
| import com.google.common.base.Splitter; | ||
| import com.google.common.collect.ImmutableSet; | ||
| import jakarta.validation.constraints.NotNull; | ||
|
|
||
| import java.util.Set; | ||
|
|
||
| import static com.facebook.presto.spi.StandardErrorCode.REMOTE_TASK_ERROR; | ||
| import static com.google.common.collect.ImmutableSet.toImmutableSet; | ||
|
|
||
| public class RetryConfig | ||
agrawalreetika marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| private boolean retryEnabled = true; | ||
| private Set<String> allowedRetryDomains = ImmutableSet.of(); | ||
| private boolean requireHttps; | ||
| private Set<Integer> crossClusterRetryErrorCodes = ImmutableSet.of( | ||
| REMOTE_TASK_ERROR.toErrorCode().getCode()); | ||
|
|
||
| public boolean isRetryEnabled() | ||
| { | ||
| return retryEnabled; | ||
| } | ||
|
|
||
| @Config("retry.enabled") | ||
| @ConfigDescription("Enable cross-cluster retry functionality") | ||
| public RetryConfig setRetryEnabled(boolean retryEnabled) | ||
| { | ||
| this.retryEnabled = retryEnabled; | ||
| return this; | ||
| } | ||
|
|
||
| @NotNull | ||
| public Set<String> getAllowedRetryDomains() | ||
| { | ||
| return allowedRetryDomains; | ||
| } | ||
|
|
||
| @Config("retry.allowed-domains") | ||
| @ConfigDescription("Comma-separated list of allowed domains for retry URLs " + | ||
| "(supports wildcards like *.example.com)") | ||
| public RetryConfig setAllowedRetryDomains(String domains) | ||
| { | ||
| if (domains == null || domains.trim().isEmpty()) { | ||
| this.allowedRetryDomains = ImmutableSet.of(); | ||
| } | ||
| else { | ||
| this.allowedRetryDomains = Splitter.on(',') | ||
| .trimResults() | ||
| .omitEmptyStrings() | ||
| .splitToList(domains) | ||
| .stream() | ||
| .map(String::toLowerCase) | ||
| .collect(toImmutableSet()); | ||
| } | ||
| return this; | ||
| } | ||
|
|
||
| public boolean isRequireHttps() | ||
| { | ||
| return requireHttps; | ||
| } | ||
|
|
||
| @Config("retry.require-https") | ||
| @ConfigDescription("Require HTTPS for retry URLs") | ||
| public RetryConfig setRequireHttps(boolean requireHttps) | ||
| { | ||
| this.requireHttps = requireHttps; | ||
| return this; | ||
| } | ||
|
|
||
| @NotNull | ||
| public Set<Integer> getCrossClusterRetryErrorCodes() | ||
| { | ||
| return crossClusterRetryErrorCodes; | ||
| } | ||
|
|
||
| @Config("retry.cross-cluster-error-codes") | ||
| @ConfigDescription("Comma-separated list of error codes that allow cross-cluster retry") | ||
| public RetryConfig setCrossClusterRetryErrorCodes(String errorCodes) | ||
| { | ||
| if (errorCodes == null || errorCodes.trim().isEmpty()) { | ||
| // Keep the default error codes | ||
| return this; | ||
| } | ||
| else { | ||
| this.crossClusterRetryErrorCodes = Splitter.on(',') | ||
| .trimResults() | ||
| .omitEmptyStrings() | ||
| .splitToList(errorCodes) | ||
| .stream() | ||
| .map(StandardErrorCode::valueOf) | ||
| .map(StandardErrorCode::toErrorCode) | ||
| .map(ErrorCode::getCode) | ||
| .collect(toImmutableSet()); | ||
| } | ||
| return this; | ||
| } | ||
| } | ||
55 changes: 55 additions & 0 deletions
55
presto-main-base/src/test/java/com/facebook/presto/server/TestRetryConfig.java
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 |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| /* | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package com.facebook.presto.server; | ||
|
|
||
| import com.facebook.airlift.configuration.testing.ConfigAssertions; | ||
| import com.google.common.collect.ImmutableMap; | ||
| import org.testng.annotations.Test; | ||
|
|
||
| import java.util.Map; | ||
|
|
||
| import static com.facebook.airlift.configuration.testing.ConfigAssertions.assertFullMapping; | ||
| import static com.facebook.airlift.configuration.testing.ConfigAssertions.assertRecordedDefaults; | ||
|
|
||
| public class TestRetryConfig | ||
| { | ||
| @Test | ||
| public void testDefaults() | ||
| { | ||
| assertRecordedDefaults(ConfigAssertions.recordDefaults(RetryConfig.class) | ||
| .setRetryEnabled(true) | ||
| .setRequireHttps(false) | ||
| .setAllowedRetryDomains(null) | ||
| .setCrossClusterRetryErrorCodes("REMOTE_TASK_ERROR")); | ||
| } | ||
|
|
||
| @Test | ||
| public void testExplicitPropertyMappings() | ||
| { | ||
| Map<String, String> properties = new ImmutableMap.Builder<String, String>() | ||
| .put("retry.enabled", "false") | ||
| .put("retry.allowed-domains", "*.foo.bar,*.baz.qux") | ||
| .put("retry.require-https", "true") | ||
| .put("retry.cross-cluster-error-codes", "QUERY_QUEUE_FULL") | ||
| .build(); | ||
|
|
||
| RetryConfig expected = new RetryConfig() | ||
| .setRetryEnabled(false) | ||
| .setRequireHttps(true) | ||
| .setAllowedRetryDomains("*.foo.bar,*.baz.qux") | ||
| .setCrossClusterRetryErrorCodes("QUERY_QUEUE_FULL"); | ||
|
|
||
| assertFullMapping(properties, expected); | ||
| } | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.