fix merr logic.

Signed-off-by: Krasi Georgiev <kgeorgie@redhat.com>
This commit is contained in:
Krasi Georgiev 2019-02-06 16:31:02 +02:00
parent 08e7bc8ee8
commit 776769377e
1 changed files with 4 additions and 2 deletions

View File

@ -487,9 +487,10 @@ func (c *LeveledCompactor) write(dest string, meta *BlockMeta, blocks ...BlockRe
dir := filepath.Join(dest, meta.ULID.String())
tmp := dir + ".tmp"
var writers []io.Closer
var merr MultiError
defer func(t time.Time) {
var merr MultiError
merr.Add(err)
err = merr.Err()
for _, w := range writers {
merr.Add(w.Close())
}
@ -498,7 +499,7 @@ func (c *LeveledCompactor) write(dest string, meta *BlockMeta, blocks ...BlockRe
if err := os.RemoveAll(tmp); err != nil {
level.Error(c.logger).Log("msg", "removed tmp folder after failed compaction", "err", err.Error())
}
if merr.Err() != nil {
if err != nil {
c.metrics.failed.Inc()
}
c.metrics.ran.Inc()
@ -552,6 +553,7 @@ func (c *LeveledCompactor) write(dest string, meta *BlockMeta, blocks ...BlockRe
// though these are covered under defer. This is because in Windows,
// you cannot delete these unless they are closed and the defer is to
// make sure they are closed if the function exits due to an error above.
var merr MultiError
for _, w := range writers {
merr.Add(w.Close())
}