Skip to content

Commit

Permalink
Merge pull request #196 from samoht/flush-after-clear
Browse files Browse the repository at this point in the history
always fsync after a clear
  • Loading branch information
samoht authored Jul 12, 2020
2 parents c1bb147 + 5134d3c commit 2d6fb0b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/unix/index_unix.ml
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ module IO : Index.IO = struct
t.flushed <- t.header;
Header.set_header t { offset = t.offset; generation };
Raw.Fan.set t.raw "";
Buffer.clear t.buf
Buffer.clear t.buf;
Raw.fsync t.raw

let buffers = Hashtbl.create 256

Expand Down
28 changes: 23 additions & 5 deletions test/unix/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -242,16 +242,34 @@ module Readonly = struct
Index.close rw

let readonly_clear () =
let check_no_index_entry index k =
Alcotest.check_raises (Fmt.strf "Find %s key after clearing." k) Not_found
(fun () -> ignore_value (Index.find index k))
in
let Context.{ rw; tbl; clone } = Context.full_index () in
let ro = clone ~readonly:true () in
check_equivalence ro tbl;
Index.clear rw;
Index.sync ro;
Hashtbl.iter
(fun k _ ->
Alcotest.check_raises (Printf.sprintf "Found %s key after clearing." k)
Not_found (fun () -> ignore_value (Index.find ro k)))
tbl;
Hashtbl.iter (fun k _ -> check_no_index_entry ro k) tbl;
Index.close rw;
Index.close ro;
let rw = clone ~readonly:false () in
let ro = clone ~readonly:true () in
let k, v = (Key.v (), Value.v ()) in
Index.replace rw k v;
check_index_entry rw k v;
check_no_index_entry ro k;
Index.flush rw;
Index.sync ro;
check_index_entry rw k v;
check_index_entry ro k v;
Index.clear rw;
check_no_index_entry rw k;
check_index_entry ro k v;
Index.sync ro;
check_no_index_entry rw k;
check_no_index_entry ro k;
Index.close rw;
Index.close ro

Expand Down

0 comments on commit 2d6fb0b

Please sign in to comment.