chunks: close all opened MmapFiles on NewDirReader error path (#575)

Signed-off-by: Pavel Borzenkov <pavel.borzenkov@gmail.com>
This commit is contained in:
Pavel Borzenkov 2019-04-02 15:16:29 +03:00 committed by Krasi Georgiev
parent e46ec89de6
commit 4f204dcbc1
2 changed files with 7 additions and 4 deletions

View File

@ -3,6 +3,7 @@
- [REMOVED] `FromData` is considered unused so was removed. - [REMOVED] `FromData` is considered unused so was removed.
- [FEATURE] Added option WALSegmentSize -1 to disable the WAL. - [FEATURE] Added option WALSegmentSize -1 to disable the WAL.
- [BUGFIX] Fsync the meta file to persist it on disk to avoid data loss in case of a host crash. - [BUGFIX] Fsync the meta file to persist it on disk to avoid data loss in case of a host crash.
- [BUGFIX] Fix fd and vm_area leak on error path in chunks.NewDirReader
## 0.6.1 ## 0.6.1
- [BUGFIX] Update `last` after appending a non-overlapping chunk in `chunks.MergeOverlappingChunks`. [#539](https://github.com/prometheus/tsdb/pull/539) - [BUGFIX] Update `last` after appending a non-overlapping chunk in `chunks.MergeOverlappingChunks`. [#539](https://github.com/prometheus/tsdb/pull/539)

View File

@ -408,13 +408,16 @@ func NewDirReader(dir string, pool chunkenc.Pool) (*Reader, error) {
} }
var ( var (
bs []ByteSlice bs []ByteSlice
cs []io.Closer cs []io.Closer
merr tsdb_errors.MultiError
) )
for _, fn := range files { for _, fn := range files {
f, err := fileutil.OpenMmapFile(fn) f, err := fileutil.OpenMmapFile(fn)
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "mmap files") merr.Add(errors.Wrap(err, "mmap files"))
merr.Add(closeAll(cs))
return nil, merr
} }
cs = append(cs, f) cs = append(cs, f)
bs = append(bs, realByteSlice(f.Bytes())) bs = append(bs, realByteSlice(f.Bytes()))
@ -422,7 +425,6 @@ func NewDirReader(dir string, pool chunkenc.Pool) (*Reader, error) {
reader, err := newReader(bs, cs, pool) reader, err := newReader(bs, cs, pool)
if err != nil { if err != nil {
var merr tsdb_errors.MultiError
merr.Add(err) merr.Add(err)
merr.Add(closeAll(cs)) merr.Add(closeAll(cs))
return nil, merr return nil, merr