Skip to content

Commit 733fd7f

Browse files
anna-tranNaman-B-Parlecha
authored andcommitted
Force sync writes to meta.json in case of host crash (thanos-io#8282)
* Force sync writes to meta.json in case of host crash Signed-off-by: Anna Tran <trananna@amazon.com> * Update CHANGELOG for fsync meta.json Signed-off-by: Anna Tran <trananna@amazon.com> --------- Signed-off-by: Anna Tran <trananna@amazon.com>
1 parent c48db15 commit 733fd7f

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ We use *breaking :warning:* to mark changes that are not backward compatible (re
1212
- [#8190](https://github.com/thanos-io/thanos/pull/8190) Fix markdown formatting in CHANGELOG.
1313
- [#8202](https://github.com/thanos-io/thanos/pull/8202) Receive: Unhide `--tsdb.enable-native-histograms` flag
1414
- [#8225](https://github.com/thanos-io/thanos/pull/8225) tools: Extend bucket ls options.
15+
- [#8282](https://github.com/thanos-io/thanos/pull/8282) Force sync writes to meta.json in case of host crash
1516

1617
### Added
1718

pkg/block/metadata/meta.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,11 @@ func (m Meta) WriteToDir(logger log.Logger, dir string) error {
209209
runutil.CloseWithLogOnErr(logger, f, "close meta")
210210
return err
211211
}
212+
213+
// Force the kernel to persist the file on disk to avoid data loss if the host crashes.
214+
if err := f.Sync(); err != nil {
215+
return err
216+
}
212217
if err := f.Close(); err != nil {
213218
return err
214219
}

pkg/shipper/shipper.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,11 @@ func WriteMetaFile(logger log.Logger, path string, meta *Meta) error {
467467
runutil.CloseWithLogOnErr(logger, f, "write meta file close")
468468
return err
469469
}
470+
471+
// Force the kernel to persist the file on disk to avoid data loss if the host crashes.
472+
if err := f.Sync(); err != nil {
473+
return err
474+
}
470475
if err := f.Close(); err != nil {
471476
return err
472477
}

0 commit comments

Comments
 (0)