diff --git a/bench/irmin-pack/trace_replay.ml b/bench/irmin-pack/trace_replay.ml index 761c20c038..602cb86fc3 100644 --- a/bench/irmin-pack/trace_replay.ml +++ b/bench/irmin-pack/trace_replay.ml @@ -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 -> @@ -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; @@ -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) @@ -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 diff --git a/bench/irmin-pack/trace_replay_intf.ml b/bench/irmin-pack/trace_replay_intf.ml index 57499d38b9..63b47af254 100644 --- a/bench/irmin-pack/trace_replay_intf.ml +++ b/bench/irmin-pack/trace_replay_intf.ml @@ -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 @@ -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 diff --git a/bench/irmin-pack/tree.ml b/bench/irmin-pack/tree.ml index ea4b594a24..bfa50ba3bf 100644 --- a/bench/irmin-pack/tree.ml +++ b/bench/irmin-pack/tree.ml @@ -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 @@ -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; @@ -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 @@ -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 @@ -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"] @@ -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 = @@ -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 [ { @@ -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; @@ -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; @@ -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 @@ -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 @@ -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]; diff --git a/examples/irmin-pack/gc.ml b/examples/irmin-pack/gc.ml index 3b8e8c969d..ad3d160e57 100644 --- a/examples/irmin-pack/gc.ml +++ b/examples/irmin-pack/gc.ml @@ -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 -> () @@ -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 -> @@ -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 @@ -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 @@ -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 diff --git a/src/irmin-pack/io/async_intf.ml b/src/irmin-pack/io/async_intf.ml index c59f1449ac..9b1def4089 100644 --- a/src/irmin-pack/io/async_intf.ml +++ b/src/irmin-pack/io/async_intf.ml @@ -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 ] diff --git a/src/irmin-pack/io/gc.ml b/src/irmin-pack/io/gc.ml index 4cbeacf8c1..eb76fb737a 100644 --- a/src/irmin-pack/io/gc.ml +++ b/src/irmin-pack/io/gc.ml @@ -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 @@ -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 diff --git a/src/irmin-pack/io/gc.mli b/src/irmin-pack/io/gc.mli index a543508d6b..32898538fc 100644 --- a/src/irmin-pack/io/gc.mli +++ b/src/irmin-pack/io/gc.mli @@ -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 ] -> diff --git a/src/irmin-pack/io/store.ml b/src/irmin-pack/io/store.ml index 51d713d5e8..8f487ad4d3 100644 --- a/src/irmin-pack/io/store.ml +++ b/src/irmin-pack/io/store.ml @@ -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* () = @@ -272,14 +273,15 @@ 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 _ -> @@ -287,7 +289,8 @@ struct 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) @@ -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 -> () @@ -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 @@ -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 @@ -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 diff --git a/src/irmin-pack/io/store_intf.ml b/src/irmin-pack/io/store_intf.ml index 3353a5e2cc..b93e1ade35 100644 --- a/src/irmin-pack/io/store_intf.ml +++ b/src/irmin-pack/io/store_intf.ml @@ -103,7 +103,8 @@ module type S = sig (** [flush t] flush read-write pack on disk. Raises [RO_Not_Allowed] if called by a readonly instance.*) - val create_one_commit_store : repo -> commit_key -> string -> unit + val create_one_commit_store : + domain_mgr:_ Eio.Domain_manager.t -> repo -> commit_key -> string -> unit (** [create_one_commit_store t key path] creates a new store at [path] from the existing one, containing only one commit, specified by the [key]. Note that this operation is blocking. @@ -121,7 +122,12 @@ module type S = sig (** {1 Low-level API} *) - val start_exn : ?unlink:bool -> repo -> commit_key -> bool + val start_exn : + domain_mgr:_ Eio.Domain_manager.t -> + ?unlink:bool -> + repo -> + commit_key -> + bool (** [start_exn] tries to start the GC process and returns true if the GC is launched. If a GC is already running, a new one is not started. @@ -159,6 +165,7 @@ module type S = sig logging *) val run : + domain_mgr:_ Eio.Domain_manager.t -> ?finished:((Stats.Latest_gc.stats, msg) result -> unit) -> repo -> commit_key -> diff --git a/src/irmin-pack/unix/async.ml b/src/irmin-pack/unix/async.ml index c1b2aa28f0..97497d4762 100644 --- a/src/irmin-pack/unix/async.ml +++ b/src/irmin-pack/unix/async.ml @@ -16,10 +16,6 @@ open! Irmin_pack_io.Import -let ref_domain_mgr = ref None -let set_domain_mgr t = ref_domain_mgr := Some t -let domain_mgr () = Option.get !ref_domain_mgr - module Unix = struct type outcome = [ `Success | `Cancelled | `Failure of string ] [@@deriving irmin] @@ -29,7 +25,7 @@ module Unix = struct type t = Eio.Switch.t * outcome Eio.Promise.or_exn - let async ~sw f = + let async ~sw ~domain_mgr f = let run f () = Logs.set_level None; match f () with @@ -42,7 +38,7 @@ module Unix = struct Eio.Fiber.fork_promise ~sw (fun () -> Eio.Switch.run @@ fun sw' -> Eio.Promise.resolve gc_sw_resolver sw'; - Eio.Domain_manager.run (domain_mgr ()) (run f)) + Eio.Domain_manager.run domain_mgr (run f)) in let gc_sw = Eio.Promise.await gc_sw_promise in (gc_sw, promise) diff --git a/src/irmin-pack/unix/async.mli b/src/irmin-pack/unix/async.mli index 148fd4cb76..796ae52765 100644 --- a/src/irmin-pack/unix/async.mli +++ b/src/irmin-pack/unix/async.mli @@ -15,5 +15,3 @@ *) module Unix : Irmin_pack_io.Async_intf.S - -val set_domain_mgr : Eio.Domain_manager.ty Eio.Resource.t -> unit diff --git a/test/irmin-bench/replay.ml b/test/irmin-bench/replay.ml index 06251746a1..088d82d45f 100644 --- a/test/irmin-bench/replay.ml +++ b/test/irmin-bench/replay.ml @@ -33,13 +33,13 @@ module Store = 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"] @@ -78,7 +78,7 @@ let setup_env () = ()); trace_path -let replay_1_commit () = +let replay_1_commit domain_mgr () = let trace_path = setup_env () in let replay_config : _ Replay.config = { @@ -98,7 +98,7 @@ let replay_1_commit () = add_volume_every = 0; } in - let summary = Replay.run () replay_config in + let summary = Replay.run ~domain_mgr () replay_config in [%logs.debug "%a" (Irmin_traces.Trace_stat_summary_pp.pp 5) ([ "" ], [ summary ])]; let check name = Alcotest.(check int) ("Stats_counters" ^ name) in @@ -144,12 +144,12 @@ module Store_mem = 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 Replay_mem = Irmin_traces.Trace_replay.Make (Store_mem) -let replay_1_commit_mem () = +let replay_1_commit_mem domain_mgr () = let trace_path = setup_env () in let replay_config : _ Irmin_traces.Trace_replay.config = { @@ -169,17 +169,17 @@ let replay_1_commit_mem () = add_volume_every = 0; } in - let summary = Replay_mem.run () replay_config in + let summary = Replay_mem.run ~domain_mgr () replay_config in [%logs.debug "%a" (Irmin_traces.Trace_stat_summary_pp.pp 5) ([ "" ], [ summary ])]; () -let test_cases = +let test_cases domain_mgr = let tc msg f = Alcotest.test_case msg `Quick f in [ ( "replay", [ - tc "replay_1_commit" replay_1_commit; - tc "replay_1_commit_in_memory" replay_1_commit_mem; + tc "replay_1_commit" (replay_1_commit domain_mgr); + tc "replay_1_commit_in_memory" (replay_1_commit_mem domain_mgr); ] ); ] diff --git a/test/irmin-bench/test.ml b/test/irmin-bench/test.ml index 0d09b93185..cff00b41ba 100644 --- a/test/irmin-bench/test.ml +++ b/test/irmin-bench/test.ml @@ -16,6 +16,7 @@ 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); Alcotest.run "irmin-bench" - (Ema.test_cases @ Misc.test_cases @ Replay.test_cases) + (Ema.test_cases @ Misc.test_cases @ Replay.test_cases domain_mgr) diff --git a/test/irmin-pack/test.ml b/test/irmin-pack/test.ml index 83756e07dd..14f60e1f02 100644 --- a/test/irmin-pack/test.ml +++ b/test/irmin-pack/test.ml @@ -16,9 +16,7 @@ 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); - Irmin_pack_unix.Async.set_domain_mgr domain_mgr; (* **/** *) let test_suite = Test_pack.suite in Irmin_test.Store.run "irmin-pack" diff --git a/test/irmin-pack/test_async.ml b/test/irmin-pack/test_async.ml index b3fda31471..eec0e46335 100644 --- a/test/irmin-pack/test_async.ml +++ b/test/irmin-pack/test_async.ml @@ -20,22 +20,23 @@ module Async = Irmin_pack_unix.Async.Unix let check_outcome = Alcotest.check_repr Async.outcome_t -let test_success () = +let test_success domain_mgr () = Eio.Switch.run @@ fun sw -> let f () = assert true in - let task = Async.async ~sw f in + let task = Async.async ~sw ~domain_mgr f in let result = Async.await task in check_outcome "should succeed" `Success result -let test_exception_in_task () = +let test_exception_in_task domain_mgr () = Eio.Switch.run @@ fun sw -> let f () = assert false in - let task = Async.async ~sw f in + let task = Async.async ~sw ~domain_mgr f in let result = Async.await task in check_outcome "should fail" (`Failure "Unhandled exception") result -let tests = +let tests domain_mgr = [ - Alcotest.test_case "Successful task" `Quick test_success; - Alcotest.test_case "Exception occurs in task" `Quick test_exception_in_task; + Alcotest.test_case "Successful task" `Quick (test_success domain_mgr); + Alcotest.test_case "Exception occurs in task" `Quick + (test_exception_in_task domain_mgr); ] diff --git a/test/irmin-pack/test_async.mli b/test/irmin-pack/test_async.mli index 57112a0179..c0fe6c21df 100644 --- a/test/irmin-pack/test_async.mli +++ b/test/irmin-pack/test_async.mli @@ -14,4 +14,4 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. *) -val tests : unit Alcotest.test_case list +val tests : _ Eio.Domain_manager.t -> unit Alcotest.test_case list diff --git a/test/irmin-pack/test_dispatcher.ml b/test/irmin-pack/test_dispatcher.ml index 8a9410cc38..4abea8d71f 100644 --- a/test/irmin-pack/test_dispatcher.ml +++ b/test/irmin-pack/test_dispatcher.ml @@ -24,7 +24,7 @@ let src = Logs.Src.create "tests.dispatcher" ~doc:"Test dispatcher" module Log = (val Logs.src_log src : Logs.LOG) -let setup_store () = +let setup_store domain_mgr () = rm_dir root; Eio.Switch.run @@ fun sw -> let config = S.config root in @@ -34,7 +34,7 @@ let setup_store () = let t = S.checkout_exn t c2 in let t, _c3 = S.commit_3 t in [%log.debug "Gc c1, keep c2, c3"]; - let () = S.start_gc t c2 in + let () = S.start_gc domain_mgr t c2 in let () = S.finalise_gc t in let () = S.close t in config @@ -76,9 +76,9 @@ let check_hex msg buf expected = msg expected (Bytes.to_string buf |> Hex.of_string |> Hex.show) -let test_read () = +let test_read domain_mgr () = Eio.Switch.run @@ fun sw -> - let config = setup_store () in + let config = setup_store domain_mgr () in let fm = File_manager.open_ro ~sw config |> Errs.raise_if_error in let dsp = Dispatcher.v fm |> Errs.raise_if_error in let _ = @@ -101,4 +101,5 @@ let test_read () = File_manager.close fm |> Errs.raise_if_error -let tests = [ Alcotest.test_case "read" `Quick test_read ] +let tests domain_mgr = + [ Alcotest.test_case "read" `Quick (test_read domain_mgr) ] diff --git a/test/irmin-pack/test_dispatcher.mli b/test/irmin-pack/test_dispatcher.mli index 2b40d2f891..c755c6e844 100644 --- a/test/irmin-pack/test_dispatcher.mli +++ b/test/irmin-pack/test_dispatcher.mli @@ -14,4 +14,4 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. *) -val tests : unit Alcotest.test_case list +val tests : _ Eio.Domain_manager.t -> unit Alcotest.test_case list diff --git a/test/irmin-pack/test_existing_stores.ml b/test/irmin-pack/test_existing_stores.ml index 83f3e07c44..915defabb8 100644 --- a/test/irmin-pack/test_existing_stores.ml +++ b/test/irmin-pack/test_existing_stores.ml @@ -309,7 +309,7 @@ module Test_traverse_gced = struct module S = V2 () include Test (S) - let commit_and_gc conf = + let commit_and_gc domain_mgr conf = Eio.Switch.run @@ fun sw -> let repo = S.Repo.v ~sw conf in let commit = @@ -319,7 +319,7 @@ module Test_traverse_gced = struct let tree = S.Tree.add tree [ "abba"; "baba" ] "x" in let commit = S.Commit.v repo ~info:S.Info.empty ~parents:[] tree in let commit_key = S.Commit.key commit in - let _launched = S.Gc.start_exn ~unlink:false repo commit_key in + let _ = S.Gc.start_exn ~domain_mgr ~unlink:false repo commit_key in let result = S.Gc.finalise_exn ~wait:true repo in let () = match result with @@ -329,7 +329,7 @@ module Test_traverse_gced = struct in S.Repo.close repo - let test_traverse_pack () = + let test_traverse_pack domain_mgr () = Eio.Switch.run @@ fun sw -> let module Kind = Irmin_pack.Pack_value.Kind in setup_test_env (); @@ -337,11 +337,11 @@ module Test_traverse_gced = struct config ~readonly:false ~fresh:false ~indexing_strategy:Irmin_pack.Indexing_strategy.minimal root_local_build in - let () = commit_and_gc conf in + let () = commit_and_gc domain_mgr conf in S.test_traverse_pack_file ~sw `Check_index conf end -let tests = +let tests domain_mgr = [ Alcotest.test_case "Test index reconstruction" `Quick Test_reconstruct.test_reconstruct; @@ -353,5 +353,5 @@ let tests = Alcotest.test_case "Test integrity check for inodes" `Quick Test_corrupted_inode.test; Alcotest.test_case "Test traverse pack on gced store" `Quick - Test_traverse_gced.test_traverse_pack; + (Test_traverse_gced.test_traverse_pack domain_mgr); ] diff --git a/test/irmin-pack/test_existing_stores.mli b/test/irmin-pack/test_existing_stores.mli index 2b40d2f891..c755c6e844 100644 --- a/test/irmin-pack/test_existing_stores.mli +++ b/test/irmin-pack/test_existing_stores.mli @@ -14,4 +14,4 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. *) -val tests : unit Alcotest.test_case list +val tests : _ Eio.Domain_manager.t -> unit Alcotest.test_case list diff --git a/test/irmin-pack/test_gc.ml b/test/irmin-pack/test_gc.ml index 39ca3e25bd..654c28b8ff 100644 --- a/test/irmin-pack/test_gc.ml +++ b/test/irmin-pack/test_gc.ml @@ -73,9 +73,9 @@ module Store = struct let info = S.Info.empty - let start_gc ?(unlink = false) t commit = + let start_gc domain_mgr ?(unlink = false) t commit = let commit_key = S.Commit.key commit in - let _launched = S.Gc.start_exn ~unlink t.repo commit_key in + let _ = S.Gc.start_exn ~domain_mgr ~unlink t.repo commit_key in () let finalise_gc_with_stats t = @@ -275,7 +275,7 @@ let rec check_async_unlinked ?(timeout = 3.141) file = module Gc_common (B : Gc_backend) = struct (** Check that gc preserves and deletes commits accordingly. *) - let one_gc () = + let one_gc domain_mgr () = (* c1 - c2 *) (* \---- c3 *) (* gc(c3) *) @@ -287,7 +287,7 @@ module Gc_common (B : Gc_backend) = struct let t = checkout_exn t c1 in let t, c3 = commit_3 t in [%log.debug "Gc c1, c2, keep c3"]; - let () = start_gc t c3 in + let () = start_gc domain_mgr t c3 in let () = finalise_gc t in let () = B.check_gced t c1 "gced c1" in let () = B.check_removed t c2 "gced c2" in @@ -295,7 +295,7 @@ module Gc_common (B : Gc_backend) = struct S.Repo.close t.repo (** Check that calling gc twice works. *) - let two_gc () = + let two_gc domain_mgr () = (* gc(c4) gc(c5) *) (* c1 - c2 --- c4 -------- c5 *) (* \---- c3 *) @@ -309,13 +309,13 @@ module Gc_common (B : Gc_backend) = struct let t = checkout_exn t c2 in let t, c4 = commit_4 t in [%log.debug "Gc c1, c2, c3, keep c4"]; - let () = start_gc t c4 in + let () = start_gc domain_mgr t c4 in let () = finalise_gc t in let t = checkout_exn t c4 in let t, c5 = commit_5 t in let () = check_5 t c5 in [%log.debug "Gc c4, keep c5"]; - let () = start_gc t c5 in + let () = start_gc domain_mgr t c5 in let () = finalise_gc t in let () = check_5 t c5 in let () = B.check_gced t c1 "gced c1" in @@ -325,7 +325,7 @@ module Gc_common (B : Gc_backend) = struct S.Repo.close t.repo (** Check that calling gc on first commit of chain keeps everything. *) - let gc_keeps_all () = + let gc_keeps_all domain_mgr () = (* c1 - c2 - c3 *) (* gc(c1) *) Eio.Switch.run @@ fun sw -> @@ -336,7 +336,7 @@ module Gc_common (B : Gc_backend) = struct let t = checkout_exn t c2 in let t, c3 = commit_3 t in [%log.debug "Keep c1, c2, c3"]; - let () = start_gc t c1 in + let () = start_gc domain_mgr t c1 in let () = finalise_gc t in let () = check_1 t c1 in let () = check_2 t c2 in @@ -344,7 +344,7 @@ module Gc_common (B : Gc_backend) = struct S.Repo.close t.repo (** Check that adding back gced commits works. *) - let gc_add_back () = + let gc_add_back domain_mgr () = (* c1 - c_del - c3 ------ c1 - c2 ------- c3 *) (* gc(c3) gc(c1) *) Eio.Switch.run @@ fun sw -> @@ -355,7 +355,7 @@ module Gc_common (B : Gc_backend) = struct let t = checkout_exn t c_del in let t, c3 = commit_3 t in [%log.debug "Gc c1, c_del, keep c3"]; - let () = start_gc t c3 in + let () = start_gc domain_mgr t c3 in let () = finalise_gc t in let () = B.check_gced t c1 "gced c1" in let () = B.check_gced t c_del "gced c_del" in @@ -369,7 +369,7 @@ module Gc_common (B : Gc_backend) = struct let t, c2 = commit_2 t in let () = check_2 t c2 in [%log.debug "Gc c3, keep c1, c2"]; - let () = start_gc t c1 in + let () = start_gc domain_mgr t c1 in let () = finalise_gc t in let () = B.check_gced t c3 "gced c3" in let () = check_2 t c2 in @@ -381,7 +381,7 @@ module Gc_common (B : Gc_backend) = struct S.Repo.close t.repo (** Check that gc and close work together. *) - let close () = + let close domain_mgr () = (* c1 ------ c2 *) (* gc(c1) gc(c2) *) (* close close close *) @@ -389,7 +389,7 @@ module Gc_common (B : Gc_backend) = struct let t = B.init ~sw () in let store_name = t.root in let t, c1 = commit_1 t in - let () = start_gc ~unlink:false t c1 in + let () = start_gc domain_mgr ~unlink:false t c1 in let () = finalise_gc t in let t = checkout_exn t c1 in let t, c2 = commit_2 t in @@ -417,7 +417,7 @@ module Gc_common (B : Gc_backend) = struct Eio.Switch.run @@ fun sw -> let t = B.init ~sw ~readonly:false ~fresh:false ~root:store_name () in [%log.debug "Gc c1, keep c2"]; - let () = start_gc ~unlink:true t c2 in + let () = start_gc domain_mgr ~unlink:true t c2 in let () = finalise_gc t in let () = S.Repo.close t.repo in Alcotest.(check bool) @@ -430,7 +430,7 @@ module Gc_common (B : Gc_backend) = struct S.Repo.close t.repo (** Check that gc works on a commit with two parents. *) - let gc_commit_with_two_parents () = + let gc_commit_with_two_parents domain_mgr () = (* gc(c3) *) (* c1 - c3 *) (* c2 -/ *) @@ -441,7 +441,7 @@ module Gc_common (B : Gc_backend) = struct let t, c2 = commit_2 t in let t = { t with parents = [ c1; c2 ] } in let t, c3 = commit_3 t in - let () = start_gc t c3 in + let () = start_gc domain_mgr t c3 in let () = finalise_gc t in let () = B.check_gced t c1 "gced c1" in let () = B.check_gced t c2 "gced c2" in @@ -449,7 +449,7 @@ module Gc_common (B : Gc_backend) = struct S.Repo.close t.repo (** Check that gc preserves and deletes commits from RO. *) - let gc_ro () = + let gc_ro domain_mgr () = (* c1 ---- c3 ------------------- c4 - c5 *) (* \- c2 *) (* gc(c3) gc(c4) *) @@ -464,7 +464,7 @@ module Gc_common (B : Gc_backend) = struct let t, c3 = commit_3 t in S.reload ro_t.repo; [%log.debug "Gc c1, c2, keeps c3"]; - let () = start_gc t c3 in + let () = start_gc domain_mgr t c3 in let () = finalise_gc t in [%log.debug "RO finds everything before reload"]; let () = check_1 ro_t c1 in @@ -481,7 +481,7 @@ module Gc_common (B : Gc_backend) = struct let t, c5 = commit_5 t in S.reload ro_t.repo; [%log.debug "Gc c3, keep c4, c5"]; - let () = start_gc t c4 in + let () = start_gc domain_mgr t c4 in let () = finalise_gc t in [%log.debug "RO finds c3, c4, c5 before reload"]; let () = check_3 ro_t c3 in @@ -496,7 +496,7 @@ module Gc_common (B : Gc_backend) = struct S.Repo.close ro_t.repo (** Check that RO works if reload is called after two gcs. *) - let ro_after_two_gc () = + let ro_after_two_gc domain_mgr () = (* c1 ------- c2 *) (* gc(c1) gc(c2) *) (* reload *) @@ -505,11 +505,11 @@ module Gc_common (B : Gc_backend) = struct let ro_t = B.init ~sw ~readonly:true ~fresh:false ~root:t.root () in let t, c1 = commit_1 t in S.reload ro_t.repo; - let () = start_gc t c1 in + let () = start_gc domain_mgr t c1 in let () = finalise_gc t in let t = checkout_exn t c1 in let t, c2 = commit_2 t in - let () = start_gc t c2 in + let () = start_gc domain_mgr t c2 in let () = finalise_gc t in [%log.debug "RO finds c1, but c2 gced before reload"]; let () = check_1 ro_t c1 in @@ -522,7 +522,7 @@ module Gc_common (B : Gc_backend) = struct S.Repo.close ro_t.repo (** Check that gc and close and ro work together. *) - let ro_close () = + let ro_close domain_mgr () = Eio.Switch.run @@ fun sw -> let t = B.init ~sw () in let ro_t = B.init ~sw ~readonly:true ~fresh:false ~root:t.root () in @@ -530,7 +530,7 @@ module Gc_common (B : Gc_backend) = struct let t = checkout_exn t c1 in let t, c2 = commit_2 t in let () = S.Repo.close ro_t.repo in - let () = start_gc t c2 in + let () = start_gc domain_mgr t c2 in let () = finalise_gc t in [%log.debug "RO reopens is similar to a reload"]; let ro_t = B.init ~sw ~readonly:true ~fresh:false ~root:t.root () in @@ -558,7 +558,7 @@ module Gc_common (B : Gc_backend) = struct (** Check that gc works when the lru caches some objects that are delete by consequent commits. See https://github.com/mirage/irmin/issues/1920. *) - let gc_lru () = + let gc_lru domain_mgr () = let check t c = S.Commit.of_key t.repo (S.Commit.key c) |> function | None -> Alcotest.fail "no hash found in repo" @@ -579,13 +579,13 @@ module Gc_common (B : Gc_backend) = struct let t = checkout_exn t c3 in let t = set t [ "a"; "b"; "e" ] "a" in let c4 = commit t in - let () = start_gc t c3 in + let () = start_gc domain_mgr t c3 in let () = finalise_gc t in let () = check t c4 in S.Repo.close t.repo (** Check that calling gc during a batch raises an error. *) - let gc_during_batch () = + let gc_during_batch domain_mgr () = Eio.Switch.run @@ fun sw -> let t = B.init ~sw () in let t, c1 = commit_1 t in @@ -594,13 +594,13 @@ module Gc_common (B : Gc_backend) = struct (Irmin_pack_unix.Errors.Pack_error `Gc_forbidden_during_batch) (fun () -> S.Backend.Repo.batch t.repo (fun _ _ _ -> - let () = start_gc t c1 in + let () = start_gc domain_mgr t c1 in finalise_gc t)) in S.Repo.close t.repo (** Add back commits after they were gced. *) - let add_back_gced_commit () = + let add_back_gced_commit domain_mgr () = (* c1 - c2 - c3 *) (* gc(c3) *) (* c1 - c2 *) @@ -612,7 +612,7 @@ module Gc_common (B : Gc_backend) = struct let t = checkout_exn t c2 in let t, c3 = commit_3 t in [%log.debug "Keep c3 gc c1 c2"]; - let () = start_gc t c3 in + let () = start_gc domain_mgr t c3 in let () = finalise_gc t in let () = B.check_gced t c1 "gced c1" in let () = B.check_gced t c2 "gced c2" in @@ -630,21 +630,21 @@ module Gc_common (B : Gc_backend) = struct let () = check_3 t c3 in S.Repo.close t.repo - let gc_similar_commits () = + let gc_similar_commits domain_mgr () = Eio.Switch.run @@ fun sw -> let t = B.init ~sw () in let t, c1 = commit_1 t in - let () = start_gc t c1 in + let () = start_gc domain_mgr t c1 in let () = finalise_gc t in let t = checkout_exn t c1 in let t, c1_again = commit_1_different_author t in - let () = start_gc t c1_again in + let () = start_gc domain_mgr t c1_again in let () = finalise_gc t in let () = check_1 t c1_again in S.Repo.close t.repo (** Check [Gc.latest_gc_target]. *) - let latest_gc_target () = + let latest_gc_target domain_mgr () = Eio.Switch.run @@ fun sw -> let t = B.init ~sw () in let check_latest_gc_target expected = @@ -661,18 +661,18 @@ module Gc_common (B : Gc_backend) = struct let t = checkout_exn t c1 in check_latest_gc_target None; let t, c2 = commit_2 t in - let () = start_gc t c2 in + let () = start_gc domain_mgr t c2 in let () = finalise_gc t in check_latest_gc_target (Some c2); let t = checkout_exn t c2 in let t, c3 = commit_3 t in - let () = start_gc t c3 in + let () = start_gc domain_mgr t c3 in let () = finalise_gc t in check_latest_gc_target (Some c3); S.Repo.close t.repo (** Check Gc stats. *) - let gc_stats () = + let gc_stats domain_mgr () = let check_stats (stats : Irmin_pack_unix.Stats.Latest_gc.stats) = let objects_traversed = stats.worker.objects_traversed |> Int63.to_int in Alcotest.(check int) "objects_traversed" objects_traversed 8; @@ -696,17 +696,17 @@ module Gc_common (B : Gc_backend) = struct let t, c1 = commit_1 t in let t = checkout_exn t c1 in let t, c2 = commit_2 t in - let () = start_gc t c2 in + let () = start_gc domain_mgr t c2 in let () = finalise_gc t in let t = checkout_exn t c2 in let t, c3 = commit_3 t in - let () = start_gc t c3 in + let () = start_gc domain_mgr t c3 in let stats = finalise_gc_with_stats t in check_stats (Option.get stats); S.Repo.close t.repo (** Check that a GC clears the LRU *) - let gc_clears_lru () = + let gc_clears_lru domain_mgr () = Eio.Switch.run @@ fun sw -> let t = init ~sw ~lru_size:100 () in (* Rreate some commits *) @@ -722,32 +722,33 @@ module Gc_common (B : Gc_backend) = struct (* TODO: Now that the GC is not in another process, it cleans every stats. Make the stats domain dependant ? *) (* let count_before_gc = lru_hits () in *) - let () = start_gc t c2 in + let () = start_gc domain_mgr t c2 in let () = finalise_gc t in (* Read data again *) let () = check_3 t c3 in Alcotest.(check int) "GC does clear LRU" 0 (lru_hits ()); S.Repo.close t.repo - let tests = + let tests domain_mgr = [ - tc "Test one gc" one_gc; - tc "Test twice gc" two_gc; - tc "Test gc keeps commits" gc_keeps_all; - tc "Test adding back commits" gc_add_back; - tc "Test close" close; - tc "Test gc commit with two parents" gc_commit_with_two_parents; - tc "Test gc ro" gc_ro; - tc "Test reload after two gc" ro_after_two_gc; - tc "Test ro close" ro_close; + tc "Test one gc" (one_gc domain_mgr); + tc "Test twice gc" (two_gc domain_mgr); + tc "Test gc keeps commits" (gc_keeps_all domain_mgr); + tc "Test adding back commits" (gc_add_back domain_mgr); + tc "Test close" (close domain_mgr); + tc "Test gc commit with two parents" + (gc_commit_with_two_parents domain_mgr); + tc "Test gc ro" (gc_ro domain_mgr); + tc "Test reload after two gc" (ro_after_two_gc domain_mgr); + tc "Test ro close" (ro_close domain_mgr); tc "Test ro reload after open" ro_reload_after_v; - tc "Test lru" gc_lru; - tc "Test gc during batch" gc_during_batch; - tc "Test add back gced commit" add_back_gced_commit; - tc "Test gc on similar commits" gc_similar_commits; - tc "Test oldest live commit" latest_gc_target; - tc "Test worker gc stats" gc_stats; - tc "Test gc_clears_lru" gc_clears_lru; + tc "Test lru" (gc_lru domain_mgr); + tc "Test gc during batch" (gc_during_batch domain_mgr); + tc "Test add back gced commit" (add_back_gced_commit domain_mgr); + tc "Test gc on similar commits" (gc_similar_commits domain_mgr); + tc "Test oldest live commit" (latest_gc_target domain_mgr); + tc "Test worker gc stats" (gc_stats domain_mgr); + tc "Test gc_clears_lru" (gc_clears_lru domain_mgr); ] end @@ -811,7 +812,7 @@ module Gc_archival = struct (S.Gc.is_allowed t.repo) false; S.Repo.close t.repo - let gc_reachability_old () = + let gc_reachability_old domain_mgr () = let root = create_v1_test_env () in let lower_root = create_lower_root () in [%log.debug "Open v1 store to trigger migration"]; @@ -829,7 +830,7 @@ module Gc_archival = struct true | _ -> assert false in - let () = start_gc t head in + let () = start_gc domain_mgr t head in let () = finalise_gc t in S.Repo.close t.repo @@ -846,7 +847,7 @@ module Gc_archival = struct let check_removed = check_not_found end - let gc_archival_multiple_volumes () = + let gc_archival_multiple_volumes domain_mgr () = Eio.Switch.run @@ fun sw -> let t = B.init ~sw () in let t, c1 = commit_1 t in @@ -857,7 +858,7 @@ module Gc_archival = struct let t = checkout_exn t c2 in let t, c4 = commit_4 t in [%log.debug "Gc c1, c2, c3, keep c4"]; - let () = start_gc t c4 in + let () = start_gc domain_mgr t c4 in let () = finalise_gc t in [%log.debug "Add a new volume"]; S.add_volume t.repo; @@ -865,7 +866,7 @@ module Gc_archival = struct let t, c5 = commit_5 t in let () = check_5 t c5 in [%log.debug "Gc c4, keep c5"]; - let () = start_gc t c5 in + let () = start_gc domain_mgr t c5 in let () = finalise_gc t in let () = check_5 t c5 in let () = B.check_gced t c1 "gced c1" in @@ -875,35 +876,35 @@ module Gc_archival = struct let () = Alcotest.check_raises_pack_error "Cannot GC on commit older than c5" (function `Gc_disallowed _ -> true | _ -> false) - (fun () -> start_gc t c4) + (fun () -> start_gc domain_mgr t c4) in S.Repo.close t.repo module Gc_common_tests = Gc_common (B) - let tests = + let tests domain_mgr = [ tc "Test availability of different gc modes on recent stores" gc_availability_recent; tc "Test availability of different gc modes on old stores" gc_availability_old; tc "Test archiving twice on different volumes" - gc_archival_multiple_volumes; - tc "Test reachability on old stores" gc_reachability_old; + (gc_archival_multiple_volumes domain_mgr); + tc "Test reachability on old stores" (gc_reachability_old domain_mgr); ] - @ Gc_common_tests.tests + @ Gc_common_tests.tests domain_mgr end module Concurrent_gc = struct (** Check that finding old objects during a gc works. *) - let find_running_gc ~lru_size () = + let find_running_gc domain_mgr ~lru_size () = Eio.Switch.run @@ fun sw -> let t = init ~sw ~lru_size () in let t, c1 = commit_1 t in let t = checkout_exn t c1 in let t, c2 = commit_2 t in [%log.debug "Gc c1 keep c2"]; - let () = start_gc t c2 in + let () = start_gc domain_mgr t c2 in let () = check_1 t c1 in let () = check_2 t c2 in let () = finalise_gc t in @@ -912,14 +913,14 @@ module Concurrent_gc = struct S.Repo.close t.repo (** Check adding new objects during a gc and finding them after the gc. *) - let add_running_gc ~lru_size () = + let add_running_gc domain_mgr ~lru_size () = Eio.Switch.run @@ fun sw -> let t = init ~sw ~lru_size () in let t, c1 = commit_1 t in let t = checkout_exn t c1 in let t, c2 = commit_2 t in [%log.debug "Gc c1 keep c2"]; - let () = start_gc t c2 in + let () = start_gc domain_mgr t c2 in let t = checkout_exn t c2 in let t, c3 = commit_3 t in let () = finalise_gc t in @@ -929,23 +930,23 @@ module Concurrent_gc = struct S.Repo.close t.repo (** Check adding new objects during a gc and finding them after the gc. *) - let several_gc ~lru_size () = + let several_gc domain_mgr ~lru_size () = Eio.Switch.run @@ fun sw -> let t = init ~sw ~lru_size () in let t, c1 = commit_1 t in - let () = start_gc t c1 in + let () = start_gc domain_mgr t c1 in let t = checkout_exn t c1 in let t, c2 = commit_2 t in let () = finalise_gc t in - let () = start_gc t c2 in + let () = start_gc domain_mgr t c2 in let t = checkout_exn t c2 in let t, c3 = commit_3 t in let () = finalise_gc t in - let () = start_gc t c3 in + let () = start_gc domain_mgr t c3 in let t = checkout_exn t c3 in let t, c4 = commit_4 t in let () = finalise_gc t in - let () = start_gc t c4 in + let () = start_gc domain_mgr t c4 in let t = checkout_exn t c4 in let t, c5 = commit_5 t in let () = finalise_gc t in @@ -965,7 +966,7 @@ module Concurrent_gc = struct (** Check that RO can find old objects during gc. Also that RO can still find removed objects before a call to [reload]. *) - let ro_find_running_gc () = + let ro_find_running_gc domain_mgr () = Eio.Switch.run @@ fun sw -> let t = init ~sw () in let ro_t = init ~sw ~readonly:true ~fresh:false ~root:t.root () in @@ -973,7 +974,7 @@ module Concurrent_gc = struct let t = checkout_exn t c1 in let t, c2 = commit_2 t in [%log.debug "Gc c1 keep c2"]; - let () = start_gc t c2 in + let () = start_gc domain_mgr t c2 in S.reload ro_t.repo; let () = check_1 ro_t c1 in S.reload ro_t.repo; @@ -989,7 +990,7 @@ module Concurrent_gc = struct (** Check that RO can find objects added during gc, but only after a call to [reload]. *) - let ro_add_running_gc () = + let ro_add_running_gc domain_mgr () = Eio.Switch.run @@ fun sw -> let t = init ~sw () in let ro_t = init ~sw ~readonly:true ~fresh:false ~root:t.root () in @@ -997,7 +998,7 @@ module Concurrent_gc = struct let t = checkout_exn t c1 in let t, c2 = commit_2 t in [%log.debug "Gc c1 keep c2"]; - let () = start_gc t c2 in + let () = start_gc domain_mgr t c2 in S.reload ro_t.repo; let t = checkout_exn t c2 in let t, c3 = commit_3 t in @@ -1017,7 +1018,7 @@ module Concurrent_gc = struct (** Check that RO can call [reload] during a second gc, even after no reloads occured during the first gc. *) - let ro_reload_after_second_gc () = + let ro_reload_after_second_gc domain_mgr () = Eio.Switch.run @@ fun sw -> let t = init ~sw () in let ro_t = init ~sw ~readonly:true ~fresh:false ~root:t.root () in @@ -1025,12 +1026,12 @@ module Concurrent_gc = struct let t = checkout_exn t c1 in let t, c2 = commit_2 t in [%log.debug "Gc c1 keep c2"]; - let () = start_gc t c2 in + let () = start_gc domain_mgr t c2 in let () = finalise_gc t in let t = checkout_exn t c2 in let t, c3 = commit_3 t in [%log.debug "Gc c2 keep c3"]; - let () = start_gc t c3 in + let () = start_gc domain_mgr t c3 in let () = finalise_gc t in S.reload ro_t.repo; let () = check_not_found ro_t c1 "removed c1" in @@ -1040,7 +1041,7 @@ module Concurrent_gc = struct S.Repo.close ro_t.repo (** Check that calling reload in RO will clear the LRU only after GC. *) - let ro_reload_clears_lru () = + let ro_reload_clears_lru domain_mgr () = Eio.Switch.run @@ fun sw -> let rw_t = init ~sw () in let ro_t = @@ -1064,7 +1065,7 @@ module Concurrent_gc = struct (count_before_reload < lru_hits ()); (* GC *) (* let count_before_gc = lru_hits () in *) - let () = start_gc rw_t c2 in + let () = start_gc domain_mgr rw_t c2 in let () = finalise_gc rw_t in (* Reload RO to get changes and clear LRU, and read some data *) S.reload ro_t.repo; @@ -1076,24 +1077,24 @@ module Concurrent_gc = struct (** Check that calling close during a gc kills the gc without finalising it. On reopening the store, the following gc works fine. *) - let close_running_gc () = + let close_running_gc domain_mgr () = Eio.Switch.run @@ fun sw -> let t = init ~sw () in let t, c1 = commit_1 t in - let () = start_gc t c1 in + let () = start_gc domain_mgr t c1 in let () = S.Repo.close t.repo in Eio.Switch.run @@ fun sw -> let t = init ~sw ~readonly:false ~fresh:false ~root:t.root () in let () = check_1 t c1 in let t = checkout_exn t c1 in let t, c2 = commit_2 t in - let () = start_gc t c2 in + let () = start_gc domain_mgr t c2 in let () = finalise_gc t in let t = checkout_exn t c2 in S.Repo.close t.repo (** Check that the cleanup routine in file manager deletes correct files. *) - let test_cancel_cleanup () = + let test_cancel_cleanup domain_mgr () = Eio.Switch.run @@ fun sw -> let t = init ~sw () in (* chunk 0, commit 1 *) @@ -1105,14 +1106,14 @@ module Concurrent_gc = struct let () = S.split t.repo in (* GC chunk 0 - important to have at least one GC to test the cleanup routine's usage of generation *) - let () = start_gc t c2 in + let () = start_gc domain_mgr t c2 in let () = finalise_gc t in (* chunk 2, commit 3 *) let t = checkout_exn t c2 in let t, c3 = commit_3 t in let () = S.split t.repo in (* Start GC and then close repo before finalise *) - let () = start_gc t c3 in + let () = start_gc domain_mgr t c3 in let () = S.Repo.close t.repo in (* Reopen store. If the cleanup on cancel deletes wrong files, the store will fail to open. *) @@ -1126,16 +1127,16 @@ module Concurrent_gc = struct S.Repo.close t.repo (** Check starting a gc before a previous is finalised. *) - let test_skip () = + let test_skip domain_mgr () = Eio.Switch.run @@ fun sw -> let t = init ~sw () in let t, c1 = commit_1 t in let t = checkout_exn t c1 in let t, c2 = commit_2 t in - let () = start_gc t c2 in + let () = start_gc domain_mgr t c2 in let t = checkout_exn t c2 in let t, c3 = commit_3 t in - let () = start_gc t c3 in + let () = start_gc domain_mgr t c3 in let () = finalise_gc t in let () = check_not_found t c1 "removed c1" in let () = check_2 t c2 in @@ -1147,11 +1148,11 @@ module Concurrent_gc = struct if S.Internal.kill_gc repo then true else Alcotest.failf "running_gc missing after call to start" - let test_kill_gc_and_finalise () = + let test_kill_gc_and_finalise domain_mgr () = Eio.Switch.run @@ fun sw -> let t = init ~sw () in let t, c1 = commit_1 t in - let () = start_gc t c1 in + let () = start_gc domain_mgr t c1 in let killed = kill_gc t in let () = if killed then @@ -1163,31 +1164,31 @@ module Concurrent_gc = struct in S.Repo.close t.repo - let test_kill_gc_and_close () = + let test_kill_gc_and_close domain_mgr () = Eio.Switch.run @@ fun sw -> let t = init ~sw () in let t, c1 = commit_1 t in - let () = start_gc t c1 in + let () = start_gc domain_mgr t c1 in let _killed = kill_gc t in S.Repo.close t.repo - let tests = + let tests domain_mgr = [ - tc "Test find_running_gc" find_running_gc; - tc "Test add_running_gc" add_running_gc; - tc "Test several_gc" several_gc; - tc "Test find_running_gc_with_lru" find_running_gc_with_lru; - tc "Test add_running_gc_with_lru" add_running_gc_with_lru; - tc "Test several_gc_with_lru" several_gc_with_lru; - tc "Test ro_find_running_gc" ro_find_running_gc; - tc "Test ro_add_running_gc" ro_add_running_gc; - tc "Test ro_reload_after_second_gc" ro_reload_after_second_gc; - tc "Test ro_reload_clears_lru" ro_reload_clears_lru; - tc "Test close_running_gc" close_running_gc; - tc "Test skip gc" test_skip; - tc "Test kill gc and finalise" test_kill_gc_and_finalise; - tc "Test kill gc and close" test_kill_gc_and_close; - tc "Test gc cancel cleanup" test_cancel_cleanup; + tc "Test find_running_gc" (find_running_gc domain_mgr); + tc "Test add_running_gc" (add_running_gc domain_mgr); + tc "Test several_gc" (several_gc domain_mgr); + tc "Test find_running_gc_with_lru" (find_running_gc_with_lru domain_mgr); + tc "Test add_running_gc_with_lru" (add_running_gc_with_lru domain_mgr); + tc "Test several_gc_with_lru" (several_gc_with_lru domain_mgr); + tc "Test ro_find_running_gc" (ro_find_running_gc domain_mgr); + tc "Test ro_add_running_gc" (ro_add_running_gc domain_mgr); + tc "Test ro_reload_after_second_gc" (ro_reload_after_second_gc domain_mgr); + tc "Test ro_reload_clears_lru" (ro_reload_clears_lru domain_mgr); + tc "Test close_running_gc" (close_running_gc domain_mgr); + tc "Test skip gc" (test_skip domain_mgr); + tc "Test kill gc and finalise" (test_kill_gc_and_finalise domain_mgr); + tc "Test kill gc and close" (test_kill_gc_and_close domain_mgr); + tc "Test gc cancel cleanup" (test_cancel_cleanup domain_mgr); ] end @@ -1252,7 +1253,7 @@ module Split = struct let got = S.Tree.find tree [ "step-n01"; "step-b01" ] in Alcotest.(check (option string)) "find blob" (Some "b01") got - let v3_migrated_store_splits_and_gc () = + let v3_migrated_store_splits_and_gc domain_mgr () = let root = create_test_env () in Eio.Switch.run @@ fun sw -> let t = init ~sw ~readonly:false ~fresh:false ~root () in @@ -1268,7 +1269,7 @@ module Split = struct let () = check_1 t c1 in let () = check_2 t c2 in [%log.debug "GC at c0"]; - let () = start_gc ~unlink:true t c0 in + let () = start_gc domain_mgr ~unlink:true t c0 in let () = finalise_gc t in let () = check_preexisting_commit t in let () = check_1 t c1 in @@ -1277,7 +1278,7 @@ module Split = struct "Chunk0 still exists" true (Sys.file_exists (Filename.concat t.root "store.0.suffix")); [%log.debug "GC at c1"]; - let () = start_gc ~unlink:true t c1 in + let () = start_gc domain_mgr ~unlink:true t c1 in let () = finalise_gc t in let () = check_not_found t c0 "removed c0" in let () = check_1 t c1 in @@ -1286,7 +1287,7 @@ module Split = struct "Chunk0 removed" true (check_async_unlinked (Filename.concat t.root "store.0.suffix")); [%log.debug "GC at c2"]; - let () = start_gc ~unlink:true t c2 in + let () = start_gc domain_mgr ~unlink:true t c2 in let () = finalise_gc t in let () = check_not_found t c0 "removed c0" in let () = check_not_found t c1 "removed c1" in @@ -1319,17 +1320,17 @@ module Split = struct let () = check_3 t c3 in S.Repo.close t.repo - let two_gc_then_split () = + let two_gc_then_split domain_mgr () = Eio.Switch.run @@ fun sw -> let t = init ~sw () in let t, c1 = commit_1 t in let t = checkout_exn t c1 in let t, c2 = commit_2 t in - let () = start_gc t c2 in + let () = start_gc domain_mgr t c2 in let () = finalise_gc t in let t = checkout_exn t c2 in let t, c3 = commit_3 t in - let () = start_gc t c3 in + let () = start_gc domain_mgr t c3 in let () = finalise_gc t in let () = S.split t.repo in let t = checkout_exn t c3 in @@ -1340,7 +1341,7 @@ module Split = struct let () = check_4 t c4 in S.Repo.close t.repo - let multi_split_and_gc () = + let multi_split_and_gc domain_mgr () = (* This test primarily checks that dead byte calculation happens correctly by testing GCs on chunks past the first one. When the calculation is incorrect, exceptions are thrown @@ -1354,14 +1355,14 @@ module Split = struct let t, c2 = commit_2 t in let () = S.split t.repo in - let () = start_gc t c1 in + let () = start_gc domain_mgr t c1 in let () = finalise_gc t in let t = checkout_exn t c2 in let t, c3 = commit_3 t in let () = S.split t.repo in - let () = start_gc t c2 in + let () = start_gc domain_mgr t c2 in let () = finalise_gc t in let t = checkout_exn t c3 in @@ -1373,37 +1374,37 @@ module Split = struct let () = check_4 t c4 in S.Repo.close t.repo - let split_and_gc () = + let split_and_gc domain_mgr () = Eio.Switch.run @@ fun sw -> let t = init ~sw () in let t, c1 = commit_1 t in let () = S.split t.repo in let t = checkout_exn t c1 in let t, c2 = commit_2 t in - let () = start_gc t c2 in + let () = start_gc domain_mgr t c2 in let () = finalise_gc t in let () = check_2 t c2 in let () = check_not_found t c1 "removed c1" in S.Repo.close t.repo - let another_split_and_gc () = + let another_split_and_gc domain_mgr () = Eio.Switch.run @@ fun sw -> let t = init ~sw () in let t, c1 = commit_1 t in let () = S.split t.repo in let t = checkout_exn t c1 in let t, c2 = commit_2 t in - let () = start_gc t c1 in + let () = start_gc domain_mgr t c1 in let () = finalise_gc t in let () = check_1 t c1 in let () = check_2 t c2 in S.Repo.close t.repo - let split_during_gc () = + let split_during_gc domain_mgr () = Eio.Switch.run @@ fun sw -> let t = init ~sw () in let t, c1 = commit_1 t in - let () = start_gc t c1 in + let () = start_gc domain_mgr t c1 in let () = S.split t.repo in let t = checkout_exn t c1 in let t, c2 = commit_2 t in @@ -1412,7 +1413,7 @@ module Split = struct let () = check_2 t c2 in S.Repo.close t.repo - let commits_and_splits_during_gc () = + let commits_and_splits_during_gc domain_mgr () = (* This test primarily ensures that chunk num is calculated correctly by intentionally creating chunks during a GC. *) Eio.Switch.run @@ fun sw -> @@ -1423,7 +1424,7 @@ module Split = struct let t = checkout_exn t c1 in let t, c2 = commit_2 t in - let () = start_gc t c2 in + let () = start_gc domain_mgr t c2 in let () = S.split t.repo in let t = checkout_exn t c2 in @@ -1454,34 +1455,36 @@ module Split = struct (S.is_split_allowed t.repo)); S.Repo.close t.repo - let tests = + let tests domain_mgr = [ tc "Test two splits" two_splits; tc "Test two splits for ro" ro_two_splits; - tc "Test splits and GC on V3 store" v3_migrated_store_splits_and_gc; + tc "Test splits and GC on V3 store" + (v3_migrated_store_splits_and_gc domain_mgr); tc "Test split and close" close_and_split; - tc "Test two gc followed by split" two_gc_then_split; - tc "Test split and GC" split_and_gc; - tc "Test multi split and GC" multi_split_and_gc; - tc "Test another split and GC" another_split_and_gc; - tc "Test split during GC" split_during_gc; - tc "Test commits and splits during GC" commits_and_splits_during_gc; + tc "Test two gc followed by split" (two_gc_then_split domain_mgr); + tc "Test split and GC" (split_and_gc domain_mgr); + tc "Test multi split and GC" (multi_split_and_gc domain_mgr); + tc "Test another split and GC" (another_split_and_gc domain_mgr); + tc "Test split during GC" (split_during_gc domain_mgr); + tc "Test commits and splits during GC" + (commits_and_splits_during_gc domain_mgr); tc "Test split for always indexed from v2 store" split_always_indexed_from_v2_store; ] end module Snapshot = struct - let export t commit = + let export ~domain_mgr t commit = let commit_key = S.Commit.key commit in - S.create_one_commit_store t.repo commit_key + S.create_one_commit_store ~domain_mgr t.repo commit_key - let snapshot_rw () = + let snapshot_rw domain_mgr () = Eio.Switch.run @@ fun sw -> let t = init ~sw () in let t, c1 = commit_1 t in let root_snap = Filename.concat t.root "snap" in - let () = export t c1 root_snap in + let () = export ~domain_mgr t c1 root_snap in [%log.debug "store works after export"]; let t = checkout_exn t c1 in let t, c2 = commit_2 t in @@ -1498,12 +1501,12 @@ module Snapshot = struct let () = check_2 t c2 in S.Repo.close t.repo - let snapshot_import_in_ro () = + let snapshot_import_in_ro domain_mgr () = Eio.Switch.run @@ fun sw -> let t = init ~sw () in let t, c1 = commit_1 t in let root_snap = Filename.concat t.root "snap" in - let () = export t c1 root_snap in + let () = export ~domain_mgr t c1 root_snap in let () = S.Repo.close t.repo in [%log.debug "open store from import in ro"]; Eio.Switch.run @@ fun sw -> @@ -1512,7 +1515,7 @@ module Snapshot = struct let () = check_1 t c1 in S.Repo.close t.repo - let snapshot_export_in_ro () = + let snapshot_export_in_ro domain_mgr () = Eio.Switch.run @@ fun sw -> let t = init ~sw () in let t, c1 = commit_1 t in @@ -1521,7 +1524,7 @@ module Snapshot = struct Eio.Switch.run @@ fun sw -> let t = init ~sw ~readonly:false ~fresh:false ~root:t.root () in let root_snap = Filename.concat t.root "snap" in - let () = export t c1 root_snap in + let () = export ~domain_mgr t c1 root_snap in [%log.debug "store works after export in readonly"]; let t = checkout_exn t c1 in let () = check_1 t c1 in @@ -1537,17 +1540,17 @@ module Snapshot = struct (* Test creating a snapshot in an archive store for a commit that is before the last gc target commit (ie it is in the lower) *) - let snapshot_gced_commit () = + let snapshot_gced_commit domain_mgr () = let lower_root = create_lower_root ~mkdir:false () in Eio.Switch.run @@ fun sw -> let t = init ~sw ~lower_root:(Some lower_root) () in let t, c1 = commit_1 t in let t = checkout_exn t c1 in let t, c2 = commit_2 t in - let () = start_gc t c2 in + let () = start_gc domain_mgr t c2 in let () = finalise_gc t in let root_snap = Filename.concat t.root "snap" in - let () = export t c1 root_snap in + let () = export ~domain_mgr t c1 root_snap in let () = S.Repo.close t.repo in [%log.debug "open store from snapshot"]; Eio.Switch.run @@ fun sw -> @@ -1558,11 +1561,11 @@ module Snapshot = struct let () = check_2 t c2 in S.Repo.close t.repo - let tests = + let tests domain_mgr = [ - tc "Import/export in rw" snapshot_rw; - tc "Import in ro" snapshot_import_in_ro; - tc "Export in ro" snapshot_export_in_ro; - tc "Snapshot gced commit" snapshot_gced_commit; + tc "Import/export in rw" (snapshot_rw domain_mgr); + tc "Import in ro" (snapshot_import_in_ro domain_mgr); + tc "Export in ro" (snapshot_export_in_ro domain_mgr); + tc "Snapshot gced commit" (snapshot_gced_commit domain_mgr); ] end diff --git a/test/irmin-pack/test_gc.mli b/test/irmin-pack/test_gc.mli index ae62d04580..e0f308c0fa 100644 --- a/test/irmin-pack/test_gc.mli +++ b/test/irmin-pack/test_gc.mli @@ -15,23 +15,23 @@ *) module Gc : sig - val tests : unit Alcotest.test_case list + val tests : _ Eio.Domain_manager.t -> unit Alcotest.test_case list end module Gc_archival : sig - val tests : unit Alcotest.test_case list + val tests : _ Eio.Domain_manager.t -> unit Alcotest.test_case list end module Concurrent_gc : sig - val tests : unit Alcotest.test_case list + val tests : _ Eio.Domain_manager.t -> unit Alcotest.test_case list end module Split : sig - val tests : unit Alcotest.test_case list + val tests : _ Eio.Domain_manager.t -> unit Alcotest.test_case list end module Snapshot : sig - val tests : unit Alcotest.test_case list + val tests : _ Eio.Domain_manager.t -> unit Alcotest.test_case list end module Store : sig @@ -42,7 +42,7 @@ module Store : sig val config : string -> Irmin.config val init_with_config : sw:Eio.Switch.t -> Irmin.config -> t val close : t -> unit - val start_gc : ?unlink:bool -> t -> S.commit -> unit + val start_gc : _ Eio.Domain_manager.t -> ?unlink:bool -> t -> S.commit -> unit val finalise_gc : t -> unit val commit_1 : t -> t * S.commit val commit_2 : t -> t * S.commit diff --git a/test/irmin-pack/test_lower.ml b/test/irmin-pack/test_lower.ml index 60b99bf16b..7177414098 100644 --- a/test/irmin-pack/test_lower.ml +++ b/test/irmin-pack/test_lower.ml @@ -261,7 +261,7 @@ module Store_tc = struct Alcotest.(check int) "volume_num is 1" 1 volume_num; Store.Repo.close repo - let test_add_volume_during_gc () = + let test_add_volume_during_gc domain_mgr () = Eio.Switch.run @@ fun sw -> let repo = init ~sw () in let main = Store.main repo in @@ -271,7 +271,7 @@ module Store_tc = struct main [ "a" ] "a" in let c = Store.Head.get main in - let _ = Store.Gc.start_exn repo (Store.Commit.key c) in + let _ = Store.Gc.start_exn ~domain_mgr repo (Store.Commit.key c) in let () = Alcotest.check_raises "add volume during gc" (Irmin_pack_unix.Errors.Pack_error `Add_volume_forbidden_during_gc) @@ -289,7 +289,7 @@ module Store_tc = struct in Store.Repo.close repo - let test_add_volume_reopen () = + let test_add_volume_reopen domain_mgr () = Eio.Switch.run @@ fun sw -> let root, lower_root = fresh_roots () in let repo = Store.Repo.v ~sw (config ~fresh:true ~lower_root root) in @@ -297,7 +297,7 @@ module Store_tc = struct let info () = Store.Info.v ~author:"test" Int64.zero in let () = Store.set_exn ~info main [ "a" ] "a" in let c1 = Store.Head.get main in - let _ = Store.Gc.start_exn repo (Store.Commit.key c1) in + let _ = Store.Gc.start_exn ~domain_mgr repo (Store.Commit.key c1) in let _ = Store.Gc.finalise_exn ~wait:true repo in let () = Store.add_volume repo in Alcotest.(check int) "two volumes" 2 (count_volumes repo); @@ -381,7 +381,7 @@ module Store_tc = struct let _ = read_everything repo in Store.Repo.close repo - let test_migrate_then_gc () = + let test_migrate_then_gc domain_mgr () = Eio.Switch.run @@ fun sw -> let root, lower_root = fresh_roots () in (* Create without a lower *) @@ -401,12 +401,12 @@ module Store_tc = struct let b_commit = Store.Head.get main in let () = Store.set_exn ~info main [ "c" ] "c" in (* GC at [b] requires reading [a] data from the lower volume *) - let _ = Store.Gc.start_exn repo (Store.Commit.key b_commit) in + let _ = Store.Gc.start_exn ~domain_mgr repo (Store.Commit.key b_commit) in let _ = Store.Gc.finalise_exn ~wait:true repo in let _ = read_everything repo in Store.Repo.close repo - let test_migrate_then_gc_in_lower () = + let test_migrate_then_gc_in_lower domain_mgr () = Eio.Switch.run @@ fun sw -> let root, lower_root = fresh_roots () in (* Create without a lower *) @@ -426,11 +426,11 @@ module Store_tc = struct Important: we call GC on a commit that is not the latest in the lower (ie [b]) to ensure its offset is not equal to the start offset of the upper. *) - let _ = Store.Gc.start_exn repo (Store.Commit.key a_commit) in + let _ = Store.Gc.start_exn repo ~domain_mgr (Store.Commit.key a_commit) in let _ = Store.Gc.finalise_exn ~wait:true repo in Store.Repo.close repo - let test_volume_data_locality () = + let test_volume_data_locality domain_mgr () = Eio.Switch.run @@ fun sw -> let root, lower_root = fresh_roots () in let repo = Store.Repo.v ~sw (config ~fresh:true ~lower_root root) in @@ -440,7 +440,7 @@ module Store_tc = struct let () = Store.set_exn ~info main [ "c1" ] "a" in let c1 = Store.Head.get main in [%log.debug "GC c1"]; - let _ = Store.Gc.start_exn repo (Store.Commit.key c1) in + let _ = Store.Gc.start_exn ~domain_mgr repo (Store.Commit.key c1) in let _ = Store.Gc.finalise_exn ~wait:true repo in let () = Store.add_volume repo in [%log.debug "add c2, c3, c4"]; @@ -451,7 +451,7 @@ module Store_tc = struct let () = Store.set_exn ~info main [ "c5" ] "e" in let c5 = Store.Head.get main in [%log.debug "GC c5"]; - let _ = Store.Gc.start_exn repo (Store.Commit.key c5) in + let _ = Store.Gc.start_exn ~domain_mgr repo (Store.Commit.key c5) in let _ = Store.Gc.finalise_exn ~wait:true repo in let get_direct_key key = match Irmin_pack_unix.Pack_key.inspect key with @@ -494,7 +494,7 @@ module Store_tc = struct in Store.Repo.close repo - let test_cleanup () = + let test_cleanup domain_mgr () = Eio.Switch.run @@ fun sw -> let root, lower_root = fresh_roots () in [%log.debug "create store with data and run GC"]; @@ -503,7 +503,7 @@ module Store_tc = struct let info () = Store.Info.v ~author:"test" Int64.zero in let () = Store.set_exn ~info main [ "a" ] "a" in let c1 = Store.Head.get main in - let _ = Store.Gc.start_exn repo (Store.Commit.key c1) in + let _ = Store.Gc.start_exn ~domain_mgr repo (Store.Commit.key c1) in let _ = Store.Gc.finalise_exn ~wait:true repo in let volume_root = volume_path repo Int63.zero in let generation = generation repo in @@ -533,23 +533,25 @@ end module Store = struct include Store_tc - let tests = + let tests domain_mgr = Alcotest. [ quick_tc "create store" test_create; quick_tc "create nested" test_create_nested; quick_tc "open rw with lower" test_open_rw_lower; quick_tc "add volume with no lower" test_add_volume_wo_lower; - quick_tc "add volume during gc" test_add_volume_during_gc; - quick_tc "control file updated after add" test_add_volume_reopen; - quick_tc "add volume and reopen" test_add_volume_reopen; + quick_tc "add volume during gc" (test_add_volume_during_gc domain_mgr); + quick_tc "control file updated after add" + (test_add_volume_reopen domain_mgr); + quick_tc "add volume and reopen" (test_add_volume_reopen domain_mgr); quick_tc "create without lower then migrate" test_migrate; quick_tc "migrate v2" test_migrate_v2; quick_tc "migrate v3" test_migrate_v3; - quick_tc "migrate then gc" test_migrate_then_gc; - quick_tc "migrate then gc in lower" test_migrate_then_gc_in_lower; - quick_tc "test data locality" test_volume_data_locality; - quick_tc "test cleanup" test_cleanup; + quick_tc "migrate then gc" (test_migrate_then_gc domain_mgr); + quick_tc "migrate then gc in lower" + (test_migrate_then_gc_in_lower domain_mgr); + quick_tc "test data locality" (test_volume_data_locality domain_mgr); + quick_tc "test cleanup" (test_cleanup domain_mgr); ] end diff --git a/test/irmin-pack/test_lower.mli b/test/irmin-pack/test_lower.mli index a2a5f61123..55f66e2ce1 100644 --- a/test/irmin-pack/test_lower.mli +++ b/test/irmin-pack/test_lower.mli @@ -15,7 +15,7 @@ *) module Store : sig - val tests : unit Alcotest.test_case list + val tests : _ Eio.Domain_manager.t -> unit Alcotest.test_case list end module Direct : sig diff --git a/test/irmin-pack/test_pack.ml b/test/irmin-pack/test_pack.ml index cbd0ebea7d..8200218f5f 100644 --- a/test/irmin-pack/test_pack.ml +++ b/test/irmin-pack/test_pack.ml @@ -564,27 +564,27 @@ let misc d_mgr = ("pack-files", Pack.tests); ("branch-files", Branch.tests); ("read-only", Test_readonly.tests); - ("existing stores", Test_existing_stores.tests); + ("existing stores", Test_existing_stores.tests d_mgr); ("inodes", Test_inode.tests); ("trees", Test_tree.tests); ("version-bump", Test_pack_version_bump.tests); - ("snapshot", Test_snapshot.tests); - ("upgrade", Test_upgrade.tests); - ("gc", Test_gc.Gc.tests); - ("concurrent gc", Test_gc.Concurrent_gc.tests); - ("gc archival", Test_gc.Gc_archival.tests); - ("split", Test_gc.Split.tests); + ("snapshot", Test_snapshot.tests d_mgr); + ("upgrade", Test_upgrade.tests d_mgr); + ("gc", Test_gc.Gc.tests d_mgr); + ("concurrent gc", Test_gc.Concurrent_gc.tests d_mgr); + ("gc archival", Test_gc.Gc_archival.tests d_mgr); + ("split", Test_gc.Split.tests d_mgr); ("flush", Test_flush_reload.tests); ("ranges", Test_ranges.tests); ("mapping", Test_mapping.tests); ("test_nearest_geq", Test_nearest_geq.tests); ("layout", Layout.tests); - ("dispatcher", Test_dispatcher.tests); + ("dispatcher", Test_dispatcher.tests d_mgr); ("corrupted", Test_corrupted.tests); - ("snapshot_gc", Test_gc.Snapshot.tests); - ("async tasks", Test_async.tests); + ("snapshot_gc", Test_gc.Snapshot.tests d_mgr); + ("async tasks", Test_async.tests d_mgr); ("indexing strategy", Test_indexing_strategy.tests); ("lower: direct", Test_lower.Direct.tests); - ("lower: store", Test_lower.Store.tests); + ("lower: store", Test_lower.Store.tests d_mgr); ("multicore", Test_multicore.tests d_mgr); ] diff --git a/test/irmin-pack/test_snapshot.ml b/test/irmin-pack/test_snapshot.ml index e5abec29c7..bc9345c4c6 100644 --- a/test/irmin-pack/test_snapshot.ml +++ b/test/irmin-pack/test_snapshot.ml @@ -174,9 +174,9 @@ let test_on_disk_minimal = let test_on_disk_always = test_on_disk ~indexing_strategy:Irmin_pack.Indexing_strategy.always -let start_gc repo commit = +let start_gc domain_mgr repo commit = let commit_key = S.Commit.key commit in - let launched = S.Gc.start_exn ~unlink:false repo commit_key in + let launched = S.Gc.start_exn ~domain_mgr ~unlink:false repo commit_key in assert launched let finalise_gc repo = @@ -185,7 +185,7 @@ let finalise_gc repo = | `Idle | `Running -> Alcotest.fail "expected finalised gc" | `Finalised _ -> () -let test_gc ~repo_export ~repo_import ?on_disk expected_visited = +let test_gc domain_mgr ~repo_export ~repo_import ?on_disk expected_visited = (* create the store *) let tree1 = let t = S.Tree.singleton [ "b"; "a" ] "x0" in @@ -201,7 +201,7 @@ let test_gc ~repo_export ~repo_import ?on_disk expected_visited = in let c3 = S.Commit.v repo_export ~parents:[ k1 ] ~info tree3 in (* call gc on last commit *) - let () = start_gc repo_export c3 in + let () = start_gc domain_mgr repo_export c3 in let () = finalise_gc repo_export in let tree = S.Commit.tree c3 in let root_key = S.Tree.key tree |> Option.get in @@ -223,7 +223,7 @@ let test_gc ~repo_export ~repo_import ?on_disk expected_visited = let indexing_strategy = Irmin_pack.Indexing_strategy.minimal -let test_gced_store_in_memory () = +let test_gced_store_in_memory domain_mgr () = rm_dir root_export; rm_dir root_import; Eio.Switch.run @@ fun sw -> @@ -235,11 +235,11 @@ let test_gced_store_in_memory () = S.Repo.v ~sw (config ~readonly:false ~fresh:true ~indexing_strategy root_import) in - let () = test_gc ~repo_export ~repo_import 5 in + let () = test_gc domain_mgr ~repo_export ~repo_import 5 in let () = S.Repo.close repo_export in S.Repo.close repo_import -let test_gced_store_on_disk () = +let test_gced_store_on_disk domain_mgr () = rm_dir root_export; rm_dir root_import; let index_on_disk = Filename.concat root_import "index_on_disk" in @@ -252,11 +252,14 @@ let test_gced_store_on_disk () = S.Repo.v ~sw (config ~readonly:false ~fresh:true ~indexing_strategy root_import) in - let () = test_gc ~repo_export ~repo_import ~on_disk:(`Path index_on_disk) 5 in + let () = + test_gc domain_mgr ~repo_export ~repo_import ~on_disk:(`Path index_on_disk) + 5 + in let () = S.Repo.close repo_export in S.Repo.close repo_import -let test_export_import_reexport () = +let test_export_import_reexport domain_mgr () = rm_dir root_export; rm_dir root_import; Eio.Switch.run @@ fun sw -> @@ -291,7 +294,9 @@ let test_export_import_reexport () = let commit_key = S.Commit.key commit in let commit_hash = S.Commit.hash commit in (* export the gc-based snapshot in a clean root_export. *) - let () = S.create_one_commit_store repo_import commit_key root_export in + let () = + S.create_one_commit_store ~domain_mgr repo_import commit_key root_export + in let () = S.Repo.close repo_import in (* open the new store and check that everything is readable. *) let repo_export = @@ -305,15 +310,15 @@ let test_export_import_reexport () = Alcotest.(check (option string)) "find blob" (Some "x") got; S.Repo.close repo_export -let tests = +let tests domain_mgr = let tc name f = Alcotest.test_case name `Quick f in [ tc "in memory minimal" test_in_memory_minimal; tc "in memory always" test_in_memory_always; tc "on disk minimal" test_on_disk_minimal; tc "on disk always" test_on_disk_always; - tc "gced store, in memory" test_gced_store_in_memory; - tc "gced store, on disk" test_gced_store_on_disk; + tc "gced store, in memory" (test_gced_store_in_memory domain_mgr); + tc "gced store, on disk" (test_gced_store_on_disk domain_mgr); tc "import old snapshot, export gc based snapshot" - test_export_import_reexport; + (test_export_import_reexport domain_mgr); ] diff --git a/test/irmin-pack/test_upgrade.ml b/test/irmin-pack/test_upgrade.ml index 2db4bcf04f..9cb85e2b56 100644 --- a/test/irmin-pack/test_upgrade.ml +++ b/test/irmin-pack/test_upgrade.ml @@ -245,9 +245,9 @@ module Store = struct let close = S.Repo.close let reload = S.reload - let gc repo = + let gc domain_mgr repo = let k = key_of_entry c1 in - let launched = S.Gc.start_exn ~unlink:true repo k in + let launched = S.Gc.start_exn ~domain_mgr ~unlink:true repo k in assert launched; let result = S.Gc.finalise_exn ~wait:true repo in match result with @@ -522,7 +522,7 @@ let write1_rw t = () (** One of the 4 rw mutations *) -let gc_rw t = +let gc_rw domain_mgr t = [%logs.app "*** gc_rw %a" pp_setup t.setup]; match t.rw with | None -> assert false @@ -535,10 +535,11 @@ let gc_rw t = Alcotest.check_raises "GC on V2/always" (Irmin_pack_unix.Errors.Pack_error (`Gc_disallowed "Store does not support GC")) - (fun () -> Store.gc repo) + (fun () -> Store.gc domain_mgr repo) in raise Skip_the_rest_of_that_test - | (From_v3 | From_scratch | From_v3_c0_gced), `minimal -> Store.gc repo + | (From_v3 | From_scratch | From_v3_c0_gced), `minimal -> + Store.gc domain_mgr repo in () @@ -624,7 +625,7 @@ let close_everything t = (fun (_, repo) -> Store.close repo) (Option.to_list t.ro @ Option.to_list t.rw) -let test_one t ~ro_open_at ~ro_sync_at = +let test_one domain_mgr t ~ro_open_at ~ro_sync_at = Eio.Switch.run @@ fun sw -> let aux phase = let () = check t in @@ -639,15 +640,15 @@ let test_one t ~ro_open_at ~ro_sync_at = let () = aux S2_before_write in let () = write1_rw t in let () = aux S3_before_gc in - let () = gc_rw t in + let () = gc_rw domain_mgr t in let () = aux S4_before_write in let () = write2_rw t in aux S5_before_close -let test_one_guarded setup ~ro_open_at ~ro_sync_at = +let test_one_guarded domain_mgr setup ~ro_open_at ~ro_sync_at = let t = create_test_env setup in try - let () = test_one t ~ro_open_at ~ro_sync_at in + let () = test_one domain_mgr t ~ro_open_at ~ro_sync_at in close_everything t with | Skip_the_rest_of_that_test -> @@ -657,9 +658,9 @@ let test_one_guarded setup ~ro_open_at ~ro_sync_at = (** All possible interleaving of the ro calls (open and sync) with the rw calls (open, write1, gc and write2). *) -let test start_mode indexing_strategy lru_size = +let test domain_mgr start_mode indexing_strategy lru_size = let setup = { start_mode; indexing_strategy; lru_size } in - let t = test_one_guarded setup in + let t = test_one_guarded domain_mgr setup in let () = t ~ro_open_at:S1_before_start ~ro_sync_at:S1_before_start in let () = t ~ro_open_at:S1_before_start ~ro_sync_at:S2_before_write in @@ -683,22 +684,23 @@ let test start_mode indexing_strategy lru_size = () (** Product on lru_size *) -let test start_mode indexing_strategy = - test start_mode indexing_strategy 0; - test start_mode indexing_strategy 100 +let test domain_mgr start_mode indexing_strategy = + test domain_mgr start_mode indexing_strategy 0; + test domain_mgr start_mode indexing_strategy 100 -let test_gced_store () = test From_v3_c0_gced `minimal +let test_gced_store domain_mgr () = test domain_mgr From_v3_c0_gced `minimal (** Product on indexing_strategy *) -let test start_mode () = - test start_mode `minimal; - test start_mode `always +let test domain_mgr start_mode () = + test domain_mgr start_mode `minimal; + test domain_mgr start_mode `always (** Product on start_mode *) -let tests = +let tests domain_mgr = [ - Alcotest.test_case "upgrade From_v3" `Quick (test From_v3); - Alcotest.test_case "upgrade From_v2" `Quick (test From_v2); - Alcotest.test_case "upgrade From_scratch" `Quick (test From_scratch); - Alcotest.test_case "upgrade From_v3 after Gc" `Quick test_gced_store; + Alcotest.test_case "upgrade From_v3" `Quick (test domain_mgr From_v3); + Alcotest.test_case "upgrade From_v2" `Quick (test domain_mgr From_v2); + Alcotest.test_case "upgrade From_scratch" `Quick + (test domain_mgr From_scratch); + Alcotest.test_case "upgrade From_v3 after Gc" `Quick (test_gced_store domain_mgr); ] diff --git a/test/irmin-tezos/generate.ml b/test/irmin-tezos/generate.ml index 0e67c5a084..450a5a94ec 100644 --- a/test/irmin-tezos/generate.ml +++ b/test/irmin-tezos/generate.ml @@ -63,18 +63,18 @@ module Generator = struct c3 - let create_gced_store ~sw path = + let create_gced_store ~sw domain_mgr path = let before_closing repo head = - let _ = Store.Gc.start_exn repo head in + let _ = Store.Gc.start_exn ~domain_mgr repo head in let _ = Store.Gc.wait repo in () in create_store ~sw ~before_closing Irmin_pack.Indexing_strategy.minimal path - let create_snapshot_store ~sw ~src ~dest = + let create_snapshot_store ~sw domain_mgr ~src ~dest = let before_closing repo head = rm_dir dest; - Store.create_one_commit_store repo head dest + Store.create_one_commit_store ~domain_mgr repo head dest in create_store ~sw ~before_closing Irmin_pack.Indexing_strategy.minimal src end @@ -82,7 +82,7 @@ end let ensure_data_dir () = if not (Sys.file_exists "data") then Unix.mkdir "data" 0o755 -let generate () = +let generate domain_mgr () = ensure_data_dir (); Eio.Switch.run @@ fun sw -> let _ = @@ -92,9 +92,9 @@ let generate () = let _ = Generator.create_store ~sw Irmin_pack.Indexing_strategy.always "data/always" in - let _ = Generator.create_gced_store ~sw "data/gced" in + let _ = Generator.create_gced_store ~sw domain_mgr "data/gced" in let _ = - Generator.create_snapshot_store ~sw ~src:"data/snapshot_src" + Generator.create_snapshot_store domain_mgr ~sw ~src:"data/snapshot_src" ~dest:"data/snapshot" in () @@ -103,5 +103,4 @@ 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); - Irmin_pack_unix.Async.set_domain_mgr domain_mgr; - generate () + generate domain_mgr () diff --git a/test/irmin-tezos/irmin_fsck.ml b/test/irmin-tezos/irmin_fsck.ml index 1650bd9f03..d1cd52c2b1 100644 --- a/test/irmin-tezos/irmin_fsck.ml +++ b/test/irmin-tezos/irmin_fsck.ml @@ -32,9 +32,7 @@ module Store_tz = Irmin_pack_unix.Checks.Make (Maker_tz) 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); - Irmin_pack_unix.Async.set_domain_mgr domain_mgr; try let store_type = Sys.getenv "STORE" in if store_type = "PACK" then match Store.cli () with _ -> .