-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
distsql: clean the memory usage of MemTracker when a query ends (#10893) #10898
Conversation
/run-all-tests |
/run-unit-test |
/run-all-tests |
Codecov Report
@@ Coverage Diff @@
## master #10898 +/- ##
===========================================
Coverage 80.9333% 80.9333%
===========================================
Files 418 418
Lines 89245 89245
===========================================
Hits 72229 72229
Misses 11786 11786
Partials 5230 5230 |
/run-all-tests |
1 similar comment
/run-all-tests |
/rebuild |
@@ -106,17 +106,21 @@ func (r *selectResult) fetch(ctx context.Context) { | |||
return |
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.
Should we check in here?
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.
Yes, we should. Per https://godoc.org/github.com/pingcap/tidb/kv#Response, resultSubset may be nil even if no error take place.
// Next returns a resultSubset from a single storage unit.
// When full result set is returned, nil is returned.
Next(ctx context.Context) (resultSubset ResultSubset, err error)
I will add a comment here.
distsql/select_result.go
Outdated
@@ -231,16 +234,31 @@ func (r *selectResult) readRowsData(chk *chunk.Chunk) (err error) { | |||
} | |||
} | |||
r.selectResp.Chunks[r.respChkIdx].RowsData = rowsData | |||
r.memConsume(-int64(originMemory - r.selectResp.Size())) |
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.
r.memConsume(int64(r.selectResp.Size() - originMemory))
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 prefer to directly to use -
, it indicates a memory releasing.
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.
By the way, Maybe we should not reduce the used memory size. because the underlying buffer is still referenced by rowsData
, the memory is actually not changed.
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.
You're right. I'll try to implement it in another way.
} | ||
|
||
select { | ||
case r.results <- result: | ||
case <-r.closed: | ||
// If selectResult called Close() already, make fetch goroutine exit. | ||
if resultSubset != nil { |
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.
no need to check nil
again
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.
if line 102 occurs error, resultSubset
would be nil
.
distsql/select_result.go
Outdated
r.selectResp = new(tipb.SelectResponse) | ||
err := r.selectResp.Unmarshal(re.result.GetData()) | ||
if err != nil { | ||
return errors.Trace(err) | ||
} | ||
if r.memTracker != nil && r.selectResp != nil { | ||
r.memTracker.Consume(int64(r.selectResp.Size())) | ||
if r.selectResp != nil { |
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.
it's guaranteed to be not nil
in line 176.
distsql/select_result.go
Outdated
@@ -231,16 +234,31 @@ func (r *selectResult) readRowsData(chk *chunk.Chunk) (err error) { | |||
} | |||
} | |||
r.selectResp.Chunks[r.respChkIdx].RowsData = rowsData | |||
r.memConsume(-int64(originMemory - r.selectResp.Size())) |
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.
By the way, Maybe we should not reduce the used memory size. because the underlying buffer is still referenced by rowsData
, the memory is actually not changed.
/run-all-tests |
@zz-jason @crazycs520 PTAL again. Thanks. |
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.
LGTM
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.
LGTM
What problem does this PR solve?
closes #10893
What is changed and how it works?
Correctly release memory consuming in distsql.
Check List
Tests
run a select query like
select * from t, ta
Code changes
Side effects
Related changes