diff --git a/Cargo.lock b/Cargo.lock index 0dc85f11d5..a43c0c7250 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4903,6 +4903,19 @@ dependencies = [ "solana-transaction-status", ] +[[package]] +name = "solana-store-tool" +version = "1.5.0" +dependencies = [ + "clap", + "log 0.4.8", + "solana-logger 1.5.0", + "solana-measure", + "solana-runtime", + "solana-sdk 1.5.0", + "solana-version", +] + [[package]] name = "solana-streamer" version = "1.5.0" diff --git a/Cargo.toml b/Cargo.toml index 03ed4b4d93..9be04547b5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -53,6 +53,7 @@ members = [ "remote-wallet", "ramp-tps", "runtime", + "runtime/store-tool", "sdk", "sdk/cargo-build-bpf", "scripts", diff --git a/runtime/src/append_vec.rs b/runtime/src/append_vec.rs index 2a21023cbc..825ecf287d 100644 --- a/runtime/src/append_vec.rs +++ b/runtime/src/append_vec.rs @@ -111,11 +111,14 @@ pub struct AppendVec { append_offset: Mutex, current_len: AtomicUsize, file_size: u64, + remove_on_drop: bool, } impl Drop for AppendVec { fn drop(&mut self) { - let _ignored = remove_file(&self.path); + if self.remove_on_drop { + let _ignored = remove_file(&self.path); + } } } @@ -176,11 +179,16 @@ impl AppendVec { append_offset: Mutex::new(initial_len), current_len: AtomicUsize::new(initial_len), file_size: size as u64, + remove_on_drop: true, } } + pub fn set_no_remove_on_drop(&mut self) { + self.remove_on_drop = false; + } + #[allow(clippy::mutex_atomic)] - pub(crate) fn new_empty_map(current_len: usize) -> Self { + pub fn new_empty_map(current_len: usize) -> Self { let map = MmapMut::map_anon(1).unwrap_or_else(|e| { error!( "Failed to create VM map for snapshot. {:?}\n @@ -196,6 +204,7 @@ impl AppendVec { append_offset: Mutex::new(current_len), current_len: AtomicUsize::new(current_len), file_size: 0, // will be filled by set_file() + remove_on_drop: true, } } diff --git a/runtime/store-tool/Cargo.toml b/runtime/store-tool/Cargo.toml new file mode 100644 index 0000000000..feba8d9d8f --- /dev/null +++ b/runtime/store-tool/Cargo.toml @@ -0,0 +1,22 @@ +[package] +authors = ["Solana Maintainers "] +edition = "2018" +name = "solana-store-tool" +description = "Tool to inspect append vecs" +version = "1.5.0" +repository = "https://github.com/solana-labs/solana" +license = "Apache-2.0" +homepage = "https://solana.com/" +publish = false + +[dependencies] +log = { version = "0.4.8" } +solana-logger = { path = "../../logger", version = "1.5.0" } +solana-version = { path = "../../version", version = "1.5.0" } +solana-measure = { path = "../../measure", version = "1.5.0" } +solana-runtime = { path = "..", version = "1.5.0" } +solana-sdk = { path = "../../sdk", version = "1.5.0" } +clap = "2.33.1" + +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] diff --git a/runtime/store-tool/src/main.rs b/runtime/store-tool/src/main.rs new file mode 100644 index 0000000000..6b26444f37 --- /dev/null +++ b/runtime/store-tool/src/main.rs @@ -0,0 +1,47 @@ +use clap::{crate_description, crate_name, value_t_or_exit, App, Arg}; +use log::*; +use solana_runtime::append_vec::AppendVec; + +fn main() { + solana_logger::setup_with_default("solana=info"); + let matches = App::new(crate_name!()) + .about(crate_description!()) + .version(solana_version::version!()) + .arg( + Arg::with_name("file") + .long("file") + .takes_value(true) + .value_name("") + .help("store to open"), + ) + .arg( + Arg::with_name("len") + .long("len") + .takes_value(true) + .value_name("LEN") + .help("len of store to open"), + ) + .get_matches(); + + let file = value_t_or_exit!(matches, "file", String); + let len = value_t_or_exit!(matches, "len", usize); + let mut store = AppendVec::new_empty_map(len); + store.set_no_remove_on_drop(); + store.set_file(file).expect("set_file failed"); + let accounts = store.accounts(0); + info!( + "store: len: {} capacity: {} accounts: {}", + store.len(), + store.capacity(), + accounts.len() + ); + for account in store.accounts(0) { + info!( + " account: {:?} version: {} data: {} hash: {:?}", + account.meta.pubkey, account.meta.write_version, account.meta.data_len, account.hash + ); + } +} + +#[cfg(test)] +pub mod test {}