Skip to content

Commit

Permalink
Remove domain_manager reference
Browse files Browse the repository at this point in the history
  • Loading branch information
clecat committed Jan 31, 2024
1 parent f7b52c3 commit 2d24f9e
Show file tree
Hide file tree
Showing 29 changed files with 372 additions and 340 deletions.
14 changes: 7 additions & 7 deletions bench/irmin-pack/trace_replay.ml
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,8 @@ module Make (Store : Store) = struct
let really_add_volume = time_to_add_volume in
(really_wait_gc, really_start_gc, really_split, really_add_volume)

let add_commits config repo commit_seq on_commit on_end stats check_hash
empty_blobs =
let add_commits ~domain_mgr config repo commit_seq on_commit on_end stats
check_hash empty_blobs =
let max_ncommits = config.number_of_commits_to_replay in
with_progress_bar ~message:"Replaying trace" ~n:max_ncommits ~unit:"commit"
@@ fun prog ->
Expand Down Expand Up @@ -444,7 +444,7 @@ module Make (Store : Store) = struct
commit_duration duration finalise_duration]
| Error s -> failwith s
in
Store.gc_run ~finished repo gc_commit_key)
Store.gc_run ~domain_mgr ~finished repo gc_commit_key)
in
let () = add_operations t repo ops i stats check_hash empty_blobs in
t.latest_commit_idx <- i;
Expand All @@ -465,8 +465,8 @@ module Make (Store : Store) = struct
in
aux commit_seq 0

let run : type a. _ -> a config -> a =
fun ext_config config ->
let run : type a. domain_mgr:_ Eio.Domain_manager.t -> _ -> a config -> a =
fun ~domain_mgr ext_config config ->
let check_hash =
config.path_conversion = `None
&& config.inode_config = (32, 256)
Expand Down Expand Up @@ -503,8 +503,8 @@ module Make (Store : Store) = struct
Fun.protect
(fun () ->
let block_count =
add_commits config repo commit_seq on_commit on_end stats check_hash
config.empty_blobs
add_commits ~domain_mgr config repo commit_seq on_commit on_end stats
check_hash config.empty_blobs
in
[%logs.app "Closing repo..."];
let () = Store.Repo.close repo in
Expand Down
9 changes: 7 additions & 2 deletions bench/irmin-pack/trace_replay_intf.ml
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,11 @@ module type Store = sig
type stats := Irmin_pack_unix.Stats.Latest_gc.stats

val gc_run :
?finished:((stats, string) result -> unit) -> repo -> commit_key -> unit
domain_mgr:_ Eio.Domain_manager.t ->
?finished:((stats, string) result -> unit) ->
repo ->
commit_key ->
unit
end

module type Sigs = sig
Expand All @@ -129,6 +133,7 @@ module type Sigs = sig
with type 'a return_type = 'a return_type
and type 'a config = 'a config

val run : Store.store_config -> 'a config -> 'a
val run :
domain_mgr:_ Eio.Domain_manager.t -> Store.store_config -> 'a config -> 'a
end
end
40 changes: 24 additions & 16 deletions bench/irmin-pack/tree.ml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ module type Store = sig
val add_volume : repo -> unit

val gc_run :
?finished:((stats, string) result -> unit) -> repo -> commit_key -> unit
domain_mgr:_ Eio.Domain_manager.t ->
?finished:((stats, string) result -> unit) ->
repo ->
commit_key ->
unit

val gc_wait : repo -> unit
end
Expand Down Expand Up @@ -168,7 +172,7 @@ module Bench_suite (Store : Store) = struct
config.ncommits config.nchain_trees config.depth Benchmark.pp_results
result

let run_read_trace config =
let run_read_trace ~domain_mgr config =
let replay_config : _ Irmin_traces.Trace_replay.config =
{
number_of_commits_to_replay = config.number_of_commits_to_replay;
Expand All @@ -190,11 +194,12 @@ module Bench_suite (Store : Store) = struct
in
if config.no_summary then
let () =
Trace_replay.run config { replay_config with return_type = Unit }
Trace_replay.run ~domain_mgr config
{ replay_config with return_type = Unit }
in
fun _ppf -> ()
else
let summary = Trace_replay.run config replay_config in
let summary = Trace_replay.run ~domain_mgr config replay_config in
fun ppf ->
if not config.no_summary then (
let p = Filename.concat config.artefacts_path "stat_summary.json" in
Expand Down Expand Up @@ -231,7 +236,7 @@ module Make_store_mem (Conf : Irmin_pack.Conf.S) = struct
let split _repo = ()
let add_volume _repo = ()
let gc_wait _repo = ()
let gc_run ?finished:_ _repo _key = ()
let gc_run ~domain_mgr:_ ?finished:_ _repo _key = ()
end

module Make_store_pack (Conf : Irmin_pack.Conf.S) = struct
Expand Down Expand Up @@ -270,13 +275,13 @@ module Make_store_pack (Conf : Irmin_pack.Conf.S) = struct
let r = Store.Gc.wait repo in
match r with Ok _ -> () | Error (`Msg err) -> failwith err

