Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use fsync to flush metadata when reoperning a file with new headers #308

Merged
merged 1 commit into from
Apr 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
progress: the `log_async` file was not cached properly and fully reloaded
from disk every time. (#310)

- Added fsync after `Index.clear` to signal more quickly to read-only instances
than something has changed in the file (#308)

## Changed

- Specialise `IO.v` to create read-only or read-write instances. (#291)
Expand Down
13 changes: 7 additions & 6 deletions src/unix/index_unix.ml
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ module IO : Index.IO = struct
m "[%s] raw set_header %a" file Header.pp { offset; generation });
Raw.Header.set raw header;
Raw.Fan.set raw "";
Raw.fsync raw;
raw

let clear ~generation ?(hook = fun () -> ()) ~reopen t =
Expand Down Expand Up @@ -202,23 +203,23 @@ module IO : Index.IO = struct
let v ?flush_callback ~fresh ~generation ~fan_size file =
let v = v_instance ?flush_callback ~readonly:false file in
mkdir (Filename.dirname file);
let header =
{ Raw.Header.offset = Int63.zero; version = current_version; generation }
in
match Sys.file_exists file with
| false ->
let x = Unix.openfile file Unix.[ O_CREAT; O_CLOEXEC; O_RDWR ] 0o644 in
let raw = Raw.v x in
Raw.Offset.set raw Int63.zero;
Raw.Header.set raw header;
Raw.Fan.set_size raw fan_size;
Raw.Version.set raw current_version;
Raw.Generation.set raw generation;
v ~fan_size ~offset:Int63.zero raw
| true ->
let x = Unix.openfile file Unix.[ O_EXCL; O_CLOEXEC; O_RDWR ] 0o644 in
let raw = Raw.v x in
if fresh then (
Raw.Offset.set raw Int63.zero;
Raw.Header.set raw header;
Raw.Fan.set_size raw fan_size;
Raw.Version.set raw current_version;
Raw.Generation.set raw generation;
Raw.fsync raw;
v ~fan_size ~offset:Int63.zero raw)
else
let version = Raw.Version.get raw in
Expand Down