Commit 28f0d906 authored by Romain's avatar Romain Committed by Romain

Node: add storage upgrade command

parent 5df5eabc
......@@ -63,6 +63,7 @@ let description =
`P Node_identity_command.Manpage.command_description;
`P Node_run_command.Manpage.command_description;
`P Node_config_command.Manpage.command_description;
`P Node_upgrade_command.Manpage.command_description;
`P Node_snapshot_command.Manpage.command_description;
`P Node_reconstruct_command.Manpage.command_description ]
......@@ -79,6 +80,7 @@ let commands =
[ Node_run_command.cmd;
Node_config_command.cmd;
Node_identity_command.cmd;
Node_upgrade_command.cmd;
Node_snapshot_command.cmd;
Node_reconstruct_command.cmd ]
......
......@@ -214,6 +214,32 @@ let ensure_data_dir bare data_dir =
| exc ->
raise exc)
let upgrade_data_dir data_dir =
ensure_data_dir false data_dir
>>=? function
| None ->
Format.printf "Node data dir is [email protected]" ;
return_unit
| Some (version, upgrade) -> (
Format.printf
"Upgrading node data dir from %s to %[email protected], do not interupt \
the [email protected]"
version
data_version ;
upgrade ~data_dir
>>= function
| Ok () ->
write_version data_dir
>>=? fun () ->
Format.printf "The node data dir is now [email protected]" ;
return_unit
| Error e ->
Format.printf
"%[email protected] upgrade. The storage was not [email protected]"
Error_monad.pp_print_error
e ;
return_unit )
let ensure_data_dir ?(bare = false) data_dir =
ensure_data_dir bare data_dir
>>=? function
......
......@@ -54,6 +54,11 @@ val default_peers_file_name : string
val ensure_data_dir : ?bare:bool -> string -> unit tzresult Lwt.t
(** Upgrade data directory from an older version.
Usage: [upgrade_data_dir dir] *)
val upgrade_data_dir : string -> unit tzresult Lwt.t
(** [store_dir dir] is a directory within [dir] that the node uses for its
store. In order for [store_dir dir] to be valid, [dir] must be a valid
directory name. *)
......
(*****************************************************************************)
(* *)
(* Open Source License *)
(* Copyright (c) 2018 Dynamic Ledger Solutions, Inc. <[email protected]> *)
(* *)
(* Permission is hereby granted, free of charge, to any person obtaining a *)
(* copy of this software and associated documentation files (the "Software"),*)
(* to deal in the Software without restriction, including without limitation *)
(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *)
(* and/or sell copies of the Software, and to permit persons to whom the *)
(* Software is furnished to do so, subject to the following conditions: *)
(* *)
(* The above copyright notice and this permission notice shall be included *)
(* in all copies or substantial portions of the Software. *)
(* *)
(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*)
(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *)
(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *)
(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*)
(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *)
(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *)
(* DEALINGS IN THE SOFTWARE. *)
(* *)
(*****************************************************************************)
let ( // ) = Filename.concat
(** Main *)
module Term = struct
type upgrade = Storage
let subcommand_arg =
let parser = function
| "storage" ->
`Ok Storage
| s ->
`Error ("invalid argument: " ^ s)
and printer ppf = function Storage -> Format.fprintf ppf "storage" in
let open Cmdliner.Arg in
let doc = "Upgrade to perform. Possible values: $(b, storage)." in
required
& pos 0 (some (parser, printer)) None
& info [] ~docv:"UPGRADE" ~doc
let process subcommand data_dir config_file =
match subcommand with
| Storage -> (
let run =
( match data_dir with
| Some data_dir ->
return data_dir
| None -> (
match config_file with
| None ->
let default_config =
Node_config_file.default_data_dir // "config.json"
in
if Sys.file_exists default_config then
Node_config_file.read default_config
>>=? fun cfg -> return cfg.data_dir
else return Node_config_file.default_data_dir
| Some config_file ->
Node_config_file.read config_file
>>=? fun cfg -> return cfg.data_dir ) )
>>=? fun data_dir ->
trace
(failure
"Fail to lock the data directory. Is a `tezos-node` running?")
@@ Lwt_lock_file.create
~unlink_on_exit:true
(Node_data_version.lock_file data_dir)
>>=? fun () -> Node_data_version.upgrade_data_dir data_dir
in
match Lwt_main.run run with
| Ok () ->
`Ok ()
| Error err ->
`Error (false, Format.asprintf "%a" pp_print_error err) )
let term =
Cmdliner.Term.(
ret
( const process $ subcommand_arg $ Node_shared_arg.Term.data_dir
$ Node_shared_arg.Term.config_file ))
end
module Manpage = struct
let command_description =
"The $(b,upgrade) command is meant to manage upgrades of the node."
let description =
[ `S "DESCRIPTION";
`P command_description;
`P "Available upgrades are:";
`P "$(b,storage) will upgrade the node disk storage (if needed)." ]
let man = description @ (* [ `S misc_docs ] @ *)
Node_shared_arg.Manpage.bugs
let info = Cmdliner.Term.info ~doc:"Manage node upgrades" ~man "upgrade"
end
let cmd = (Term.term, Manpage.info)
(*****************************************************************************)
(* *)
(* Open Source License *)
(* Copyright (c) 2018 Dynamic Ledger Solutions, Inc. <[email protected]> *)
(* *)
(* Permission is hereby granted, free of charge, to any person obtaining a *)
(* copy of this software and associated documentation files (the "Software"),*)
(* to deal in the Software without restriction, including without limitation *)
(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *)
(* and/or sell copies of the Software, and to permit persons to whom the *)
(* Software is furnished to do so, subject to the following conditions: *)
(* *)
(* The above copyright notice and this permission notice shall be included *)
(* in all copies or substantial portions of the Software. *)
(* *)
(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*)
(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *)
(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *)
(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*)
(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *)
(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *)
(* DEALINGS IN THE SOFTWARE. *)
(* *)
(*****************************************************************************)
val cmd : unit Cmdliner.Term.t * Cmdliner.Term.info
module Manpage : sig
val command_description : string
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment