Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
[SPARK-26917][SQL] Further reduce locks in CacheManager #24028
[SPARK-26917][SQL] Further reduce locks in CacheManager #24028
Changes from all commits
22bd4bd
9219c01
771d12d
0277891
0971a06
697796e
375ee6a
fc7487b
27ab9f0
1d6f84a
a5977f0
1de029c
755d484
032c606
d402533
1d693af
1bb2511
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
we'd better add some comments to explain the access pattern of
cachedData
. e.g. adding/removing elements should be done by creating a new seq, and locked by 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.
can we remove the
readLock
method?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.
I think we can remove
writeLock
as well, and simply usethis.synchronized
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.
I made this change, but while doing that I realized there was an issue with the earlier change to the "partition" function. See comment below
val (plansToUncache, remainingPlans) = cachedData.partition(cd => shouldRemove(cd.plan))
// If a new plan is cached by a different thread at this point, it will be in the cachedData object,
// but not in plansToUncache or remainingPlans. So the next line will remove it.
writeLock {
cachedData = remainingPlans
}
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.
So I reverted this back to the previous behavior.
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.
I talked with @maropu. Since write to a
volatile
reference is atomic, I think that we could removethis.sychronization
if we would allow this operationcachedData.filterNot(cd => needToRecache.exists(_ eq cd))
to run on multiple threads.Since the performance bottleneck was in read lock, I do not recommend to apply this change very soon.
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 write itself is atomic, but you need the this.synchronized to ensure that the value you are writing is using the most up to date value of cachedData. The value is read as part of cachedData.filterNot, and you need to make sure cachedData doesn't change between the time when it is read and when it is written.