Skip to content
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

Expose the logic to cancel task when the rest channel is closed #51423

Merged
merged 2 commits into from
Jan 28, 2020

Conversation

jimczi
Copy link
Contributor

@jimczi jimczi commented Jan 24, 2020

This commit moves the logic that cancels search requests when the rest channel is closed
to a generic client that can be used by other APIs. This will be useful for any rest action
that wants to cancel the execution of a task if the underlying rest channel is closed by the
client before completion.

Relates #49931
Relates #50990
Relates #49581

This commit moves the logic that cancels search requests when the rest channel is closed
to a generic client that can be used by other APIs. This will be useful for any rest action
that wants to cancel the execution of a task if the underlying rest channel is closed by the
client before completion.

Relates elastic#49931
Relates elastic#50990
Relates elastic#50990
@jimczi jimczi added >non-issue :Distributed Coordination/Task Management Issues for anything around the Tasks API - both persistent and node level. v8.0.0 v7.6.0 labels Jan 24, 2020
@jimczi jimczi requested a review from jpountz January 24, 2020 14:56
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-distributed (:Distributed/Task Management)

@jimczi
Copy link
Contributor Author

jimczi commented Jan 24, 2020

@elasticmachine run elasticsearch-ci/2

Copy link
Contributor

@jpountz jpountz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good. I think my main concern is that if the assertion in EsIntegTestCase fails, it'll be very hard to dig as it doesn't give any information about what leaked. But this looks like a phard problem and is also a pre-existing issue so let's not let it be in the way.

}
toCancel.stream().forEach(taskId -> cancelTask(taskId));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this might be abusive streams a bit, let's do a for loop?

}
public void onResponse(Void aVoid) {
final List<TaskId> toCancel;
synchronized (this) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't need to protect httpChannels so we could move the synchronized keyword two lines below?


CloseListener(Client client) {
this.client = client;
CloseListener() {
}

int getNumTasks() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it needs to be synchronized?

final List<TaskId> toCancel;
synchronized (this) {
// when the channel gets closed it won't be reused: we can remove it from the map and forget about it.
CloseListener closeListener = httpChannels.remove(channel.get());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we assert that channel.get() is not null?

@jimczi
Copy link
Contributor Author

jimczi commented Jan 27, 2020

Thanks @jpountz , I pushed a commit to address your comments.

I think my main concern is that if the assertion in EsIntegTestCase fails, it'll be very hard to dig as it doesn't give any information about what leaked.

I left this out of scope for now but I'll think about a way to add more informations in a follow up.

@jimczi jimczi merged commit 7e9153b into elastic:master Jan 28, 2020
@jimczi jimczi deleted the cancel_rest_node_client branch January 28, 2020 21:03
jimczi added a commit that referenced this pull request Jan 28, 2020
This commit moves the logic that cancels search requests when the rest channel is closed
to a generic client that can be used by other APIs. This will be useful for any rest action
that wants to cancel the execution of a task if the underlying rest channel is closed by the
client before completion.

Relates #49931
Relates #50990
Relates #50990
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Distributed Coordination/Task Management Issues for anything around the Tasks API - both persistent and node level. >non-issue v7.6.0 v8.0.0-alpha1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants