Skip to content

Commit

Permalink
fix memory leak in flushAObjsForSnapshot (#17123)
Browse files Browse the repository at this point in the history
fix memory leak in flushAObjsForSnapshot when error occurs.

Approved by: @XuPeng-SH, @sukki37
  • Loading branch information
w-zr authored Jun 24, 2024
1 parent 6c22c35 commit 847f8a8
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions pkg/vm/engine/tae/tables/jobs/flushTableTail.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,12 +288,12 @@ func (task *flushTableTailTask) Execute(ctx context.Context) (err error) {
inst := time.Now()
snapshotSubtasks, err := task.flushAObjsForSnapshot(ctx)
statFlushAobj := time.Since(inst)
if err != nil {
return
}
defer func() {
releaseFlushObjTasks(snapshotSubtasks, err)
}()
if err != nil {
return
}

/////////////////////
//// phase seperator
Expand Down Expand Up @@ -621,11 +621,6 @@ func (task *flushTableTailTask) mergeAObjs(ctx context.Context) (err error) {

// flushAObjsForSnapshot schedule io task to flush aobjects for snapshot read. this function will not release any data in io task
func (task *flushTableTailTask) flushAObjsForSnapshot(ctx context.Context) (subtasks []*flushObjTask, err error) {
defer func() {
if err != nil {
releaseFlushObjTasks(subtasks, err)
}
}()
subtasks = make([]*flushObjTask, len(task.aObjMetas))
// fire flush task
for i, obj := range task.aObjMetas {
Expand All @@ -647,13 +642,16 @@ func (task *flushTableTailTask) flushAObjsForSnapshot(ctx context.Context) (subt
if deletes, _, err = objData.CollectDeleteInRange(
ctx, types.TS{}, task.txn.GetStartTS(), true, common.MergeAllocator,
); err != nil {
data.Close()
return
}
if deletes != nil {
// make sure every batch in deltaloc object is sorted by rowid
_, err := mergesort.SortBlockColumns(deletes.Vecs, 0, task.rt.VectorPool.Transient)
_, err = mergesort.SortBlockColumns(deletes.Vecs, 0, task.rt.VectorPool.Transient)
if err != nil {
return nil, err
data.Close()
deletes.Close()
return
}
}

Expand Down

0 comments on commit 847f8a8

Please sign in to comment.