Skip to content

Commit

Permalink
fix(v2): allocate dedicated buffer for tsdb
Browse files Browse the repository at this point in the history
  • Loading branch information
kolesnikovae committed Oct 17, 2024
1 parent e43348d commit c0f400f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
9 changes: 6 additions & 3 deletions pkg/experiment/query_backend/block/dataset.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,18 @@ func WithDatasetMaxSizeLoadInMemory(size int) DatasetOption {
// is only initialized once. While it is possible to open the dataset
// repeatedly after close, the caller must pass the failure reason to
// the CloseWithError call, preventing further use, if applicable.
func (s *Dataset) Open(ctx context.Context, sections ...Section) (err error) {
func (s *Dataset) Open(ctx context.Context, sections ...Section) error {
return s.refs.IncErr(func() error {
return s.open(ctx, sections...)
if err := s.open(ctx, sections...); err != nil {
return fmt.Errorf("%w (%s)", err, s.obj.meta.Id)
}
return nil
})
}

func (s *Dataset) open(ctx context.Context, sections ...Section) (err error) {
if s.err != nil {
// The tenant dataset has been already closed with an error.
// The tenant dataset has already been closed with an error.
return s.err
}
if err = s.obj.Open(ctx); err != nil {
Expand Down
8 changes: 5 additions & 3 deletions pkg/experiment/query_backend/block/section_tsdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,13 @@ type tsdbBuffer struct {
}

func (b *tsdbBuffer) Close() (err error) {
if b.buf != nil {
bufferpool.Put(b.buf)
}
if b.index != nil {
err = b.index.Close()
b.index = nil
}
if b.buf != nil {
bufferpool.Put(b.buf)
b.buf = nil
}
return err
}
3 changes: 3 additions & 0 deletions pkg/objstore/read_only_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ func download(ctx context.Context, name string, src BucketReader, dir string) (f
if err != nil {
return nil, err
}
defer func() {
_ = dst.Close()
}()
buf := bufferpool.GetBuffer(32 << 10)
defer bufferpool.Put(buf)
buf.B = buf.B[:cap(buf.B)]
Expand Down

0 comments on commit c0f400f

Please sign in to comment.