Skip to content

Commit

Permalink
irmin-pack: modify auto flush callback behavior
Browse files Browse the repository at this point in the history
Instead of expecting the caller to flush, it now sends the results of a
flush to the callback.
  • Loading branch information
metanivek committed Sep 15, 2022
1 parent b72a868 commit 419ec01
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
6 changes: 4 additions & 2 deletions src/irmin-pack/unix/append_only_file.ml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ include Append_only_file_intf
module Make (Io : Io.S) = struct
module Io = Io

type auto_flush_callback = (unit, Io.write_error) result -> unit

type t = {
io : Io.t;
mutable persisted_end_offset : int63;
Expand All @@ -30,7 +32,7 @@ module Make (Io : Io.S) = struct
and rw_perm = {
buf : Buffer.t;
auto_flush_threshold : int;
auto_flush_callback : t -> unit;
auto_flush_callback : auto_flush_callback;
}
(** [rw_perm] contains the data necessary to operate in readwrite mode. *)

Expand Down Expand Up @@ -164,6 +166,6 @@ module Make (Io : Io.S) = struct
assert (Buffer.length rw_perm.buf < rw_perm.auto_flush_threshold);
Buffer.add_string rw_perm.buf s;
if Buffer.length rw_perm.buf >= rw_perm.auto_flush_threshold then (
rw_perm.auto_flush_callback t;
flush t |> rw_perm.auto_flush_callback;
assert (empty_buffer t))
end
9 changes: 5 additions & 4 deletions src/irmin-pack/unix/append_only_file_intf.ml
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ module type S = sig
module Io : Io.S

type t
type auto_flush_callback = (unit, Io.write_error) result -> unit

val create_rw :
path:string ->
overwrite:bool ->
auto_flush_threshold:int ->
auto_flush_callback:(t -> unit) ->
auto_flush_callback:auto_flush_callback ->
(t, [> Io.create_error ]) result
(** Create a rw instance of [t] by creating the file at [path]. *)

Expand All @@ -42,7 +43,7 @@ module type S = sig
end_offset:int63 ->
dead_header_size:int ->
auto_flush_threshold:int ->
auto_flush_callback:(t -> unit) ->
auto_flush_callback:auto_flush_callback ->
( t,
[> Io.open_error
| `Closed
Expand Down Expand Up @@ -76,8 +77,8 @@ module type S = sig
One of the goals of the [Append_only_file] abstraction is to provide
buffered appends. [auto_flush_threshold] is the soft cap after which the
buffer should be flushed. If a call to [append_exn] fills the buffer,
[auto_flush_callback] will be called so that the parent abstraction takes
care of the flush procedure, which is expected to call [flush]. *)
[auto_flush_callback] will be called with the result of the buffer being
flushed. *)

val open_ro :
path:string ->
Expand Down
6 changes: 3 additions & 3 deletions src/irmin-pack/unix/gc.ml
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ module Worker = struct

let create_new_suffix ~root ~generation =
let path = Irmin_pack.Layout.V3.suffix ~root ~generation in
let auto_flush_callback x = Ao.flush x |> Errs.raise_if_error in
let auto_flush_callback = Errs.raise_if_error in
Ao.create_rw_exn ~path ~auto_flush_callback

let run ~generation root commit_key =
Expand Down Expand Up @@ -233,7 +233,7 @@ module Worker = struct
(* Step 4. Create the new prefix. *)
let prefix =
let path = Irmin_pack.Layout.V3.prefix ~root ~generation in
let auto_flush_callback x = Ao.flush x |> Errs.raise_if_error in
let auto_flush_callback = Errs.raise_if_error in
Ao.create_rw_exn ~path ~auto_flush_callback
in
let () =
Expand Down Expand Up @@ -418,7 +418,7 @@ module Make (Args : Args) = struct
0. *)
let dead_header_size = 0 in
let auto_flush_threshold = 1_000_000 in
let auto_flush_callback x = Ao.flush x |> Errs.raise_if_error in
let auto_flush_callback = Errs.raise_if_error in
let* suffix =
Ao.open_rw ~path ~end_offset ~dead_header_size ~auto_flush_callback
~auto_flush_threshold
Expand Down
4 changes: 2 additions & 2 deletions src/irmin-pack/unix/mapping_file.ml
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ module Make (Io : Io.S) = struct
Io.unlink path2 |> ignore;

(* Create [file0] *)
let auto_flush_callback x = Ao.flush x |> Errs.raise_if_error in
let auto_flush_callback = Errs.raise_if_error in
let* file0 =
Ao.create_rw ~path:path0 ~overwrite:true ~auto_flush_threshold:1_000_000
~auto_flush_callback
Expand Down Expand Up @@ -404,7 +404,7 @@ module Make (Io : Io.S) = struct
Io.unlink path0 |> ignore;

(* Create [file2] *)
let auto_flush_callback x = Ao.flush x |> Errs.raise_if_error in
let auto_flush_callback = Errs.raise_if_error in
let* file2 =
Ao.create_rw ~path:path2 ~overwrite:true ~auto_flush_threshold:1_000_000
~auto_flush_callback
Expand Down

0 comments on commit 419ec01

Please sign in to comment.