From 6814d78ecb23551011272d153c5759f00bc37ede Mon Sep 17 00:00:00 2001 From: Alain Mebsout Date: Tue, 9 Jan 2024 11:42:57 +0100 Subject: [PATCH] Rollup node: Allow to specify name of exported snapshot file --- .../main_smart_rollup_node.ml | 57 +++++++++++++------ src/lib_smart_rollup_node/cli.ml | 2 +- src/lib_smart_rollup_node/snapshots.ml | 33 +++++++---- src/lib_smart_rollup_node/snapshots.mli | 12 ++-- 4 files changed, 69 insertions(+), 35 deletions(-) diff --git a/src/bin_smart_rollup_node/main_smart_rollup_node.ml b/src/bin_smart_rollup_node/main_smart_rollup_node.ml index ca00ae787f6b..ef8fbdee5fce 100644 --- a/src/bin_smart_rollup_node/main_smart_rollup_node.ml +++ b/src/bin_smart_rollup_node/main_smart_rollup_node.ml @@ -374,7 +374,25 @@ let dump_durable_storage = return_unit | Error errs -> cctxt#error "%a" pp_print_trace errs) -let export_snapshot = +let export_snapshot + (data_dir, dest, no_checks, compress_on_the_fly, uncompressed) filename + (cctxt : Client_context.full) = + let open Lwt_result_syntax in + let*! compression = + match (compress_on_the_fly, uncompressed) with + | true, true -> + cctxt#error "Cannot have both --uncompressed and --compress-on-the-fly" + | true, false -> Lwt.return Snapshots.On_the_fly + | false, false -> Lwt.return Snapshots.After + | false, true -> Lwt.return Snapshots.No + in + let* snapshot_file = + Snapshots.export ~no_checks ~compression ~data_dir ~dest ~filename + in + let*! () = cctxt#message "Snapshot exported to %s@." snapshot_file in + return_unit + +let export_snapshot_auto_name = let open Tezos_clic in command ~group @@ -386,22 +404,24 @@ let export_snapshot = Cli.compress_on_the_fly_arg Cli.uncompressed) (prefixes ["snapshot"; "export"] @@ stop) - (fun (data_dir, dest, no_checks, compress_on_the_fly, uncompressed) cctxt -> - let open Lwt_result_syntax in - let*! compression = - match (compress_on_the_fly, uncompressed) with - | true, true -> - cctxt#error - "Cannot have both --uncompressed and --compress-on-the-fly" - | true, false -> Lwt.return Snapshots.On_the_fly - | false, false -> Lwt.return Snapshots.After - | false, true -> Lwt.return Snapshots.No - in - let* snapshot_file = - Snapshots.export ~no_checks ~compression ~data_dir ~dest - in - let*! () = cctxt#message "Snapshot exported to %s@." snapshot_file in - return_unit) + (fun params cctxt -> export_snapshot params None cctxt) + +let export_snapshot_named = + let open Tezos_clic in + command + ~group + ~desc:"Export a snapshot of the rollup node state to a given file." + (args4 + data_dir_arg + Cli.no_checks_arg + Cli.compress_on_the_fly_arg + Cli.uncompressed) + (prefixes ["snapshot"; "export"] @@ Cli.snapshot_file_param @@ stop) + (fun (data_dir, no_checks, compress_on_the_fly, uncompressed) filename cctxt -> + export_snapshot + (data_dir, None, no_checks, compress_on_the_fly, uncompressed) + (Some filename) + cctxt) let import_snapshot = let open Tezos_clic in @@ -437,7 +457,8 @@ let sc_rollup_commands () = protocols_command; dump_metrics; dump_durable_storage; - export_snapshot; + export_snapshot_auto_name; + export_snapshot_named; import_snapshot; openapi_command; ] diff --git a/src/lib_smart_rollup_node/cli.ml b/src/lib_smart_rollup_node/cli.ml index ce073fee4373..c012b8af68d6 100644 --- a/src/lib_smart_rollup_node/cli.ml +++ b/src/lib_smart_rollup_node/cli.ml @@ -408,7 +408,7 @@ let snapshot_dir_arg = let snapshot_file_param next = Tezos_clic.param - ~name:"" + ~name:"snapshot_file" ~desc:"Snapshot archive file" string_parameter next diff --git a/src/lib_smart_rollup_node/snapshots.ml b/src/lib_smart_rollup_node/snapshots.ml index b839494b86f9..7924bf23eb93 100644 --- a/src/lib_smart_rollup_node/snapshots.ml +++ b/src/lib_smart_rollup_node/snapshots.ml @@ -426,7 +426,7 @@ let snapshotable_files_regexp = Re.Str.regexp "^\\(storage/.*\\|context/.*\\|wasm_2_0_0/.*\\|arith/.*\\|context/.*\\|metadata$\\)" -let export ~no_checks ~compression ~data_dir ~dest = +let export ~no_checks ~compression ~data_dir ~dest ~filename = let open Lwt_result_syntax in let* snapshot_file = Format.eprintf "Acquiring GC lock@." ; @@ -436,17 +436,28 @@ let export ~no_checks ~compression ~data_dir ~dest = Utils.with_lockfile (Node_context.processing_lockfile_path ~data_dir) @@ fun () -> let* metadata = pre_export_checks_and_get_snapshot_metadata ~data_dir in - let suffix = - match compression with On_the_fly -> "" | No | After -> ".uncompressed" - in let dest_file_name = - Format.asprintf - "snapshot-%a-%ld.%s%s" - Address.pp_short - metadata.address - metadata.head_level - (Configuration.string_of_history_mode metadata.history_mode) - suffix + match filename with + | Some f -> + let suffix = + match compression with + | No | On_the_fly -> "" + | After -> ".uncompressed" + in + f ^ suffix + | None -> + let suffix = + match compression with + | On_the_fly -> "" + | No | After -> ".uncompressed" + in + Format.asprintf + "snapshot-%a-%ld.%s%s" + Address.pp_short + metadata.address + metadata.head_level + (Configuration.string_of_history_mode metadata.history_mode) + suffix in let dest_file = match dest with diff --git a/src/lib_smart_rollup_node/snapshots.mli b/src/lib_smart_rollup_node/snapshots.mli index a4ab2eec1f68..a445ed33afb8 100644 --- a/src/lib_smart_rollup_node/snapshots.mli +++ b/src/lib_smart_rollup_node/snapshots.mli @@ -17,16 +17,18 @@ type compression = temporarily than {!On_the_fly} but does not lock the rollup node for very long. *) -(** [export ~no_checks ~compression ~data_dir ~dest] creates a tar gzipped - archive in [dest] (or the current directory) containing a snapshot of the - data of the rollup node with data directory [data_dir]. The path of the - snapshot archive is returned. If [no_checks] is [true], the integrity of the - snapshot is not checked at the end. *) +(** [export ~no_checks ~compression ~data_dir ~dest ~filename] creates a tar + gzipped archive with name [filename] (or a generated name) in [dest] (or the + current directory) containing a snapshot of the data of the rollup node with + data directory [data_dir]. The path of the snapshot archive is returned. If + [no_checks] is [true], the integrity of the snapshot is not checked at the + end. *) val export : no_checks:bool -> compression:compression -> data_dir:string -> dest:string option -> + filename:string option -> string tzresult Lwt.t (** [import ?no_checks cctxt ~data_dir ~snapshot_file] imports the snapshot at -- GitLab