Fix accounting for new/delete from different threads for VariableContext::Thread#16122
Closed
azat wants to merge 1 commit intoClickHouse:masterfrom
Closed
Fix accounting for new/delete from different threads for VariableContext::Thread#16122azat wants to merge 1 commit intoClickHouse:masterfrom
azat wants to merge 1 commit intoClickHouse:masterfrom
Conversation
…ext::Thread MemoryTracker assumes that for VariableContext::Thread new/delete may be called from different threads, hence the amount of memory can go negative. However the MemoryTracker is nested, so even if the negative amount is allowed for VariableContext::Thread it does not allowed for anything upper, and hence the MemoryTracking will not be decremented properly. Fix this, by looking at the initial level. This should fix memory drift for HTTP queries.
| } | ||
|
|
||
| if (level == VariableContext::Thread) | ||
| if (parent_level == VariableContext::Thread) |
Member
There was a problem hiding this comment.
Don't understand how initial level can be anything other than thread.
I assume that memory tracking always goes via DB::CurrentThread::getMemoryTracker()
It means we don't need this branch anymore...
Member
Author
There was a problem hiding this comment.
Hm, nice catch, Ok, this PR will be replaced with these two patches from #16121:
- 17dcdaef751e2eaa60e6f5ed63779dfdafc81eaf
- 52d247f828c2c297dd4e4539b1f0d0876a53be15
(I can't push them separately since they are required to fix MemoryTracking, otherwise I can't write a test for that PR)
alexey-milovidov
requested changes
Oct 21, 2020
Member
alexey-milovidov
left a comment
There was a problem hiding this comment.
Clarifications needed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Fix possible memory drift (due to new/delete from different threads)
Detailed description / Documentation draft:
MemoryTracker assumes that for VariableContext::Thread new/delete may be
called from different threads, hence the amount of memory can go
negative.
However the MemoryTracker is nested, so even if the negative amount is
allowed for VariableContext::Thread it does not allowed for anything
upper, and hence the MemoryTracking will not be decremented properly.
Fix this, by looking at the initial level.
Fixes: #15932 (This PR should fix memory drift for HTTP queries from that PR)
P.S. Marked as Improvement since backporting requirement is doubtful