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

[ML] Wait for job updates in AutoDetectResultProcessor.awaitCompletion #36856

Merged
merged 3 commits into from
Dec 20, 2018

Conversation

davidkyle
Copy link
Member

@davidkyle davidkyle commented Dec 19, 2018

There is a race where the job update in AutoDetectResultProcessor.updateEstablishedModelMemoryOnJob may execute after AutoDetectResultProcessor.awaitCompletion returns. This was because jobUpdateSemaphore was acquired after the call to jobResultsProvider.getEstablishedMemoryUsage and during that call awaitCompletion is free to acquire and release the semaphore after which the method returns.

Closes #36849

@davidkyle davidkyle added >test Issues or PRs that are addressing/adding tests :ml Machine learning labels Dec 19, 2018
@elasticmachine
Copy link
Collaborator

Pinging @elastic/ml-core

@davidkyle davidkyle changed the title [ML] [ML] Wait for job updates in AutoDetectResultProcessor.awaitCompletion Dec 19, 2018
jobResultsProvider.getEstablishedMemoryUsage(jobId, latestBucketTimestamp, modelSizeStatsForCalc, establishedModelMemory -> {
if (latestEstablishedModelMemory != establishedModelMemory) {


client.threadPool().executor(MachineLearning.UTILITY_THREAD_POOL_NAME).submit(() -> {
Copy link
Member Author

Choose a reason for hiding this comment

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

Can submit() throw? I'm not sure if it is necessary to wrap this in a try...catch and release the semaphore in the catch

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, it can throw rejected execution exception if the thread pool’s queue is full or it is shutting down.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, it can use execute() rather than submit() as it's not interested in getting a Future to track completion. Since you're off I'll push another commit that changes both things.

Also use execute() rather than submit() when scheduling update
Copy link
Contributor

@dimitris-athanasiou dimitris-athanasiou left a comment

Choose a reason for hiding this comment

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

LGTM

@droberts195 droberts195 merged commit 5a9ea81 into elastic:6.x Dec 20, 2018
droberts195 pushed a commit that referenced this pull request Dec 20, 2018
#36856)

There was a race where the job update in `AutoDetectResultProcessor.updateEstablishedModelMemoryOnJob`
could execute after `AutoDetectResultProcessor.awaitCompletion`
returned. This was because ` jobUpdateSemaphore` was acquired
after the call to `jobResultsProvider.getEstablishedMemoryUsage`
and during that call `awaitCompletion` is free to acquire and
release the semaphore after which the method returns.

This commit fixes the problem.

Closes #36849
@davidkyle davidkyle deleted the fix-autodetectresutprocessor-race branch January 2, 2019 13:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:ml Machine learning >test Issues or PRs that are addressing/adding tests v6.6.0 v6.7.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants