From afb4d71cb4c387d8ba1e5ae741b1dfb9ab0ebe32 Mon Sep 17 00:00:00 2001 From: metanivek Date: Fri, 5 Aug 2022 19:03:10 +0200 Subject: [PATCH] update gc callback --- src/lib_context/disk/context.ml | 51 ++++----------------------------- 1 file changed, 6 insertions(+), 45 deletions(-) diff --git a/src/lib_context/disk/context.ml b/src/lib_context/disk/context.ml index bad6417664..597aa5142d 100644 --- a/src/lib_context/disk/context.ml +++ b/src/lib_context/disk/context.ml @@ -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 @@ -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