mirror of https://github.com/prometheus/prometheus
Write meta.json file atomically
parent
6c4217276f
commit
2c3b56350a
9
block.go
9
block.go
|
@ -94,7 +94,11 @@ func readMetaFile(dir string) (*BlockMeta, error) {
|
|||
}
|
||||
|
||||
func writeMetaFile(dir string, meta *BlockMeta) error {
|
||||
f, err := os.Create(filepath.Join(dir, metaFilename))
|
||||
// Make any changes to the file appear atomic.
|
||||
path := filepath.Join(dir, metaFilename)
|
||||
tmp := path + ".tmp"
|
||||
|
||||
f, err := os.Create(tmp)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -108,8 +112,7 @@ func writeMetaFile(dir string, meta *BlockMeta) error {
|
|||
if err := f.Close(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
return renameFile(tmp, path)
|
||||
}
|
||||
|
||||
func newPersistedBlock(dir string) (*persistedBlock, error) {
|
||||
|
|
|
@ -406,7 +406,7 @@ func (c *compactionMerger) At() (labels.Labels, []ChunkMeta) {
|
|||
return c.l, c.c
|
||||
}
|
||||
|
||||
func renameDir(from, to string) error {
|
||||
func renameFile(from, to string) error {
|
||||
if err := os.RemoveAll(to); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue