Skip to content

Commit

Permalink
[tools] Restore cmd to take version (#1093)
Browse files Browse the repository at this point in the history
* update restore command to reeceive a version number

* gitignore mv files

* update restore path format

* ol check will print db version

* restore works with multiple versions in a restore bundle

* ol restore takes highest transaction version if there are multiple

* update order of tx restore

* patch default restore

* add resetting of safety data
  • Loading branch information
0o-de-lally authored Jun 1, 2022
1 parent ead6790 commit ad9c806
Show file tree
Hide file tree
Showing 7 changed files with 302 additions and 192 deletions.
13 changes: 12 additions & 1 deletion config/management/genesis/src/key.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// Copyright (c) The Diem Core Contributors
// SPDX-License-Identifier: Apache-2.0

use consensus_types::safety_data::SafetyData;
use diem_crypto::ed25519::Ed25519PublicKey;
use diem_global_constants::{GENESIS_WAYPOINT, OPERATOR_ACCOUNT, OWNER_ACCOUNT, WAYPOINT};
use diem_global_constants::{GENESIS_WAYPOINT, OPERATOR_ACCOUNT, OWNER_ACCOUNT, WAYPOINT, SAFETY_DATA};
use diem_management::{
config::ConfigPath,
error::Error,
Expand Down Expand Up @@ -91,6 +92,16 @@ pub fn set_owner_key(path: &PathBuf, namespace: &str, account: AccountAddress) {

}

//////// 0L /////////
pub fn reset_safety_data(path: &PathBuf, namespace: &str) {
let mut storage = diem_secure_storage::Storage::OnDiskStorage(
OnDiskStorage::new(path.join("key_store.json").to_owned())
);
let key = &format!("{}/{}", namespace, SAFETY_DATA);
storage
.set(key, SafetyData::new(0, 0, 0, None))
.unwrap();
}

//////// 0L /////////
pub fn set_waypoint(path: &PathBuf, namespace: &str, waypoint: Waypoint) {
Expand Down
41 changes: 1 addition & 40 deletions ol/cli/src/check/pilot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,50 +3,11 @@
#![allow(clippy::never_loop)]
use crate::node::states::*;
use crate::{
mgmt::{self, management::NodeMode::*},
mgmt::management::NodeMode::*,
node::node::Node,
};
use std::{thread, time::Duration};

/// check if we need to restore the db
pub fn maybe_restore_db(mut node: &mut Node, verbose: bool) -> &mut Node {
let cfg = node.app_conf.to_owned();
// Abort if the database is not set correctly.
node.vitals.host_state.onboard_state = OnboardState::EmptyBox;

if node.db_files_exist() {
node.vitals.host_state.onboard_state = OnboardState::DbFilesOk;

if verbose {
println!("DB: db files exist");
}
// is DB bootstrapped
if node.db_bootstrapped() {
node.vitals.host_state.onboard_state = OnboardState::DbBootstrapOk;
if verbose {
println!("DB: db bootstrapped");
}
} else {
if verbose {
println!("DB: WARN: diemDB is not bootstrapped. Database needs a valid set of transactions to boot. Attempting `ol restore` to fetch backups from archive.");
}
mgmt::restore::fast_forward_db(true, None).unwrap();
node.vitals.host_state.onboard_state = OnboardState::DbBootstrapOk;
}
// return
} else {
if verbose {
println!(
"NO db files found {:?}. Attempting `ol restore` to fetch backups from archive.",
&cfg.workspace.node_home
);
}
mgmt::restore::fast_forward_db(true, None).unwrap();
node.vitals.host_state.onboard_state = OnboardState::DbBootstrapOk;
}
node
}

/// run once
pub fn run_once(mut node: &mut Node, verbose: bool) -> &mut Node {
if verbose {
Expand Down
2 changes: 2 additions & 0 deletions ol/cli/src/check/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ Configs exist: {configs}
DB restored: {restored}
Web monitor: {web_running}
Is synced: {synced}
Local DB Version: {version}
Sync delay: {delay}
Node running: {node}
Tower running: {miner}
Expand All @@ -67,6 +68,7 @@ In validator set: {in_set}
restored = node.vitals.items.db_restored,
web_running = node.vitals.items.web_running,
synced = node.vitals.items.is_synced,
version = node.vitals.items.sync_height,
delay = node.vitals.items.sync_delay,
node = node.vitals.items.node_running,
miner = node.vitals.items.miner_running,
Expand Down
11 changes: 9 additions & 2 deletions ol/cli/src/commands/restore_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,23 @@ use crate::mgmt;
/// <https://docs.rs/gumdrop/>
#[derive(Command, Debug, Options)]
pub struct RestoreCmd {
#[options(short="v", help = "verbose logging of backup restore")]
#[options(help = "verbose logging of backup restore")]
verbose: bool,

#[options(short="e", help = "what epoch to start restore from")]
epoch: Option<u64>,

#[options(short="v", help = "specify a version or height if there is more than one per archive")]
version: Option<u64>,

#[options(help = "get only the exact last block at the end of an epoch. Not extra blocks at the start of following epoch.")]
exclude_buffer: bool,
}

impl Runnable for RestoreCmd {
/// Start the application.
fn run(&self) {
match mgmt::restore::fast_forward_db(self.verbose, self.epoch) {
match mgmt::restore::fast_forward_db(self.verbose, self.epoch, self.version) {
Ok(_) => {},
Err(e) => println!("ERROR: could not complete db restore, message: {:?}", e),
};
Expand Down
Loading

0 comments on commit ad9c806

Please sign in to comment.