From 6ac3343eb8a126f16b50f225972c9d56f21b897d Mon Sep 17 00:00:00 2001 From: davidby-influx <72418212+davidby-influx@users.noreply.github.com> Date: Mon, 6 May 2024 13:58:37 -0700 Subject: [PATCH] fix: ensure TSMBatchKeyIterator and FileStore close all TSMReaders (#24957) (#24964) (#24965) Do not let errors on closing a TSMReader prevent other closes. (cherry picked from commit 82cbdb5478af885c79a5a7dbe78c0297599bb616) closes https://github.com/influxdata/influxdb/issues/24961 (cherry picked from commit 0a4d41bc906450b2afc8137bef6ab60f08d3ba98) closes https://github.com/influxdata/influxdb/issues/24962 --- tsdb/engine/tsm1/compact.go | 10 +++++----- tsdb/engine/tsm1/file_store.go | 10 ++++------ 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/tsdb/engine/tsm1/compact.go b/tsdb/engine/tsm1/compact.go index 19520f9fb17..a2502ab10bc 100644 --- a/tsdb/engine/tsm1/compact.go +++ b/tsdb/engine/tsm1/compact.go @@ -14,6 +14,7 @@ package tsm1 import ( "bytes" + "errors" "fmt" "io" "math" @@ -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 diff --git a/tsdb/engine/tsm1/file_store.go b/tsdb/engine/tsm1/file_store.go index 765002422d6..148b7c15d10 100644 --- a/tsdb/engine/tsm1/file_store.go +++ b/tsdb/engine/tsm1/file_store.go @@ -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 {