Skip to content
This repository was archived by the owner on Aug 13, 2019. It is now read-only.

Commit 6ad3d42

Browse files
committed
cleanup tmp meta file if file renaming failed
Signed-off-by: zhulongcheng <[email protected]>
1 parent 520b1d8 commit 6ad3d42

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

block.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"github.com/prometheus/tsdb/chunkenc"
3030
"github.com/prometheus/tsdb/chunks"
3131
tsdb_errors "github.com/prometheus/tsdb/errors"
32+
"github.com/prometheus/tsdb/fileutil"
3233
"github.com/prometheus/tsdb/index"
3334
"github.com/prometheus/tsdb/labels"
3435
)
@@ -259,7 +260,14 @@ func writeMetaFile(dir string, meta *BlockMeta) error {
259260
if err := f.Close(); err != nil {
260261
return err
261262
}
262-
return renameFile(tmp, path)
263+
264+
if err := fileutil.Rename(tmp, path); err != nil {
265+
merr.Add(err)
266+
merr.Add(os.RemoveAll(tmp))
267+
return merr.Err()
268+
}
269+
270+
return nil
263271
}
264272

265273
// Block represents a directory of time series data covering a continuous time range.

0 commit comments

Comments
 (0)