Skip to content

Commit 9046cf5

Browse files
clecatart-w
authored andcommitted
irmin-pack: eio backend
1 parent 9d606d7 commit 9046cf5

File tree

104 files changed

+2831
-1946
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

104 files changed

+2831
-1946
lines changed

bench/irmin-pack/bench_common.ml

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -60,20 +60,11 @@ let random_string n = String.init n (fun _i -> random_char ())
6060
let random_blob () = random_string 10 |> Bytes.of_string
6161
let random_key () = random_string 5
6262

63-
let default_artefacts_dir =
64-
let ( / ) = Filename.concat in
65-
Unix.getcwd () / "_artefacts" / Uuidm.to_string (Uuidm.v `V4)
63+
let default_artefacts_dir cwd =
64+
Eio.Path.(cwd / "_artefacts" / Uuidm.to_string (Uuidm.v `V4))
6665

6766
let prepare_artefacts_dir path =
68-
let rec mkdir_p path =
69-
if Sys.file_exists path then ()
70-
else
71-
let path' = Filename.dirname path in
72-
if path' = path then failwith "Failed to prepare result dir";
73-
mkdir_p path';
74-
Unix.mkdir path 0o755
75-
in
76-
mkdir_p path
67+
Eio.Path.mkdirs ~exists_ok:true ~perm:0o755 path
7768

7869
let with_timer f =
7970
let t0 = Sys.time () in
@@ -121,27 +112,26 @@ end
121112

122113
module FSHelper = struct
123114
let file f =
124-
try (Unix.stat f).st_size with Unix.Unix_error (Unix.ENOENT, _, _) -> 0
115+
(* in MiB *)
116+
try
117+
Eio.Switch.run @@ fun sw ->
118+
let f = Eio.Path.open_in ~sw f in
119+
Optint.Int63.to_int (Eio.File.size f)
120+
with Eio.Exn.Io (Eio.Fs.E (Not_found _), _) -> 0
125121

126122
let dict root = file (Irmin_pack.Layout.V1_and_v2.dict ~root) / 1024 / 1024
127123
let pack root = file (Irmin_pack.Layout.V1_and_v2.pack ~root) / 1024 / 1024
128124

129125
let index root =
130-
let index_dir = Filename.concat root "index" in
131-
let a = file (Filename.concat index_dir "data") in
132-
let b = file (Filename.concat index_dir "log") in
133-
let c = file (Filename.concat index_dir "log_async") in
126+
let index_dir = Eio.Path.(root / "index") in
127+
let a = file Eio.Path.(index_dir / "data") in
128+
let b = file Eio.Path.(index_dir / "log") in
129+
let c = file Eio.Path.(index_dir / "log_async") in
134130
(a + b + c) / 1024 / 1024
135131

136132
let size root = dict root + pack root + index root
137133
let get_size root = size root
138-
139-
let rm_dir root =
140-
if Sys.file_exists root then (
141-
let cmd = Printf.sprintf "rm -rf %s" root in
142-
[%logs.info "exec: %s" cmd];
143-
let _ = Sys.command cmd in
144-
())
134+
let rm_dir root = Eio.Path.rmtree ~missing_ok:true root
145135
end
146136

147137
module Generate_trees

bench/irmin-pack/bench_common.mli

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
module Mtime : module type of Import.Mtime
1818

19-
val default_artefacts_dir : string
20-
val prepare_artefacts_dir : string -> unit
19+
val default_artefacts_dir : Eio.Fs.dir_ty Eio.Path.t -> Eio.Fs.dir_ty Eio.Path.t
20+
val prepare_artefacts_dir : Eio.Fs.dir_ty Eio.Path.t -> unit
2121
val reporter : ?prefix:string -> unit -> Logs.reporter
2222
val setup_log : Fmt.style_renderer option -> Logs.level option -> unit
2323
val reset_stats : unit -> unit
@@ -36,8 +36,8 @@ module Conf : Irmin_pack.Conf.S
3636
module Schema : Irmin.Schema.S
3737

3838
module FSHelper : sig
39-
val rm_dir : string -> unit
40-
val get_size : string -> int
39+
val rm_dir : Eio.Fs.dir_ty Eio.Path.t -> unit
40+
val get_size : Eio.Fs.dir_ty Eio.Path.t -> int
4141
end
4242

4343
module Generate_trees

bench/irmin-pack/dune

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
(executable
8181
(name trace_stats)
8282
(modules trace_stats)
83-
(libraries cmdliner irmin_traces))
83+
(libraries cmdliner irmin_traces eio_main))
8484

8585
;; Require the executables to compile during tests
8686

bench/irmin-pack/main.ml

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1515
*)
1616

17-
let config ~root = Irmin_pack.config ~fresh:false root
18-
1917
module Config = struct
2018
let entries = 2
2119
let stable_hash = 3
@@ -33,15 +31,19 @@ module Bench = Irmin_bench.Make (KV)
3331

3432
let file f =
3533
(* in MiB *)
36-
try (Unix.stat f).st_size / 1024 / 1024
37-
with Unix.Unix_error (Unix.ENOENT, _, _) -> 0
34+
try
35+
Eio.Switch.run @@ fun sw ->
36+
let open Optint.Int63 in
37+
let f = Eio.Path.open_in ~sw f in
38+
Infix.(to_int @@ (Eio.File.size f / of_int 1024 / of_int 1024))
39+
with Eio.Exn.Io (Eio.Fs.E (Not_found _), _) -> 0
3840

3941
let index root =
4042
let rec aux acc i =
4143
if i = 256 then acc
4244
else
4345
let filename = Format.sprintf "store.index.%d" i in
44-
let s = file (Filename.concat root filename) in
46+
let s = file Eio.Path.(root / filename) in
4547
aux (acc + s) (i + 1)
4648
in
4749
aux 0 0
@@ -52,4 +54,12 @@ let size ~root =
5254
|> List.map file
5355
|> List.fold_left ( + ) index_size
5456

55-
let () = Bench.run ~config ~size
57+
let () =
58+
Eio_main.run @@ fun env ->
59+
Eio.Switch.run @@ fun sw ->
60+
let fs = Eio.Stdenv.cwd env in
61+
let config ~root =
62+
Irmin_pack.config ~sw ~fs ~fresh:false Eio.Path.(fs / root)
63+
in
64+
let size ~root = size ~root:Eio.Path.(fs / root) in
65+
Bench.run ~config ~size

bench/irmin-pack/trace_collection.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ module Make_stat (Store : Irmin.Generic_key.KV) = struct
167167
}
168168
end
169169

170-
let create_file : string -> Def.config -> string -> t =
170+
let create_file : Eio.Fs.dir_ty Eio.Path.t -> Def.config -> string -> t =
171171
fun path config store_path ->
172172
let header =
173173
Def.

bench/irmin-pack/trace_common.ml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,10 @@ module Io (Ff : File_format) = struct
228228
in
229229
Seq.unfold produce_row ()
230230

231-
let open_reader : string -> Ff.Latest.header * Ff.Latest.row Seq.t =
231+
let open_reader :
232+
Eio.Fs.dir_ty Eio.Path.t -> Ff.Latest.header * Ff.Latest.row Seq.t =
232233
fun path ->
234+
let path = Eio.Path.native_exn path in
233235
let chan = open_in_bin path in
234236
let len = LargeFile.in_channel_length chan in
235237
if len < 12L then
@@ -260,6 +262,7 @@ module Io (Ff : File_format) = struct
260262
type writer = { path : string; channel : out_channel; buffer : Buffer.t }
261263

262264
let create_file path header =
265+
let path = Eio.Path.native_exn path in
263266
let channel = open_out path in
264267
let buffer = Buffer.create 0 in
265268
output_string channel (Magic.to_string Ff.magic);

bench/irmin-pack/trace_replay.ml

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -370,8 +370,8 @@ module Make (Store : Store) = struct
370370
let really_add_volume = time_to_add_volume in
371371
(really_wait_gc, really_start_gc, really_split, really_add_volume)
372372

373-
let add_commits config repo commit_seq on_commit on_end stats check_hash
374-
empty_blobs =
373+
let add_commits ~fs ~domain_mgr config repo commit_seq on_commit on_end stats
374+
check_hash empty_blobs =
375375
let max_ncommits = config.number_of_commits_to_replay in
376376
with_progress_bar ~message:"Replaying trace" ~n:max_ncommits ~unit:"commit"
377377
@@ fun prog ->
@@ -444,7 +444,7 @@ module Make (Store : Store) = struct
444444
commit_duration duration finalise_duration]
445445
| Error s -> failwith s
446446
in
447-
Store.gc_run ~finished repo gc_commit_key)
447+
Store.gc_run ~fs ~domain_mgr ~finished repo gc_commit_key)
448448
in
449449
let () = add_operations t repo ops i stats check_hash empty_blobs in
450450
t.latest_commit_idx <- i;
@@ -465,8 +465,14 @@ module Make (Store : Store) = struct
465465
in
466466
aux commit_seq 0
467467

468-
let run : type a. _ -> a config -> a =
469-
fun ext_config config ->
468+
let run :
469+
type a.
470+
fs:Eio.Fs.dir_ty Eio.Path.t ->
471+
domain_mgr:_ Eio.Domain_manager.t ->
472+
_ ->
473+
a config ->
474+
a =
475+
fun ~fs ~domain_mgr ext_config config ->
470476
let check_hash =
471477
config.path_conversion = `None
472478
&& config.inode_config = (32, 256)
@@ -475,14 +481,15 @@ module Make (Store : Store) = struct
475481
[%logs.app
476482
"Will %scheck commit hashes against reference."
477483
(if check_hash then "" else "NOT ")];
484+
Eio.Switch.run @@ fun sw ->
478485
let commit_seq =
479486
open_commit_sequence config.number_of_commits_to_replay
480487
config.path_conversion config.replay_trace_path
481488
in
482-
let root = Filename.concat config.artefacts_path "root" in
483-
let repo, on_commit, on_end = Store.create_repo ~root ext_config in
489+
let root = Eio.Path.(config.artefacts_path / "root") in
490+
let repo, on_commit, on_end = Store.create_repo ~sw ~fs ~root ext_config in
484491
prepare_artefacts_dir config.artefacts_path;
485-
let stat_path = Filename.concat config.artefacts_path "stat_trace.repr" in
492+
let stat_path = Eio.Path.(config.artefacts_path / "stat_trace.repr") in
486493
let c =
487494
let entries, stable_hash = config.inode_config in
488495
Trace_definitions.Stat_trace.
@@ -491,19 +498,21 @@ module Make (Store : Store) = struct
491498
`Replay
492499
{
493500
path_conversion = config.path_conversion;
494-
artefacts_dir = config.artefacts_path;
501+
artefacts_dir = Eio.Path.native_exn config.artefacts_path;
495502
};
496503
inode_config = (entries, entries, stable_hash);
497504
store_type = config.store_type;
498505
}
499506
in
500-
let stats = Stat_collector.create_file stat_path c root in
507+
let stats =
508+
Stat_collector.create_file stat_path c (Eio.Path.native_exn root)
509+
in
501510
Irmin_pack.Stats.reset_stats ();
502511
Fun.protect
503512
(fun () ->
504513
let block_count =
505-
add_commits config repo commit_seq on_commit on_end stats check_hash
506-
config.empty_blobs
514+
add_commits ~fs ~domain_mgr config repo commit_seq on_commit on_end
515+
stats check_hash config.empty_blobs
507516
in
508517
[%logs.app "Closing repo..."];
509518
let () = Store.Repo.close repo in
@@ -515,7 +524,7 @@ module Make (Store : Store) = struct
515524
Trace_stat_summary.summarise ~block_count stat_path)
516525
~finally:(fun () ->
517526
if config.keep_stat_trace then (
518-
[%logs.app "Stat trace kept at %s" stat_path];
519-
Unix.chmod stat_path 0o444)
527+
[%logs.app "Stat trace kept at %s" (Eio.Path.native_exn stat_path)];
528+
Unix.chmod (Eio.Path.native_exn stat_path) 0o444)
520529
else Stat_collector.remove stats)
521530
end

bench/irmin-pack/trace_replay_intf.ml

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ module Config = struct
2424
path_conversion : [ `None | `V1 | `V0_and_v1 | `V0 ];
2525
inode_config : int * int;
2626
store_type : [ `Pack | `Pack_layered | `Pack_mem ];
27-
replay_trace_path : string;
28-
artefacts_path : string;
27+
replay_trace_path : Eio.Fs.dir_ty Eio.Path.t;
28+
artefacts_path : Eio.Fs.dir_ty Eio.Path.t;
2929
keep_store : bool;
3030
keep_stat_trace : bool;
3131
empty_blobs : bool;
@@ -99,15 +99,26 @@ module type Store = sig
9999
type on_commit := int -> Hash.t -> unit
100100
type on_end := unit -> unit
101101

102-
val create_repo : root:string -> store_config -> Repo.t * on_commit * on_end
102+
val create_repo :
103+
sw:Eio.Switch.t ->
104+
fs:Eio.Fs.dir_ty Eio.Path.t ->
105+
root:Eio.Fs.dir_ty Eio.Path.t ->
106+
store_config ->
107+
Repo.t * on_commit * on_end
108+
103109
val split : repo -> unit
104110
val add_volume : repo -> unit
105111
val gc_wait : repo -> unit
106112

107113
type stats := Irmin_pack_unix.Stats.Latest_gc.stats
108114

109115
val gc_run :
110-
?finished:((stats, string) result -> unit) -> repo -> commit_key -> unit
116+
fs:Eio.Fs.dir_ty Eio.Path.t ->
117+
domain_mgr:_ Eio.Domain_manager.t ->
118+
?finished:((stats, string) result -> unit) ->
119+
repo ->
120+
commit_key ->
121+
unit
111122
end
112123

113124
module type Sigs = sig
@@ -124,6 +135,11 @@ module type Sigs = sig
124135
with type 'a return_type = 'a return_type
125136
and type 'a config = 'a config
126137

127-
val run : Store.store_config -> 'a config -> 'a
138+
val run :
139+
fs:Eio.Fs.dir_ty Eio.Path.t ->
140+
domain_mgr:_ Eio.Domain_manager.t ->
141+
Store.store_config ->
142+
'a config ->
143+
'a
128144
end
129145
end

bench/irmin-pack/trace_stat_summary.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,6 +1098,7 @@ let summarise ?block_count trace_stat_path =
10981098
(* Section 4/4 - Conversion from summary to json file *)
10991099

11001100
let save_to_json v path =
1101+
let path = Eio.Path.native_exn path in
11011102
let j = Fmt.str "%a\n" (Irmin.Type.pp_json t) v in
11021103
let chan = open_out path in
11031104
output_string chan j;

0 commit comments

Comments
 (0)