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

Fix RO sync: clear LRU for all log updates #399

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- Lock files are now opened with O_CLOEXEC flag (#394, @vect0r-vicall)
- Update to cmdliner.1.1.0 (#382, @MisterDA)
- Mirage support: optional dependency to unix (#396, @art-w)
- Fix RO sync: clear LRU for all log updates (#399, @art-w)

# 1.6.2 (2023-06-06)

Expand Down
2 changes: 1 addition & 1 deletion bench/dune
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
(preprocess
(pps ppx_repr))
(libraries index index.unix unix cmdliner logs repr ppx_repr common
tezos-base58 optint fmt rusage mtime mtime.clock.os digestif))
digestif.ocaml tezos-base58 optint fmt rusage mtime mtime.clock.os))

;; Require the above executables to compile during tests

Expand Down
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
4 changes: 4 additions & 0 deletions test/issues/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
(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")