Skip to content

Commit

Permalink
snapshot: release arrow readers after use (#602)
Browse files Browse the repository at this point in the history
This is good practice, and we're possibly retaining unnecessary memory here.
  • Loading branch information
asubiotto authored Nov 29, 2023
1 parent 2f06aa9 commit 19f82cb
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -634,17 +634,27 @@ func loadSnapshot(ctx context.Context, db *DB, r io.ReaderAt, size int64) ([]byt
}
resultParts = append(resultParts, parts.NewPart(partMeta.Tx, serBuf, partOptions))
case snapshotpb.Part_ENCODING_ARROW:
arrowReader, err := ipc.NewReader(bytes.NewReader(partBytes))
if err != nil {
return err
}

record, err := arrowReader.Read()
if err != nil {
if err := func() error {
arrowReader, err := ipc.NewReader(bytes.NewReader(partBytes))
if err != nil {
return err
}
defer arrowReader.Release()

record, err := arrowReader.Read()
if err != nil {
return err
}

record.Retain()
resultParts = append(
resultParts,
parts.NewArrowPart(partMeta.Tx, record, int(util.TotalRecordSize(record)), table.schema, partOptions),
)
return nil
}(); err != nil {
return err
}

resultParts = append(resultParts, parts.NewArrowPart(partMeta.Tx, record, int(util.TotalRecordSize(record)), table.schema, partOptions))
default:
return fmt.Errorf("unknown part encoding: %s", partMeta.Encoding)
}
Expand Down

0 comments on commit 19f82cb

Please sign in to comment.