Skip to content

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

Merged
merged 1 commit into from
Sep 13, 2024

Conversation

lukasz-antoniak
Copy link
Member

@lukasz-antoniak lukasz-antoniak commented Sep 2, 2024

Fix JAVA-3149.

@tolbertam tolbertam self-requested a review September 9, 2024 01:48
Copy link
Contributor

@tolbertam tolbertam left a 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"
Copy link
Contributor

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?

Copy link
Member Author

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
Copy link
Contributor

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);
Copy link
Contributor

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.

Copy link
Member Author

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.

@@ -145,6 +145,22 @@ public void signalTimeout(@NonNull Throttled request) {
}
}

@Override
public void signalCancel(@NonNull Throttled request) {
Copy link
Contributor

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).

Copy link
Contributor

@tolbertam tolbertam left a 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants