1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465(*
* Copyright (c) 2018-2021 Tarides <contact@tarides.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*)open!ImportmoduleIO=IO.Unixletlatest_version=`V2(** Migrate data from the IO [src] (with [name] in path [root_old]) into the
temporary dir [root_tmp], then swap in the replaced version. *)letmigrate_io_to_v2~progresssrc=IO.migrate~progresssrc`V2|>function|Ok()->IO.closesrc|Error(`Msgs)->invalid_argsletrunconfig=ifConf.readonlyconfigthenraiseS.RO_not_allowed;Log.debug(funl->l"[%s] migrate"(Conf.rootconfig));Layout.stores~root:(Conf.rootconfig)|>List.map(funstore->letio=IO.v~version:None~fresh:false~readonly:truestoreinletversion=IO.versionioin(store,io,version))|>List.partition(fun(_,_,v)->v=latest_version)|>function|migrated,[]->Log.info(funl->l"Store at %s is already in current version (%a)"(Conf.rootconfig)Version.pplatest_version);List.iter(fun(_,io,_)->IO.closeio)migrated|migrated,to_migrate->List.iter(fun(_,io,_)->IO.closeio)migrated;(matchmigratedwith|[]->()|_::_->letpp_ios=Fmt.(Dump.list(using(fun(n,_,_)->n)string))inLog.warn(funl->l"Store is in an inconsistent state: files %a have already been \
upgraded, but %a have not. Upgrading the remaining files now."pp_iosmigratedpp_iosto_migrate));lettotal=to_migrate|>List.map(fun(_,io,_)->IO.offsetio)|>List.fold_leftInt63.addInt63.zeroinletbar,progress=Utils.Progress.counter~total~sampling_interval:100~message:"Migrating store"~pp_count:Utils.pp_bytes()inList.iter(fun(_,io,_)->migrate_io_to_v2~progressio)to_migrate;Utils.Progress.finalisebar