forked from apache/cassandra-java-driver
-
Notifications
You must be signed in to change notification settings - Fork 42
fix: contain throttled request setup failures #1007
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
Open
dkropachev
wants to merge
1
commit into
scylladb:scylla-4.x
Choose a base branch
from
dkropachev:dk/980-cql-throttler-cleanup
base: scylla-4.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -149,6 +149,8 @@ public abstract class ContinuousRequestHandlerBase<StatementT extends Request, R | |
| /** The callback selected to stream results back to the client. */ | ||
| private final CompletableFuture<NodeResponseCallback> chosenCallback = new CompletableFuture<>(); | ||
|
|
||
| private final AtomicBoolean terminal = new AtomicBoolean(); | ||
|
|
||
| /** | ||
| * How many speculative executions are currently running (including the initial execution). We | ||
| * track this in order to know when to fail the request if all executions have reached the end of | ||
|
|
@@ -283,6 +285,8 @@ public void onThrottleFailure(@NonNull RequestThrottlingException error) { | |
| } | ||
|
|
||
| private boolean abortGlobalRequestOrChosenCallback(@NonNull Throwable error) { | ||
| terminal.set(true); | ||
| cancelGlobalTimeout(); | ||
| boolean completedChosenCallback = chosenCallback.completeExceptionally(error); | ||
| if (!completedChosenCallback) { | ||
| chosenCallback.thenAccept(callback -> callback.abort(error, false)); | ||
|
|
@@ -291,7 +295,16 @@ private boolean abortGlobalRequestOrChosenCallback(@NonNull Throwable error) { | |
| } | ||
|
|
||
| public CompletionStage<ResultSetT> handle() { | ||
| globalTimeout = scheduleGlobalTimeout(); | ||
| // Immediate admission happens in the continuous graph handler's constructor. If setup failed | ||
| // there, chosenCallback is already terminal and there is no live request to time out. | ||
| if (!terminal.get()) { | ||
| globalTimeout = scheduleGlobalTimeout(); | ||
| // Admission can race with handle() after the check above but before globalTimeout is | ||
| // assigned. Ensure a synchronous terminal setup failure cannot leave that timeout behind. | ||
| if (terminal.get()) { | ||
| cancelGlobalTimeout(); | ||
| } | ||
| } | ||
| return fetchNextPage(); | ||
| } | ||
|
|
||
|
|
@@ -370,7 +383,7 @@ private void sendRequest( | |
| } | ||
| } else if (!chosenCallback.isDone()) { | ||
| boolean writeSubmitted = false; | ||
| Throwable terminalPreWriteFailure = null; | ||
| Throwable terminalSetupFailure = null; | ||
| NodeResponseCallback nodeResponseCallback = null; | ||
| try { | ||
| nodeResponseCallback = | ||
|
|
@@ -392,26 +405,35 @@ private void sendRequest( | |
| writeSubmitted = true; | ||
| writeFuture.addListener(nodeResponseCallback); | ||
| } catch (Throwable t) { | ||
| if (!writeSubmitted && activeExecutionsCount.decrementAndGet() == 0) { | ||
| if (abortGlobalRequestOrChosenCallback(t)) { | ||
| terminalPreWriteFailure = t; | ||
| recordError(node, t); | ||
| if (activeExecutionsCount.decrementAndGet() == 0) { | ||
| if (abortGlobalRequestOrChosenCallback(t) && !(t instanceof CancellationException)) { | ||
|
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. major — Leaving the release to |
||
| terminalSetupFailure = t; | ||
| } | ||
| } else { | ||
| Loggers.warnWithException( | ||
| LOG, "[{}] Request setup failed, another execution is still active", logPrefix, t); | ||
| } | ||
| throw t; | ||
| } finally { | ||
| if (!writeSubmitted) { | ||
| if (nodeResponseCallback != null) { | ||
| inFlightCallbacks.remove(nodeResponseCallback); | ||
| } | ||
| try { | ||
| channel.cancelPreAcquireId(); | ||
| } finally { | ||
| if (terminalPreWriteFailure != null) { | ||
| throttler.signalError(this, terminalPreWriteFailure); | ||
| } catch (Throwable cleanupFailure) { | ||
| if (terminalSetupFailure != null && terminalSetupFailure != cleanupFailure) { | ||
| terminalSetupFailure.addSuppressed(cleanupFailure); | ||
| } else { | ||
| Loggers.warnWithException( | ||
| LOG, "[{}] Failed to cancel stream ID reservation", logPrefix, cleanupFailure); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| if (terminalSetupFailure != null) { | ||
| throttler.signalError(this, terminalSetupFailure); | ||
| } | ||
| } else { | ||
| channel.cancelPreAcquireId(); | ||
| } | ||
|
|
||
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.