let gc_run ?(finished = fun _ -> ()) repo key =
let gc_run ~domain_mgr ?(finished = fun _ -> ()) repo key =
let f (result : (_, Store.Gc.msg) result) =
match result with
| Error (`Msg err) -> finished @@ Error err
| Ok stats -> finished @@ Ok stats
in
let launched = Store.Gc.run ~finished:f repo key in
let launched = Store.Gc.run ~domain_mgr ~finished:f repo key in
match launched with
| Ok true -> ()
| Ok false -> [%logs.app "GC skipped"]
Expand All @@ -286,7 +291,9 @@ end
module type B = sig
val run_large : config -> Format.formatter -> unit
val run_chains : config -> Format.formatter -> unit
val run_read_trace : config -> Format.formatter -> unit
val run_read_trace :
domain_mgr:_ Eio.Domain_manager.t -> config -> Format.formatter -> unit
end
let store_of_config config =
Expand All @@ -307,7 +314,7 @@ type suite_elt = {
run : config -> Format.formatter -> unit;
}
let suite : suite_elt list =
let suite ~domain_mgr : suite_elt list =
List.rev
[
{
Expand All @@ -319,7 +326,7 @@ let suite : suite_elt list =
{ config with inode_config = (32, 256); store_type = `Pack }
in
let (module Store) = store_of_config config in
Store.run_read_trace config);
Store.run_read_trace ~domain_mgr config);
};
{
mode = `Read_trace;
Expand All @@ -330,7 +337,7 @@ let suite : suite_elt list =
{ config with inode_config = (32, 256); store_type = `Pack }
in
let (module Store) = store_of_config config in
Store.run_read_trace config);
Store.run_read_trace ~domain_mgr config);
};
{
mode = `Chains;
Expand Down Expand Up @@ -382,11 +389,11 @@ let suite : suite_elt list =
run =
(fun config ->
let (module Store) = store_of_config config in
Store.run_read_trace config);
Store.run_read_trace ~domain_mgr config);
};
]
let get_suite suite_filter =
let get_suite ~domain_mgr suite_filter =
List.filter
(fun { mode; speed; _ } ->
match (suite_filter, speed, mode) with
Expand All @@ -403,7 +410,7 @@ let get_suite suite_filter =
| (`Slow | `Quick | `Custom_trace | `Custom_chains | `Custom_large), _, _
->
false)
suite
(suite ~domain_mgr)
let main () ncommits number_of_commits_to_replay suite_filter inode_config
store_type freeze_commit path_conversion depth width nchain_trees
Expand Down Expand Up @@ -445,10 +452,11 @@ let main () ncommits number_of_commits_to_replay suite_filter inode_config
results. *)
Gc.set { (Gc.get ()) with Gc.allocation_policy = 0 };
FSHelper.rm_dir config.store_dir;
let suite = get_suite suite_filter in
Eio_main.run @@ fun env ->
let domain_mgr = Eio.Stdenv.domain_mgr env in
let suite = get_suite ~domain_mgr suite_filter in
let run_benchmarks () = List.map (fun b -> b.run config) suite in
let results =
Eio_main.run @@ fun _env ->
Fun.protect run_benchmarks ~finally:(fun () ->
if keep_store then (
[%logs.app "Store kept at %s" config.store_dir];
Expand Down
15 changes: 9 additions & 6 deletions examples/irmin-pack/gc.ml
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ end

(** Demonstrate running GC on a previous commit aligned to the end of a chunk
for ideal GC space reclamation. *)
let run_gc config repo tracker =
let run_gc domain_mgr config repo tracker =
let () =
match Tracker.(tracker.next_gc_commit) with
| None -> ()
Expand All @@ -148,7 +148,7 @@ let run_gc config repo tracker =
in
(* Launch GC *)
let commit_key = Store.Commit.key commit in
let launched = Store.Gc.run ~finished repo commit_key in
let launched = Store.Gc.run ~domain_mgr ~finished repo commit_key in
match launched with
| Ok false -> ()
| Ok true ->
Expand All @@ -160,7 +160,7 @@ let run_gc config repo tracker =
let () = Store.split repo in
Tracker.mark_next_gc_commit tracker

let run_experiment config =
let run_experiment domain_mgr config =
Eio.Switch.run @@ fun sw ->
let num_of_commits = 200_000 in
let gc_every = 1_000 in
Expand All @@ -177,7 +177,9 @@ let run_experiment config =
Store.Commit.v repo ~info:(info "add %s = %s" key value) ~parents tree
in
Tracker.update_latest_commit tracker commit;
let _ = if i mod gc_every = 0 then run_gc config repo tracker in
let _ =
if i mod gc_every = 0 then run_gc domain_mgr config repo tracker
in
if i >= n then () else loop (i + 1) n
in
loop 1 num_of_commits
Expand All @@ -188,8 +190,9 @@ let run_experiment config =

let () =
Eio_main.run @@ fun env ->
let domain_mgr = Eio.Stdenv.domain_mgr env in
Irmin_pack_unix.Io.set_env (Eio.Stdenv.fs env);
Printf.printf "== RUN 1: deleting discarded data ==\n";
run_experiment Repo_config.config;
run_experiment domain_mgr Repo_config.config;
Printf.printf "== RUN 2: archiving discarded data ==\n";
run_experiment Repo_config.config_with_lower
run_experiment domain_mgr Repo_config.config_with_lower
3 changes: 2 additions & 1 deletion src/irmin-pack/io/async_intf.ml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ module type S = sig

type status = [ outcome | `Running ] [@@deriving irmin]

val async : sw:Eio.Switch.t -> (unit -> unit) -> t
val async :
sw:Eio.Switch.t -> domain_mgr:_ Eio.Domain_manager.t -> (unit -> unit) -> t
(** Start a task. *)

val await : t -> [> outcome ]
Expand Down
6 changes: 3 additions & 3 deletions src/irmin-pack/io/gc.ml
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ module Make (Args : Gc_args.S) = struct
latest_gc_target_offset : int63;
}

let v ~sw ~root ~lower_root ~output ~generation ~unlink ~dispatcher ~fm
~contents ~node ~commit commit_key =
let v ~sw ~domain_mgr ~root ~lower_root ~output ~generation ~unlink
~dispatcher ~fm ~contents ~node ~commit commit_key =
let open Result_syntax in
let new_suffix_start_offset, latest_gc_target_offset =
let state : _ Pack_key.state = Pack_key.inspect commit_key in
Expand Down Expand Up @@ -112,7 +112,7 @@ module Make (Args : Gc_args.S) = struct
(* let promise, resolver = Eio.Promise.create () in *)
(* start worker task *)
let task =
Async.async ~sw (fun () ->
Async.async ~sw ~domain_mgr (fun () ->
Worker.run_and_output_result root commit_key new_suffix_start_offset
~lower_root ~generation ~new_files_path)
in
Expand Down
1 change: 1 addition & 0 deletions src/irmin-pack/io/gc.mli
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ module Make

val v :
sw:Eio.Switch.t ->
domain_mgr:_ Eio.Domain_manager.t ->
root:string ->
lower_root:string option ->
output:[ `External of string | `Root ] ->
Expand Down
35 changes: 19 additions & 16 deletions src/irmin-pack/io/store.ml
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,8 @@ struct
(Irmin.Type.to_string XKey.t key))
| Some (k, _kind) -> Ok k)

let start ~unlink ~use_auto_finalisation ~output t commit_key =
let start ~domain_mgr ~unlink ~use_auto_finalisation ~output t
commit_key =
let open Result_syntax in
[%log.info "GC: Starting on %a" pp_key commit_key];
let* () =
Expand All @@ -272,22 +273,24 @@ struct
let next_generation = current_generation + 1 in
let lower_root = Conf.lower_root t.config in
let* gc =
Gc.v ~sw:t.sw ~root ~lower_root ~generation:next_generation
~unlink ~dispatcher:t.dispatcher ~fm:t.fm ~contents:t.contents
~node:t.node ~commit:t.commit ~output commit_key
Gc.v ~sw:t.sw ~domain_mgr ~root ~lower_root
~generation:next_generation ~unlink ~dispatcher:t.dispatcher
~fm:t.fm ~contents:t.contents ~node:t.node ~commit:t.commit
~output commit_key
in
Atomic.set t.running_gc (Some { gc; use_auto_finalisation });
Ok ()

let start_exn ?(unlink = true) ?(output = `Root)
let start_exn ~domain_mgr ?(unlink = true) ?(output = `Root)
~use_auto_finalisation t commit_key =
match Atomic.get t.running_gc with
| Some _ ->
[%log.info "Repo is alreadying running GC. Skipping."];
false
| None -> (
let result =
start ~unlink ~use_auto_finalisation ~output t commit_key
start ~domain_mgr ~unlink ~use_auto_finalisation ~output t
commit_key
in
match result with Ok _ -> true | Error e -> Errs.raise_error e)

Expand Down Expand Up @@ -353,7 +356,7 @@ struct
let key = Pack_key.v_direct ~offset ~length entry.hash in
Some key)

let create_one_commit_store t commit_key path =
let create_one_commit_store ~domain_mgr t commit_key path =
let () =
match Io.classify_path path with
| `Directory -> ()
Expand All @@ -367,8 +370,8 @@ struct
(* The GC action here does not matter, since we'll not fully
finalise it *)
let launched =
start_exn ~use_auto_finalisation:false ~output:(`External path) t
commit_key
start_exn ~domain_mgr ~use_auto_finalisation:false
~output:(`External path) t commit_key
in
let () =
if not launched then Errs.raise_error `Forbidden_during_gc
Expand Down Expand Up @@ -635,14 +638,14 @@ struct

let finalise_exn = X.Repo.Gc.finalise_exn

let start_exn ?unlink t =
X.Repo.Gc.start_exn ?unlink ~use_auto_finalisation:false t
let start_exn ~domain_mgr ?unlink t =
X.Repo.Gc.start_exn ~domain_mgr ?unlink ~use_auto_finalisation:false t

let start repo commit_key =
let start ~domain_mgr repo commit_key =
try
let started =
X.Repo.Gc.start_exn ~unlink:true ~use_auto_finalisation:true repo
commit_key
X.Repo.Gc.start_exn ~domain_mgr ~unlink:true
~use_auto_finalisation:true repo commit_key
in
Ok started
with exn -> catch_errors "Start GC" exn
Expand All @@ -660,8 +663,8 @@ struct
| `Finalised stats -> Ok (Some stats)
with exn -> catch_errors "Wait for GC" exn

let run ?(finished = fun _ -> ()) repo commit_key =
let started = start repo commit_key in
let run ~domain_mgr ?(finished = fun _ -> ()) repo commit_key =
let started = start ~domain_mgr repo commit_key in
match started with
| Ok r ->
if r then
Expand Down
Loading

0 comments on commit 2d24f9e

Please sign in to comment.