generated from amazon-archives/__template_Custom
-
Notifications
You must be signed in to change notification settings - Fork 181
Support timeouts for Calcite queries #4857
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 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a09439e
Initial implementation of query timeouts
Swiddis e30a9e4
Minor cleanup
Swiddis 1b28eb1
Set default timeout to 2m instead of 1m
Swiddis f54eff9
Add a doc
Swiddis 58bb0d9
Update timeout to 5 minutes
Swiddis 88073bd
Merge remote-tracking branch 'upstream/main' into feature/ppl-timeouts
Swiddis 9c4e3d2
Add extra interrupt per coderabbit feedback
Swiddis 277da90
Use generic thread pool for timeout task
Swiddis a058b02
Merge remote-tracking branch 'upstream/main' into feature/ppl-timeouts
Swiddis 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
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
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
83 changes: 83 additions & 0 deletions
83
...earch/src/main/java/org/opensearch/sql/opensearch/planner/rules/InterruptibleRelRule.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,83 @@ | ||
| /* | ||
| * Copyright OpenSearch Contributors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package org.opensearch.sql.opensearch.planner.rules; | ||
|
|
||
| import org.apache.calcite.plan.RelOptRuleCall; | ||
| import org.apache.calcite.plan.RelRule; | ||
| import org.opensearch.OpenSearchTimeoutException; | ||
| import org.opensearch.sql.calcite.plan.OpenSearchRuleConfig; | ||
|
|
||
| /** | ||
| * Base class for OpenSearch planner rules that automatically checks for thread interruption during | ||
| * query planning. This ensures that long-running planning operations can be interrupted when a | ||
| * query timeout occurs. | ||
| * | ||
| * <p>All OpenSearch planner rules should extend this class instead of extending {@link RelRule} | ||
| * directly. This provides automatic timeout support without requiring manual interruption checks in | ||
| * each rule. | ||
| * | ||
| * <p>Example usage: | ||
| * | ||
| * <pre>{@code | ||
| * public class MyCustomRule extends InterruptibleRelRule<MyCustomRule.Config> { | ||
| * protected MyCustomRule(Config config) { | ||
| * super(config); | ||
| * } | ||
| * | ||
| * @Override | ||
| * protected void onMatchImpl(RelOptRuleCall call) { | ||
| * // Rule implementation - interruption is checked automatically | ||
| * // before this method is called | ||
| * } | ||
| * } | ||
| * }</pre> | ||
| * | ||
| * @param <C> the configuration type for this rule | ||
| */ | ||
| public abstract class InterruptibleRelRule<C extends OpenSearchRuleConfig> extends RelRule<C> { | ||
|
|
||
| /** | ||
| * Constructs an InterruptibleRelRule with the given configuration. | ||
| * | ||
| * @param config the rule configuration | ||
| */ | ||
| protected InterruptibleRelRule(C config) { | ||
| super(config); | ||
| } | ||
|
|
||
| /** | ||
| * Called when the rule matches. This method checks for thread interruption before delegating to | ||
| * the implementation-specific {@link #onMatchImpl(RelOptRuleCall)} method. | ||
| * | ||
| * <p>Do not override this method in subclasses. Instead, override {@link | ||
| * #onMatchImpl(RelOptRuleCall)}. | ||
| * | ||
| * @param call the rule call context | ||
| * @throws RuntimeException wrapping {@link InterruptedException} if the thread has been | ||
| * interrupted | ||
| */ | ||
| @Override | ||
| public final void onMatch(RelOptRuleCall call) { | ||
| if (Thread.currentThread().isInterrupted()) { | ||
| throw new OpenSearchTimeoutException( | ||
| new InterruptedException( | ||
| "Query planning interrupted in rule: " + getClass().getSimpleName())); | ||
| } | ||
|
|
||
| onMatchImpl(call); | ||
| } | ||
|
|
||
| /** | ||
| * Implementation-specific match handler. Subclasses must implement this method instead of | ||
| * overriding {@link #onMatch(RelOptRuleCall)}. | ||
| * | ||
| * <p>This method is called after an automatic interruption check. If the thread has been | ||
| * interrupted (due to a timeout), this method will not be called. | ||
| * | ||
| * @param call the rule call context | ||
| */ | ||
| protected abstract void onMatchImpl(RelOptRuleCall call); | ||
| } |
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.
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.
Does this impact both SQL and PPL queries or only PPL?
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.
I only implemented it with Calcite in mind, but I think it applies to both (up to whatever hits OSQueryManager)