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

util: Change the name of ListInDisk #47777

Merged
merged 2 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/executor/aggregate/agg_hash_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ type HashAggExec struct {

// listInDisk is the chunks to store row values for spilled data.
// The HashAggExec may be set to `spill mode` multiple times, and all spilled data will be appended to ListInDisk.
listInDisk *chunk.ListInDisk
listInDisk *chunk.DataInDiskByRows
// numOfSpilledChks indicates the number of all the spilled chunks.
numOfSpilledChks int
// offsetOfSpilledChks indicates the offset of the chunk be read from the disk.
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/chunk/row_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (

type rowContainerRecord struct {
inMemory *List
inDisk *ListInDisk
inDisk *DataInDiskByRows
// spillError stores the error when spilling.
spillError error
}
Expand Down
31 changes: 16 additions & 15 deletions pkg/util/chunk/disk.go → pkg/util/chunk/row_in_disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ import (
"github.com/pingcap/tidb/pkg/util/memory"
)

// ListInDisk represents a slice of chunks storing in temporary disk.
type ListInDisk struct {
// DataInDiskByRows represents some data stored in temporary disk.
// These data are stored in row format, so they can only be restored by rows.
type DataInDiskByRows struct {
fieldTypes []*types.FieldType
numRowsOfEachChunk []int
rowNumOfEachChunkFirstRow []int
Expand Down Expand Up @@ -101,16 +102,16 @@ var defaultChunkListInDiskPath = "chunk.ListInDisk"
var defaultChunkListInDiskOffsetPath = "chunk.ListInDiskOffset"

// NewListInDisk creates a new ListInDisk with field types.
func NewListInDisk(fieldTypes []*types.FieldType) *ListInDisk {
l := &ListInDisk{
func NewListInDisk(fieldTypes []*types.FieldType) *DataInDiskByRows {
l := &DataInDiskByRows{
fieldTypes: fieldTypes,
// TODO(fengliyuan): set the quota of disk usage.
diskTracker: disk.NewTracker(memory.LabelForChunkListInDisk, -1),
}
return l
}

func (l *ListInDisk) initDiskFile() (err error) {
func (l *DataInDiskByRows) initDiskFile() (err error) {
err = disk.CheckAndInitTempDir()
if err != nil {
return
Expand All @@ -124,19 +125,19 @@ func (l *ListInDisk) initDiskFile() (err error) {
}

// Len returns the number of rows in ListInDisk
func (l *ListInDisk) Len() int {
func (l *DataInDiskByRows) Len() int {
return l.totalNumRows
}

// GetDiskTracker returns the memory tracker of this List.
func (l *ListInDisk) GetDiskTracker() *disk.Tracker {
func (l *DataInDiskByRows) GetDiskTracker() *disk.Tracker {
return l.diskTracker
}

// Add adds a chunk to the ListInDisk. Caller must make sure the input chk
// is not empty and not used any more and has the same field types.
// Warning: Do not use Add concurrently.
func (l *ListInDisk) Add(chk *Chunk) (err error) {
func (l *DataInDiskByRows) Add(chk *Chunk) (err error) {
if chk.NumRows() == 0 {
return errors2.New("chunk appended to List should have at least 1 row")
}
Expand Down Expand Up @@ -170,7 +171,7 @@ func (l *ListInDisk) Add(chk *Chunk) (err error) {
}

// GetChunk gets a Chunk from the ListInDisk by chkIdx.
func (l *ListInDisk) GetChunk(chkIdx int) (*Chunk, error) {
func (l *DataInDiskByRows) GetChunk(chkIdx int) (*Chunk, error) {
chk := NewChunkWithCapacity(l.fieldTypes, l.NumRowsOfChunk(chkIdx))
chkSize := l.numRowsOfEachChunk[chkIdx]

Expand Down Expand Up @@ -207,13 +208,13 @@ func (l *ListInDisk) GetChunk(chkIdx int) (*Chunk, error) {
}

// GetRow gets a Row from the ListInDisk by RowPtr.
func (l *ListInDisk) GetRow(ptr RowPtr) (row Row, err error) {
func (l *DataInDiskByRows) GetRow(ptr RowPtr) (row Row, err error) {
row, _, err = l.GetRowAndAppendToChunk(ptr, nil)
return row, err
}

// GetRowAndAppendToChunk gets a Row from the ListInDisk by RowPtr. Return the Row and the Ref Chunk.
func (l *ListInDisk) GetRowAndAppendToChunk(ptr RowPtr, chk *Chunk) (row Row, _ *Chunk, err error) {
func (l *DataInDiskByRows) GetRowAndAppendToChunk(ptr RowPtr, chk *Chunk) (row Row, _ *Chunk, err error) {
off, err := l.getOffset(ptr.ChkIdx, ptr.RowIdx)
if err != nil {
return
Expand All @@ -228,7 +229,7 @@ func (l *ListInDisk) GetRowAndAppendToChunk(ptr RowPtr, chk *Chunk) (row Row, _
return row, chk, err
}

func (l *ListInDisk) getOffset(chkIdx uint32, rowIdx uint32) (int64, error) {
func (l *DataInDiskByRows) getOffset(chkIdx uint32, rowIdx uint32) (int64, error) {
offsetInOffsetFile := l.rowNumOfEachChunkFirstRow[chkIdx] + int(rowIdx)
b := make([]byte, 8)
reader := l.offsetFile.getSectionReader(int64(offsetInOffsetFile) * 8)
Expand All @@ -243,17 +244,17 @@ func (l *ListInDisk) getOffset(chkIdx uint32, rowIdx uint32) (int64, error) {
}

// NumRowsOfChunk returns the number of rows of a chunk in the ListInDisk.
func (l *ListInDisk) NumRowsOfChunk(chkID int) int {
func (l *DataInDiskByRows) NumRowsOfChunk(chkID int) int {
return l.numRowsOfEachChunk[chkID]
}

// NumChunks returns the number of chunks in the ListInDisk.
func (l *ListInDisk) NumChunks() int {
func (l *DataInDiskByRows) NumChunks() int {
return len(l.numRowsOfEachChunk)
}

// Close releases the disk resource.
func (l *ListInDisk) Close() error {
func (l *DataInDiskByRows) Close() error {
if l.dataFile.disk != nil {
l.diskTracker.Consume(-l.diskTracker.BytesConsumed())
terror.Call(l.dataFile.disk.Close)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func BenchmarkListInDiskGetRow(b *testing.B) {
}

type listInDiskWriteDisk struct {
xzhangxian1008 marked this conversation as resolved.
Show resolved Hide resolved
ListInDisk
DataInDiskByRows
}

func (l *diskFileReaderWriter) flushForTest() (err error) {
Expand Down