-
Notifications
You must be signed in to change notification settings - Fork 42
fix: release pre-acquired stream ids #965
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
base: scylla-4.x
Are you sure you want to change the base?
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 |
|---|---|---|
|
|
@@ -38,6 +38,7 @@ | |
| import java.util.Map; | ||
| import java.util.concurrent.CompletionStage; | ||
| import java.util.concurrent.TimeUnit; | ||
| import java.util.concurrent.atomic.AtomicBoolean; | ||
| import net.jcip.annotations.ThreadSafe; | ||
|
|
||
| @ThreadSafe | ||
|
|
@@ -104,10 +105,11 @@ public static ThrottledAdminRequestHandler<ByteBuffer> prepare( | |
| private final long startTimeNanos; | ||
| private final RequestThrottler throttler; | ||
| private final SessionMetricUpdater metricUpdater; | ||
| private final AtomicBoolean holdsExternalReservation; | ||
|
|
||
| protected ThrottledAdminRequestHandler( | ||
| DriverChannel channel, | ||
| boolean preAcquireId, | ||
| boolean shouldPreAcquireId, | ||
| Message message, | ||
| Map<String, ByteBuffer> customPayload, | ||
| Duration timeout, | ||
|
|
@@ -118,7 +120,7 @@ protected ThrottledAdminRequestHandler( | |
| Class<? extends Result> expectedResponseType) { | ||
| super( | ||
| channel, | ||
| preAcquireId, | ||
| shouldPreAcquireId, | ||
| message, | ||
| customPayload, | ||
| timeout, | ||
|
|
@@ -128,33 +130,55 @@ protected ThrottledAdminRequestHandler( | |
| this.startTimeNanos = System.nanoTime(); | ||
| this.throttler = throttler; | ||
| this.metricUpdater = metricUpdater; | ||
| this.holdsExternalReservation = new AtomicBoolean(!shouldPreAcquireId); | ||
| } | ||
|
|
||
| @Override | ||
| public CompletionStage<ResultT> start() { | ||
| // Don't write request yet, wait for green light from throttler | ||
| throttler.register(this); | ||
| try { | ||
| throttler.register(this); | ||
| } catch (Throwable t) { | ||
| cancelExternalReservation(); | ||
|
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. This cancels but doesn't |
||
| throw t; | ||
| } | ||
| return result; | ||
| } | ||
|
|
||
| @Override | ||
| public void onThrottleReady(boolean wasDelayed) { | ||
| if (wasDelayed) { | ||
| metricUpdater.updateTimer( | ||
| DefaultSessionMetric.THROTTLING_DELAY, | ||
| null, | ||
| System.nanoTime() - startTimeNanos, | ||
| TimeUnit.NANOSECONDS); | ||
| try { | ||
| if (wasDelayed) { | ||
| metricUpdater.updateTimer( | ||
| DefaultSessionMetric.THROTTLING_DELAY, | ||
| null, | ||
| System.nanoTime() - startTimeNanos, | ||
| TimeUnit.NANOSECONDS); | ||
| } | ||
| holdsExternalReservation.set(false); | ||
| super.start(); | ||
| } catch (Throwable t) { | ||
| cancelExternalReservation(); | ||
| setFinalError(t); | ||
| throw t; | ||
|
dkropachev marked this conversation as resolved.
dkropachev marked this conversation as resolved.
|
||
| } | ||
| super.start(); | ||
| } | ||
|
|
||
| @Override | ||
| public void onThrottleFailure(@NonNull RequestThrottlingException error) { | ||
| cancelExternalReservation(); | ||
| metricUpdater.incrementCounter(DefaultSessionMetric.THROTTLING_ERRORS, null); | ||
| setFinalError(error); | ||
| } | ||
|
|
||
| private void cancelExternalReservation() { | ||
| // register() can invoke onThrottleReady() synchronously. If that callback throws, both | ||
| // onThrottleReady() and start() catch the same failure, so cancellation must be idempotent. | ||
| if (holdsExternalReservation.compareAndSet(true, false)) { | ||
| cancelCallerOwnedPreAcquireId(); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| protected boolean setFinalResult(ResultT result) { | ||
| boolean wasSet = super.setFinalResult(result); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.