Skip to content

Commit

Permalink
fix: ensure TSMBatchKeyIterator and FileStore close all TSMReaders (#…
Browse files Browse the repository at this point in the history
…24957) (#24964)

Do not let errors on closing
a TSMReader prevent other
closes.

(cherry picked from commit 82cbdb5)

closes #24961
  • Loading branch information
davidby-influx authored May 6, 2024
1 parent 73f694a commit 0a4d41b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
10 changes: 5 additions & 5 deletions tsdb/engine/tsm1/compact.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ package tsm1

import (
"bytes"
"errors"
"fmt"
"io"
"math"
Expand Down Expand Up @@ -1630,15 +1631,14 @@ func (k *tsmBatchKeyIterator) Close() error {
k.values = nil
k.pos = nil
k.iterators = nil
var errSlice []error
for _, r := range k.readers {
if err := r.Close(); err != nil {
return err
}
errSlice = append(errSlice, r.Close())
}
return nil
return errors.Join(errSlice...)
}

// Error returns any errors encountered during iteration.
// Err error returns any errors encountered during iteration.
func (k *tsmBatchKeyIterator) Err() error {
if len(k.errs) == 0 {
return nil
Expand Down
10 changes: 4 additions & 6 deletions tsdb/engine/tsm1/file_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -679,14 +679,12 @@ func (f *FileStore) Close() error {
// Let other methods access this closed object while we do the actual closing.
f.mu.Unlock()

for _, file := range files {
err := file.Close()
if err != nil {
return err
}
var errSlice []error
for _, tsmFile := range files {
errSlice = append(errSlice, tsmFile.Close())
}

return nil
return errors.Join(errSlice...)
}

func (f *FileStore) DiskSizeBytes() int64 {
Expand Down

0 comments on commit 0a4d41b

Please sign in to comment.