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

Handle rejection in PrioritizedThrottledTaskRunner #92621

Conversation

DaveCTurner
Copy link
Contributor

Today PrioritizedThrottledTaskRunner submits a bare Runnable to the executor, wrapping around the Runnable received from the caller, which effectively assumes that tasks are never rejected from the threadpool. However this utility accepts any Executor, so this is not a safe assumption to make. This commit moves to submitting an AbstractRunnable to the executor, and to requiring callers to pass in an AbstractRunnable, so that failures and rejections can be handled properly.

Today `PrioritizedThrottledTaskRunner` submits a bare `Runnable` to the
executor, wrapping around the `Runnable` received from the caller, which
effectively assumes that tasks are never rejected from the threadpool.
However this utility accepts any `Executor`, so this is not a safe
assumption to make. This commit moves to submitting an
`AbstractRunnable` to the executor, and to requiring callers to pass in
an `AbstractRunnable`, so that failures and rejections can be handled
properly.
@DaveCTurner DaveCTurner added >bug :Distributed Coordination/Snapshot/Restore Anything directly related to the `_snapshot/*` APIs v8.7.0 labels Jan 3, 2023
@DaveCTurner DaveCTurner requested a review from pxsalehi January 3, 2023 08:45
@elasticsearchmachine elasticsearchmachine added the Team:Distributed (Obsolete) Meta label for distributed team (obsolete). Replaced by Distributed Indexing/Coordination. label Jan 3, 2023
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-distributed (Team:Distributed)

@elasticsearchmachine
Copy link
Collaborator

Hi @DaveCTurner, I've created a changelog YAML for you.

@DaveCTurner
Copy link
Contributor Author

>non-issue because the places this is used today don't ever reject tasks.

spawnThread.interrupt();
spawnThread.join();
assertThat(taskRunner.runningTasks(), equalTo(0));
assertThat(taskRunner.queueSize(), equalTo(0));
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 at least one rejection happened?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, I think we can do that. See 0fc9484.

@DaveCTurner DaveCTurner added the auto-merge-without-approval Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) label Jan 3, 2023
Copy link
Member

@pxsalehi pxsalehi left a comment

Choose a reason for hiding this comment

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

I was wondering since we now use AbstractRunnable, would it make sense to also require an EsThreadPoolExecutor instead of an Executor? From what I understand, isForceExecution is enforced only if we use one of our own Executors.

@DaveCTurner
Copy link
Contributor Author

I think not, for instance because ThreadPool#executor doesn't return an EsThreadPoolExecutor so we'd have to do some casting.

IMO it's up to the caller to use an executor which is appropriate for their tasks. If they're relying on isForceExecution working then they'd better pass in an executor that uses it.

@DaveCTurner
Copy link
Contributor Author

@elasticmachine please run elasticsearch-ci/part-2

@DaveCTurner
Copy link
Contributor Author

I could see some value in accepting a plain Runnable and then checking if it's an AbstractRunnable within the runner, much like we do with EsThreadPoolExecutor, but I do prefer this approach. If anything I'd rather make EsThreadPoolExecutor refuse to work with plain old Runnable things. It's all too easy to miss stuff like rejection handling today, leading to things like #92449. But that's a whole other discussion...

@elasticsearchmachine elasticsearchmachine merged commit b990254 into elastic:main Jan 3, 2023
@DaveCTurner DaveCTurner deleted the 2023-01-03-PrioritizedThrottledTaskRunner-rejection branch January 3, 2023 10:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-merge-without-approval Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) :Distributed Coordination/Snapshot/Restore Anything directly related to the `_snapshot/*` APIs >non-issue Team:Distributed (Obsolete) Meta label for distributed team (obsolete). Replaced by Distributed Indexing/Coordination. v8.7.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants