Skip to content

Commit

Permalink
update gc callback
Browse files Browse the repository at this point in the history
  • Loading branch information
metanivek committed Aug 5, 2022
1 parent e723622 commit afb4d71
Showing 1 changed file with 6 additions and 45 deletions.
51 changes: 6 additions & 45 deletions src/lib_context/disk/context.ml
Original file line number Diff line number Diff line change
Expand Up @@ -274,48 +274,10 @@ module Make (Encoding : module type of Tezos_context_encoding.Context) = struct
let commit = P.Commit_portable.v ~parents ~node ~info in
Hash.to_context_hash (Commit_hash.hash commit)

let finalise_gc_and_log repo context_hash =
let open Lwt_syntax in
let catch_errors error =
let error_msg =
match error with
| Irmin.Closed -> "Closed"
| Irmin_pack.RO_not_allowed -> "RO_not_allowed"
| Irmin_pack_unix.Errors.Pack_error error ->
(
Fmt.str "Pack_error: %a" Irmin_pack_unix.Errors.pp_base_error error
)
| Unix.Unix_error (err, s1, s2) ->
let pp = Irmin.Type.pp Irmin_pack_unix.Io.Unix.misc_error_t in
Fmt.str "Unix_error: %a" pp (err, s1, s2)
| exn -> raise exn
in
Format.printf "Finalising Gc resulted in error %s@." error_msg ;
Lwt.return_unit
in
Lwt.catch
(fun () ->
let c0 = Mtime_clock.counter () in
let* wait = Store.Gc.finalise_exn ~wait:false repo in
let span = Mtime_clock.count c0 |> Mtime.Span.to_ms in
let () = match wait with | `Finalised stats ->
Format.printf
"Gc ended on commit %a, gc took %.4fms finalisation %.4fms@."
Context_hash.pp
context_hash
stats.Store.Gc.duration
span
| _ -> ()
in
Lwt.return_unit)
catch_errors

let commit ~time ?message context =
let open Lwt_syntax in
let* commit = raw_commit ~time ?message context in
let hash = Hash.to_context_hash (Store.Commit.hash commit) in
let+ () = finalise_gc_and_log context.index.repo hash in
hash
let+ commit = raw_commit ~time ?message context in
Hash.to_context_hash (Store.Commit.hash commit)

let gc index context_hash =
let open Lwt_syntax in
Expand All @@ -332,11 +294,10 @@ module Make (Encoding : module type of Tezos_context_encoding.Context) = struct
let finished = function
| Ok stats ->
Logs.info (fun m ->
m
"GC ended. %a@."
(Irmin.Type.pp Store.Gc.stats_t) stats
)
| Error (`Msg err) -> Logs.warn (fun m -> m "GC failed, %s@." err)
m "GC ended. %a@." (Irmin.Type.pp Store.Gc.stats_t) stats)
|> Lwt.return
| Error (`Msg err) ->
Logs.warn (fun m -> m "GC failed, %s@." err) |> Lwt.return
in
let commit_key = Store.Commit.key commit in
let* launch_result = Store.Gc.run ~finished repo commit_key in
Expand Down

0 comments on commit afb4d71

Please sign in to comment.