Commit 5df5eabc authored by Romain's avatar Romain Committed by Romain

Node: add storage upgrade function from 0.0.3

parent c577b507
......@@ -27,20 +27,6 @@ let ( // ) = Filename.concat
type t = string
(* Data_version hitory:
* - 0.0.1 : original storage
* - 0.0.2 : never released
* - 0.0.3 : store upgrade (introducing history mode)
* - 0.0.4 : context upgrade (switching from LMDB to IRMIN v2) *)
let data_version = "0.0.4"
(* List of upgrade functions from each still supported previous
version to the current [data_version] above. If this list grows too
much, an idea would be to have triples (version, version,
converter), and to sequence them dynamically instead of
statically. *)
let upgradable_data_version = []
let store_dir data_dir = data_dir // "store"
let context_dir data_dir = data_dir // "context"
......@@ -57,6 +43,23 @@ let default_config_file_name = "config.json"
let version_file_name = "version.json"
(* Data_version hitory:
* - 0.0.1 : original storage
* - 0.0.2 : never released
* - 0.0.3 : store upgrade (introducing history mode)
* - 0.0.4 : context upgrade (switching from LMDB to IRMIN v2) *)
let data_version = "0.0.4"
(* List of upgrade functions from each still supported previous
version to the current [data_version] above. If this list grows too
much, an idea would be to have triples (version, version,
converter), and to sequence them dynamically instead of
statically. *)
let upgradable_data_version =
[ ( "0.0.3",
fun ~data_dir ->
Context.upgrade_0_0_3 ~context_dir:(context_dir data_dir) ) ]
let version_encoding = Data_encoding.(obj1 (req "version" string))
type error += Invalid_data_dir_version of t * t
......@@ -86,7 +89,8 @@ let () =
~pp:(fun ppf (exp, got) ->
Format.fprintf
ppf
"Invalid data directory version '%s' (expected '%s')."
"Invalid data directory version '%s' (expected '%s')[email protected],\
Your data directory is outdated and cannot be automatically upgraded."
got
exp)
Data_encoding.(
......
......@@ -912,3 +912,33 @@ let restore_contexts idx ~filename k_store_pruned_block pipeline_validation =
if current = total then return result
else fail @@ Suspicious_file (total - current))
(fun () -> Lwt_unix.close fd)
let upgrade_0_0_3 ~context_dir =
Lwt_unix.file_exists (context_dir ^ "/" ^ "data.mdb")
(* We assume that the data.mdb file is representative of a lmdb context *)
>>= fun is_lmdb ->
Lwt_unix.file_exists (context_dir ^ "/" ^ "store.pack")
(* We assume that the store.pack file is representative of an irmin context *)
>>= fun is_irmin ->
match (is_lmdb, is_irmin) with
| (true, true) ->
Format.printf
"Your directory containts both the LMDB and Irmin2 chain's data. From \
now, the node only uses Irmin2. LMDB data can be safely removed. To \
do so, delete the following files: %s/data.mdb and %s/[email protected]"
context_dir
context_dir ;
return_unit
| (true, false) ->
failwith
"Your directory contains the lmdb database which cannot be handled \
with this version of the node. Please upgrade to the new irmin \
[email protected] guide to upgrade toward the new storage can be found \
here: http://tezos.gitlab.io/releases/october-2019.html"
| (false, true) ->
return_unit
| (false, false) ->
failwith
"Cannot find any context data in the provided directory (located at: \
%s). Please make sure that the path to the storage is correct."
context_dir
......@@ -210,3 +210,5 @@ val validate_context_hash_consistency_and_commit :
parents:Context_hash.t list ->
index:index ->
bool Lwt.t
val upgrade_0_0_3 : context_dir:string -> unit tzresult Lwt.t
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