-
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
util: support spill offset into disk when spilling #34212
util: support spill offset into disk when spilling #34212
Conversation
[REVIEW NOTIFICATION] This pull request has been approved by:
To complete the pull request process, please ask the reviewers in the list to review by filling The full list of commands accepted by this bot can be found here. Reviewer can indicate their review by submitting an approval review. |
Code Coverage Details: https://codecov.io/github/pingcap/tidb/commit/9239cf1d5a94e30e38924b1750a5b6982d015c9f |
c572458
to
0bb0cc5
Compare
util/chunk/disk.go
Outdated
offsetFile tempFileWithIOWrapper | ||
} | ||
|
||
type tempFileWithIOWrapper struct { |
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.
diskFileReaderWriter ?
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.
Add a comment for this definition
util/chunk/disk.go
Outdated
offWrite int64 | ||
fieldTypes []*types.FieldType | ||
numRowForEachChunk []int | ||
numRowPrefixSum []int |
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.
Add a comment for this
util/chunk/disk.go
Outdated
offWrite int64 | ||
fieldTypes []*types.FieldType | ||
numRowForEachChunk []int | ||
numRowPrefixSum []int | ||
|
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.
useless empty line
util/chunk/disk.go
Outdated
return underlying | ||
} | ||
|
||
func (l *tempFileWithIOWrapper) getSelectionReader(off int64) *io.SectionReader { |
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.
SectionReader
? not SelectionReader
util/chunk/disk.go
Outdated
return 0, err | ||
} | ||
if n != 8 { | ||
return 0, errors2.New("Can not get offset from disk") |
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 file spilled is broken, can not get data offset from the disk.
util/chunk/disk.go
Outdated
func (chk *chunkInDisk) getOffsetsOfRows() offsetsOfRows { return chk.offsetsOfRows } | ||
|
||
// WriteTo serializes the offsetsOfRow, and writes to w. | ||
func (off offsetsOfRows) WriteTo(w io.Writer) (written int64, err error) { |
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.
Put this function to line line262?
util/chunk/disk_test.go
Outdated
@@ -145,25 +143,47 @@ type listInDiskWriteDisk struct { | |||
ListInDisk | |||
} | |||
|
|||
func (l *tempFileWithIOWrapper) flushForTest() (err error) { |
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 seems flush
is not an appropriate name for now?
util/chunk/disk.go
Outdated
} | ||
|
||
type tempFileWithIOWrapper struct { | ||
// diskFileReaderWriter represents a Reader and a Writer for the temporary disk file, | ||
// without considering the detail of checksum and encryption. |
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.
cipherWriter is only enabled when ...
util/chunk/disk.go
Outdated
@@ -33,16 +33,17 @@ import ( | |||
type ListInDisk struct { | |||
fieldTypes []*types.FieldType | |||
numRowForEachChunk []int |
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.
numRowsOfEachChunk
rowNumOfEachChunkFirstRow
totalNumRows
/merge |
1 similar comment
/merge |
This pull request has been accepted and is ready to merge. Commit hash: b636337
|
1 similar comment
This pull request has been accepted and is ready to merge. Commit hash: b636337
|
/run-mysql-test |
/run-mysql-test |
TiDB MergeCI notify
|
What problem does this PR solve?
Issue Number: ref #33877
close #35634
Problem Summary:
What is changed and how it works?
Support spilling offsets of each row in ListInDisk, which reduces the memory usage for spilling.
Benchmark:
Heap Pprof: Sort 1e8 rows and spill. We can see the memory usage of chunkInDisk.WriteTo disappeared
Performance Test: Sort 1e8 rows and set memory quota to 1GB, tidb will spill data to disk. This pr will use more disk space.
Check List
Tests
Side effects
Documentation
Release note
Please refer to Release Notes Language Style Guide to write a quality release note.