use fsync to force persisting the meta file. (#573)

* use fsync to force persisting the meta file.

Signed-off-by: Krasi Georgiev <kgeorgie@redhat.com>
This commit is contained in:
Krasi Georgiev 2019-04-01 16:23:45 +03:00 committed by GitHub
parent aed16621c0
commit e46ec89de6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 0 deletions

View file

@ -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)

View file

@ -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
}