fix: Do not close connection twice in DigestWithOptions (#21659) (#21662)

tsm1.DigestWithOptions closes its network connection
twice. This may cause broken pipe errors on concurrent
invocations of the same procedure, by closing a reused
i/o descriptor. This fix also captures errors from TSM
file closures, which were previously ignored.

Closes https://github.com/influxdata/influxdb/issues/21656

(cherry picked from commit bce6553459)

Closes https://github.com/influxdata/influxdb/issues/21660
pull/21653/head^2
davidby-influx 2021-06-10 13:32:36 -07:00 committed by GitHub
parent 23547fe746
commit 5251c85412
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 4 deletions

View File

@ -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. [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. [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] ## v2.0.7 [2021-06-04]

View File

@ -22,7 +22,7 @@ type DigestOptions struct {
// DigestWithOptions writes a digest of dir to w using options to filter by // DigestWithOptions writes a digest of dir to w using options to filter by
// time and key range. // 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) manifest, err := NewDigestManifest(dir, files)
if err != nil { if err != nil {
return err return err
@ -31,7 +31,9 @@ func DigestWithOptions(dir string, files []string, opts DigestOptions, w io.Writ
tsmFiles := make([]TSMFile, 0, len(files)) tsmFiles := make([]TSMFile, 0, len(files))
defer func() { defer func() {
for _, r := range tsmFiles { 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 { if err != nil {
return err return err
} }
defer dw.Close() defer func() {
if e := dw.Close(); e != nil && err == nil {
err = e
}
}()
// Write the manifest. // Write the manifest.
if err := dw.WriteManifest(manifest); err != nil { 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 err
} }
} }
return dw.Close() return nil
} }
// Digest writes a digest of dir to w of a full shard dir. // Digest writes a digest of dir to w of a full shard dir.