Skip to content

Commit

Permalink
global sort: fix forget to close writer when reader has error (#51509)
Browse files Browse the repository at this point in the history
close #51508
  • Loading branch information
lance6716 authored Mar 5, 2024
1 parent 7c48d3b commit a5a3712
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions br/pkg/lightning/backend/external/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,18 @@ func mergeOverlappingFilesInternal(
if err != nil {
return nil
}
defer func() {
err2 := writer.Close(ctx)
if err2 == nil {
return
}

if err == nil {
err = err2
} else {
logutil.Logger(ctx).Warn("close writer failed", zap.Error(err2))
}
}()

// currently use same goroutine to do read and write. The main advantage is
// there's no KV copy and iter can reuse the buffer.
Expand All @@ -133,10 +145,5 @@ func mergeOverlappingFilesInternal(
return err
}
}
err = iter.Error()
if err != nil {
return err
}

return writer.Close(ctx)
return iter.Error()
}

0 comments on commit a5a3712

Please sign in to comment.