-
Notifications
You must be signed in to change notification settings - Fork 885
JAVA-3149: Support request cancellation in request throttler #1950
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
Conversation
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.
Looks good, thank you! Just a couple suggestions. If we can make this API compatible I will be a +1.
core/revapi.json
Outdated
{ | ||
"code": "java.method.addedToInterface", | ||
"new": "method void com.datastax.oss.driver.api.core.session.throttling.RequestThrottler::signalCancel(com.datastax.oss.driver.api.core.session.throttling.Throttled)", | ||
"justification": "JAVA-3149: Propagate cancellation of AsyncResultSet future to the throttler" |
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.
Similar to #1640 with ExecutionInfo#getExecutionProfile
, could we should add a default implementation that in this case would essentially be a no-op?
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.
Yes, you are right. I though that nearly nobody declares custom request throttler. Reported also CASSANDRA-19908 to remove in 5.0.
@@ -56,4 +56,10 @@ public interface RequestThrottler extends Closeable { | |||
* perform time-based eviction on pending requests. | |||
*/ | |||
void signalTimeout(@NonNull Throttled request); | |||
|
|||
/** | |||
* Signals that a request has been cancelled. This indicates to the throttler that another request |
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.
It took me a little bit to come around to why we couldn't just reuse an existing api method (much like the originator of the JIRA re-used signalTimeout
), but I think i agree that it makes sense that we add a new API method.
Calling future.cancel()
does not actually cancel an inflight query, which I suppose is a similar story to signalTimeout
in that C* nodes may still not be working on that query.
I think it's useful to make this a separate method so throttling implementations can make their own decision about how to handle cancel. 👍
@@ -124,6 +124,7 @@ protected CqlPrepareHandler( | |||
try { | |||
if (t instanceof CancellationException) { | |||
cancelTimeout(); | |||
context.getRequestThrottler().signalCancel(this); |
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.
One thought I immediately had was, "is it possible that we might signal to the throttler twice for the same request?".
It doesn't appear to be possible from what I can tell. It looks like CompletableFuture.cancel(..)
cannot cancel a completed exception, so this should be fine.
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.
Correct, I think the same.
integration-tests/src/test/java/com/datastax/oss/driver/core/throttling/ThrottlingIT.java
Outdated
Show resolved
Hide resolved
@@ -145,6 +145,22 @@ public void signalTimeout(@NonNull Throttled request) { | |||
} | |||
} | |||
|
|||
@Override | |||
public void signalCancel(@NonNull Throttled request) { |
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.
The code for signalTimeout/signalCancel is functionally the same except for the log, but it's probably fine this way (complexity of method is low enough that refactoring into a common method is probably not worth it).
5a3585f
to
8a462b1
Compare
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.
Looks great, thank you @lukasz-antoniak ! 👍 to merging and then we can turn to #1957
patch by Lukasz Antoniak; reviewed by Andy Tolbert and Chris Lohfink for JAVA-3149
8a462b1
to
df12d0f
Compare
Fix JAVA-3149.