-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[storage] reassemble db restore tool into storage-cli (#304)
- Loading branch information
1 parent
8164cd2
commit 7c7a82a
Showing
19 changed files
with
449 additions
and
61 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,7 @@ | ||
[workspace] | ||
resolver = "2" | ||
|
||
members = [ | ||
"diem-node-proxy" | ||
] | ||
members = ["diem-node-proxy"] | ||
|
||
[workspace.dependencies] | ||
diem-node = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "release" } | ||
diem-node = { workspace = true } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file added
BIN
+13.9 MB
tools/storage/fixtures/v7/transaction_38100001-.541f/38100001-.chunk.gz
Binary file not shown.
Binary file added
BIN
+1.04 KB
tools/storage/fixtures/v7/transaction_38100001-.541f/38100001-38200000.proof
Binary file not shown.
Binary file added
BIN
+797 Bytes
tools/storage/fixtures/v7/transaction_38100001-.541f/38100001-38200000.proof.gz
Binary file not shown.
1 change: 1 addition & 0 deletions
1
tools/storage/fixtures/v7/transaction_38100001-.541f/transaction.manifest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"first_version":38100001,"last_version":38200000,"chunks":[{"first_version":38100001,"last_version":38200000,"transactions":"transaction_38100001-.541f/38100001-.chunk","proof":"transaction_38100001-.541f/38100001-38200000.proof"}]} |
Binary file added
BIN
+114 Bytes
tools/storage/fixtures/v7/transaction_38100001-.541f/transaction.manifest.gz
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
//! refactoring the internals of Vendor DBTool::Oneoff | ||
//! source: <diem> storage/db-tool/src/restore.rs | ||
use crate::restore_bundle::RestoreBundle; | ||
|
||
use std::{ | ||
path::{Path, PathBuf}, | ||
sync::Arc, | ||
}; | ||
|
||
use anyhow::Result; | ||
use diem_backup_cli::{ | ||
backup_types::{ | ||
epoch_ending::restore::{EpochEndingRestoreController, EpochEndingRestoreOpt}, | ||
state_snapshot::restore::{StateSnapshotRestoreController, StateSnapshotRestoreOpt}, | ||
transaction::restore::{TransactionRestoreController, TransactionRestoreOpt}, | ||
}, | ||
storage::{local_fs::LocalFs, BackupStorage}, | ||
utils::{GlobalRestoreOptions, RestoreRunMode, TrustedWaypointOpt}, | ||
}; | ||
use diem_config::config::{ | ||
RocksdbConfigs, BUFFERED_STATE_TARGET_ITEMS, DEFAULT_MAX_NUM_NODES_PER_LRU_CACHE_SHARD, | ||
NO_OP_STORAGE_PRUNER_CONFIG, | ||
}; | ||
use diem_db::{state_restore::StateSnapshotRestoreMode, DiemDB, GetRestoreHandler}; | ||
use diem_executor_types::VerifyExecutionMode; | ||
|
||
/// types of db restore. Note: all of them are necessary for a successful restore. | ||
pub enum RestoreTypes { | ||
Epoch, | ||
Snapshot, | ||
Transaction, | ||
} | ||
|
||
pub fn get_backup_storage(local_fs_dir: PathBuf) -> Result<Arc<dyn BackupStorage>> { | ||
Ok(Arc::new(LocalFs::new(local_fs_dir))) | ||
} | ||
|
||
pub fn get_global_db_opts( | ||
db_dir: &Path, | ||
bundle: &RestoreBundle, | ||
) -> anyhow::Result<GlobalRestoreOptions> { | ||
let restore_handler = Arc::new(DiemDB::open_kv_only( | ||
db_dir.to_owned(), | ||
false, /* read_only */ | ||
NO_OP_STORAGE_PRUNER_CONFIG, /* pruner config */ | ||
RocksdbConfigs::default(), | ||
false, | ||
BUFFERED_STATE_TARGET_ITEMS, | ||
DEFAULT_MAX_NUM_NODES_PER_LRU_CACHE_SHARD, | ||
)?) | ||
.get_restore_handler(); | ||
|
||
let run_mode = RestoreRunMode::Restore { restore_handler }; | ||
|
||
let twp = TrustedWaypointOpt { | ||
trust_waypoint: vec![bundle.waypoint.expect("no waypoint")], | ||
}; | ||
|
||
Ok(GlobalRestoreOptions { | ||
target_version: bundle.version, | ||
trusted_waypoints: Arc::new(twp.verify().expect("cannot verify waypoint")), | ||
run_mode: Arc::new(run_mode), | ||
concurrent_downloads: num_cpus::get(), | ||
replay_concurrency_level: 4, | ||
}) | ||
} | ||
|
||
pub async fn run_restore( | ||
rtype: RestoreTypes, | ||
db_path: &Path, | ||
bundle: &RestoreBundle, | ||
) -> anyhow::Result<()> { | ||
let global = get_global_db_opts(db_path, bundle)?; | ||
|
||
let storage = get_backup_storage(bundle.restore_bundle_dir.to_path_buf())?; | ||
|
||
match rtype { | ||
RestoreTypes::Epoch => { | ||
EpochEndingRestoreController::new( | ||
EpochEndingRestoreOpt { | ||
manifest_handle: bundle.epoch_manifest.to_str().unwrap().to_string(), | ||
}, | ||
global, | ||
storage, | ||
) | ||
.run(None) | ||
.await?; | ||
} | ||
RestoreTypes::Snapshot => { | ||
StateSnapshotRestoreController::new( | ||
StateSnapshotRestoreOpt { | ||
manifest_handle: bundle.snapshot_manifest.to_str().unwrap().to_string(), | ||
version: bundle.version, | ||
validate_modules: false, | ||
restore_mode: StateSnapshotRestoreMode::Default, | ||
}, | ||
global, | ||
storage, | ||
None, /* epoch_history */ | ||
) | ||
.run() | ||
.await?; | ||
} | ||
RestoreTypes::Transaction => { | ||
TransactionRestoreController::new( | ||
TransactionRestoreOpt { | ||
manifest_handle: bundle.transaction_manifest.to_str().unwrap().to_string(), | ||
replay_from_version: None, | ||
kv_only_replay: None, | ||
}, | ||
global, | ||
storage, | ||
None, /* epoch_history */ | ||
VerifyExecutionMode::NoVerify, | ||
) | ||
.run() | ||
.await?; | ||
} | ||
} | ||
Ok(()) | ||
} | ||
|
||
// TODO: perhaps deprecated since this test is nearly identical to restore::test_full_restore | ||
#[tokio::test] | ||
async fn test_restore() -> anyhow::Result<()> { | ||
let dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")); | ||
let mut b = RestoreBundle::new(dir.join("fixtures/v7")); | ||
b.load()?; | ||
let db_temp = diem_temppath::TempPath::new(); | ||
db_temp.create_as_dir().unwrap(); | ||
run_restore(RestoreTypes::Epoch, db_temp.path(), &b).await?; | ||
run_restore(RestoreTypes::Snapshot, db_temp.path(), &b).await?; | ||
run_restore(RestoreTypes::Transaction, db_temp.path(), &b).await?; | ||
|
||
assert!(db_temp.path().join("ledger_db").exists()); | ||
assert!(db_temp.path().join("state_merkle_db").exists()); | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
pub mod dbtool_init; | ||
pub mod read_snapshot; | ||
pub mod restore; | ||
pub mod restore_bundle; | ||
pub mod storage_cli; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Do a full restoration given a RestoreBundle with verified manifests | ||
|
||
use std::path::Path; | ||
|
||
use crate::{ | ||
dbtool_init::{run_restore, RestoreTypes}, | ||
restore_bundle::RestoreBundle, | ||
}; | ||
|
||
pub async fn full_restore(db_destination: &Path, bundle: &RestoreBundle) -> anyhow::Result<()> { | ||
assert!( | ||
bundle.is_loaded(), | ||
"the restore bundle hasn't been checked yet" | ||
); | ||
|
||
run_restore(RestoreTypes::Epoch, db_destination, bundle).await?; | ||
run_restore(RestoreTypes::Snapshot, db_destination, bundle).await?; | ||
run_restore(RestoreTypes::Transaction, db_destination, bundle).await?; | ||
|
||
Ok(()) | ||
} | ||
|
||
#[tokio::test] | ||
async fn test_full_restore() -> anyhow::Result<()> { | ||
use std::path::PathBuf; | ||
let dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")); | ||
let mut b = RestoreBundle::new(dir.join("fixtures/v7")); | ||
b.load().unwrap(); | ||
let mut db_temp = diem_temppath::TempPath::new(); | ||
db_temp.persist(); | ||
db_temp.create_as_dir()?; | ||
|
||
full_restore(db_temp.path(), &b).await?; | ||
|
||
assert!(db_temp.path().join("ledger_db").exists()); | ||
assert!(db_temp.path().join("state_merkle_db").exists()); | ||
Ok(()) | ||
} |
Oops, something went wrong.