diff --git a/CHANGELOG.md b/CHANGELOG.md index 51858f3cb..80f502304 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ - [REMOVED] `chunks.NewReader` is removed as it wasn't used anywhere. - [REMOVED] `FromData` is considered unused so was removed. - [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. ## 0.6.1 - [BUGFIX] Update `last` after appending a non-overlapping chunk in `chunks.MergeOverlappingChunks`. [#539](https://github.com/prometheus/tsdb/pull/539) diff --git a/block.go b/block.go index 2d9c81df9..e08503b64 100644 --- a/block.go +++ b/block.go @@ -251,6 +251,11 @@ func writeMetaFile(dir string, meta *BlockMeta) error { merr.Add(f.Close()) return merr.Err() } + // Force the kernel to persist the file on disk to avoid data loss if the host crashes. + if merr.Add(f.Sync()); merr.Err() != nil { + merr.Add(f.Close()) + return merr.Err() + } if err := f.Close(); err != nil { return err }