diff --git a/CHANGELOG.md b/CHANGELOG.md index 07a4d1ce668..ccbfc3c423b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,7 @@ This release adds an embedded SQLite database for storing metadata required by t 1. [21610](https://github.com/influxdata/influxdb/pull/21610): Avoid rewriting `fields.idx` unnecessarily. 1. [21648](https://github.com/influxdata/influxdb/pull/21648): Change static legend's `hide` to `show` to let users decide if they want it. +1. [21662](https://github.com/influxdata/influxdb/pull/21662): Do not close connection twice in DigestWithOptions ## v2.0.7 [2021-06-04] diff --git a/tsdb/engine/tsm1/digest.go b/tsdb/engine/tsm1/digest.go index c4613d0b48a..d66dc9fb343 100644 --- a/tsdb/engine/tsm1/digest.go +++ b/tsdb/engine/tsm1/digest.go @@ -22,7 +22,7 @@ type DigestOptions struct { // DigestWithOptions writes a digest of dir to w using options to filter by // time and key range. -func DigestWithOptions(dir string, files []string, opts DigestOptions, w io.WriteCloser) error { +func DigestWithOptions(dir string, files []string, opts DigestOptions, w io.WriteCloser) (err error) { manifest, err := NewDigestManifest(dir, files) if err != nil { return err @@ -31,7 +31,9 @@ func DigestWithOptions(dir string, files []string, opts DigestOptions, w io.Writ tsmFiles := make([]TSMFile, 0, len(files)) defer func() { for _, r := range tsmFiles { - r.Close() + if e := r.Close(); e != nil && err == nil { + err = e + } } }() @@ -54,7 +56,11 @@ func DigestWithOptions(dir string, files []string, opts DigestOptions, w io.Writ if err != nil { return err } - defer dw.Close() + defer func() { + if e := dw.Close(); e != nil && err == nil { + err = e + } + }() // Write the manifest. if err := dw.WriteManifest(manifest); err != nil { @@ -106,7 +112,7 @@ func DigestWithOptions(dir string, files []string, opts DigestOptions, w io.Writ return err } } - return dw.Close() + return nil } // Digest writes a digest of dir to w of a full shard dir.