Skip to content

Commit

Permalink
Fix RO sync: clear LRU for all log updates
Browse files Browse the repository at this point in the history
  • Loading branch information
art-w committed May 24, 2024
1 parent 09ab315 commit 2ddfbee
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/index.ml
Original file line number Diff line number Diff line change
Expand Up @@ -310,12 +310,14 @@ struct
Log_file.close log;
(* check that file is on disk, reopen and reload everything. *)
hook `Reload_log_async;
Lru.clear t.lru;
t.log_async <- try_load_log t (Layout.log_async ~root:t.root)
(* else if the disk offset is greater, reload the newest data. *))
else if old_offset < h.offset then
else if old_offset < h.offset then (
Lru.clear t.lru;
Log_file.sync_entries ~min:old_offset log
(* else if the offset is lesser, that means the [log_async] was
cleared, and the generation should have changed. *)
cleared, and the generation should have changed. *))
else if old_offset > h.offset then (
(* Should never occur, but we can recover by reloading the log from
scratch rather than just hard failing. *)
Expand Down Expand Up @@ -397,6 +399,7 @@ struct
Log.debug (fun l ->
l "[%s] new entries detected, reading log from disk"
(Filename.basename t.root));
Lru.clear t.lru;
Log_file.sync_entries ~min:log_offset log)
else
(* Here the disk offset should be equal to the known one. A smaller
Expand Down
1 change: 1 addition & 0 deletions test/issues/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(test (name issue398) (modules issue398) (libraries index index.unix))
23 changes: 23 additions & 0 deletions test/issues/issue398.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
(* See https://github.com/mirage/index/issues/398 *)

module L = struct
let length = 4
end

module I =
Index_unix.Make
(Index.Key.String_fixed (L)) (Index.Value.String_fixed (L))
(Index.Cache.Noop)

let () =
let path = "issue398.index" in
let t = I.v path ~log_size:16384 in
let ro = I.v path ~readonly:true ~log_size:16384 in
I.replace t "1234" "aaaa";
I.flush t;
I.sync ro;
assert (I.find ro "1234" = "aaaa");
I.replace t "1234" "aaab";
I.flush t;
I.sync ro;
assert (I.find ro "1234" = "aaab")

0 comments on commit 2ddfbee

Please sign in to comment.