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 {
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -108,8 +112,7 @@ func writeMetaFile(dir string, meta *BlockMeta) error {
|
||||||
if err := f.Close(); err != nil {
|
if err := f.Close(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
return renameFile(tmp, path)
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func newPersistedBlock(dir string) (*persistedBlock, error) {
|
func newPersistedBlock(dir string) (*persistedBlock, error) {
|
||||||
|
|
|
@ -406,7 +406,7 @@ func (c *compactionMerger) At() (labels.Labels, []ChunkMeta) {
|
||||||
return c.l, c.c
|
return c.l, c.c
|
||||||
}
|
}
|
||||||
|
|
||||||
func renameDir(from, to string) error {
|
func renameFile(from, to string) error {
|
||||||
if err := os.RemoveAll(to); err != nil {
|
if err := os.RemoveAll(to); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue