Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
icristescu committed Nov 3, 2022
1 parent 6bd607c commit 67cf48a
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 30 deletions.
2 changes: 1 addition & 1 deletion src/irmin-pack/unix/ext.ml
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ module Maker (Config : Conf.S) = struct
let* _suffix_start_offset, _prefix_commit_offset =
match t.running_gc with
| None -> assert false
| Some { gc; _ } -> Gc.finalise_snap_exn gc
| Some { gc; _ } -> Gc.finalise_snap_exn gc path
in
Lwt.return_unit
end
Expand Down
4 changes: 4 additions & 0 deletions src/irmin-pack/unix/file_manager.ml
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,10 @@ struct
else open_rw_no_control_file config
| `Directory | `Other -> Error `Invalid_layout)

let open_rw_from_snapshot config ~generation ~suffix_start_offset
~prefix_commit_offset =


let open_rw_from_snapshot config ~generation ~suffix_start_offset
~prefix_commit_offset =
let open Result_syntax in
Expand Down
54 changes: 30 additions & 24 deletions src/irmin-pack/unix/gc.ml
Original file line number Diff line number Diff line change
Expand Up @@ -315,39 +315,45 @@ module Make (Args : Gc_args.S) = struct
| `Running -> Lwt.return_ok `Running
| #Async.outcome as status -> go status)

let finalise_snap_exn t =
let create_new_suffix ~root ~generation =
let open Result_syntax in
let path = Irmin_pack.Layout.V4.suffix_chunk ~root ~chunk_idx:generation in
let ao =
Ao.create_rw ~path ~overwrite:true ~auto_flush_threshold:1_000_000
~auto_flush_procedure:`Internal
|> Errs.raise_if_error
in
Ao.close ao |> Errs.raise_if_error

let finalise_snap_exn t snapshot_root =
let* status = Async.await t.task in
match status with
| `Success ->
let root = t.root in
let snap_root = Filename.concat t.root "snap" in
let () = Io.mkdir snap_root |> Errs.raise_if_error in
let () = Io.mkdir snapshot_root |> Errs.raise_if_error in
let generation = t.generation in
let src_prefix = Irmin_pack.Layout.V4.prefix ~root ~generation in
let dst_prefix =
Irmin_pack.Layout.V4.prefix ~root:snap_root ~generation
in
let src_mapping = Irmin_pack.Layout.V4.mapping ~root ~generation in
let dst_mapping =
Irmin_pack.Layout.V4.mapping ~root:snap_root ~generation
in
(* let src_prefix = Irmin_pack.Layout.V4.prefix ~root ~generation in
* let dst_prefix =
* Irmin_pack.Layout.V4.prefix ~root:snap_root ~generation
* in
* let src_mapping = Irmin_pack.Layout.V4.mapping ~root ~generation in
* let dst_mapping =
* Irmin_pack.Layout.V4.mapping ~root:snap_root ~generation
* in
* let () =
* Io.move_file ~src:src_prefix ~dst:dst_prefix |> Errs.raise_if_error
* in
* let () =
* Io.move_file ~src:src_mapping ~dst:dst_mapping |> Errs.raise_if_error
* in *)
let src_dict = Irmin_pack.Layout.V4.dict ~root in
let dst_dict = Irmin_pack.Layout.V4.dict ~root:snap_root in
let () =
Io.move_file ~src:src_prefix ~dst:dst_prefix |> Errs.raise_if_error
in
let () =
Io.move_file ~src:src_mapping ~dst:dst_mapping |> Errs.raise_if_error
in
let dst_dict = Irmin_pack.Layout.V4.dict ~root:snapshot_root in
let () =
Io.cp_file ~src:src_dict ~dst:dst_dict |> Errs.raise_if_error
in
(*TODO there is no new suffix with chunks. *)
let suffix =
Irmin_pack.Layout.V4.suffix_chunk ~root ~chunk_idx:generation
in
let () = Io.unlink suffix |> Errs.raise_if_error in
Lwt.return (t.offset, t.latest_gc_target_offset)
let () = create_new_suffix ~root:snapshot_root ~generation in
let latest_gc_target_offset = t.latest_gc_target_offset in
Lwt.return_unit
| _ ->
let gc_output = read_gc_output ~root:t.root ~generation:t.generation in
let r = gc_errors status gc_output |> Errs.raise_if_error in
Expand Down
15 changes: 10 additions & 5 deletions src/irmin-pack/unix/gc_worker.ml
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ module Make (Args : Gc_args.S) = struct
stats := Gc_stats.Worker.add_file_size !stats "mapping" mapping_size
in
(fun f ->
Mapping_file.create ~report_file_sizes ~root ~generation
Mapping_file.create ~report_file_sizes ~root:path_new_files ~generation
~register_entries:f ()
|> Errs.raise_if_error)
@@ fun ~register_entry ->
Expand Down Expand Up @@ -218,7 +218,9 @@ module Make (Args : Gc_args.S) = struct
(* Step 4. Create the new prefix. *)
stats := Gc_stats.Worker.finish_current_step !stats "prefix: start";
let prefix =
let path = Irmin_pack.Layout.V4.prefix ~root ~generation in
let path =
Irmin_pack.Layout.V4.prefix ~root:path_new_files ~generation
in
Ao.create_rw_exn ~path
in
let () =
Expand Down Expand Up @@ -252,7 +254,9 @@ module Make (Args : Gc_args.S) = struct
Dispatcher.read_exn dispatcher accessor buf
in
let prefix =
let path = Irmin_pack.Layout.V4.prefix ~root ~generation in
let path =
Irmin_pack.Layout.V4.prefix ~root:path_new_files ~generation
in
Io.open_ ~path ~readonly:false |> Errs.raise_if_error
in
Errors.finalise_exn (fun _outcome ->
Expand Down Expand Up @@ -330,10 +334,11 @@ module Make (Args : Gc_args.S) = struct

(* No one catches errors when this function terminates. Write the result in a
file and terminate. *)
let run_and_output_result ~generation root commit_key new_prefix_end_offset =
let run_and_output_result ~generation ~path_new_files root commit_key
new_prefix_end_offset =
let result =
Errs.catch (fun () ->
run ~generation root commit_key new_prefix_end_offset)
run ~generation ~path_new_files root commit_key new_prefix_end_offset)
in
let write_result = write_gc_output ~root ~generation result in
write_result |> Errs.log_if_error "writing gc output"
Expand Down

0 comments on commit 67cf48a

Please sign in to comment.