@ -1,5 +1,6 @@
|
|||||||
use crate::result::{Error, Result};
|
use crate::result::{Error, Result};
|
||||||
use crate::service::Service;
|
use crate::service::Service;
|
||||||
|
use solana_measure::measure::Measure;
|
||||||
use solana_runtime::accounts_db::AccountStorageEntry;
|
use solana_runtime::accounts_db::AccountStorageEntry;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::io::{Error as IOError, ErrorKind};
|
use std::io::{Error as IOError, ErrorKind};
|
||||||
@ -19,6 +20,7 @@ pub const TAR_SNAPSHOTS_DIR: &str = "snapshots";
|
|||||||
pub const TAR_ACCOUNTS_DIR: &str = "accounts";
|
pub const TAR_ACCOUNTS_DIR: &str = "accounts";
|
||||||
|
|
||||||
pub struct SnapshotPackage {
|
pub struct SnapshotPackage {
|
||||||
|
root: u64,
|
||||||
snapshot_links: TempDir,
|
snapshot_links: TempDir,
|
||||||
storage_entries: Vec<Arc<AccountStorageEntry>>,
|
storage_entries: Vec<Arc<AccountStorageEntry>>,
|
||||||
tar_output_file: PathBuf,
|
tar_output_file: PathBuf,
|
||||||
@ -26,11 +28,13 @@ pub struct SnapshotPackage {
|
|||||||
|
|
||||||
impl SnapshotPackage {
|
impl SnapshotPackage {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
|
root: u64,
|
||||||
snapshot_links: TempDir,
|
snapshot_links: TempDir,
|
||||||
storage_entries: Vec<Arc<AccountStorageEntry>>,
|
storage_entries: Vec<Arc<AccountStorageEntry>>,
|
||||||
tar_output_file: PathBuf,
|
tar_output_file: PathBuf,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
root,
|
||||||
snapshot_links,
|
snapshot_links,
|
||||||
storage_entries,
|
storage_entries,
|
||||||
tar_output_file,
|
tar_output_file,
|
||||||
@ -66,6 +70,11 @@ impl SnapshotPackagerService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn package_snapshots(snapshot_package: &SnapshotPackage) -> Result<()> {
|
pub fn package_snapshots(snapshot_package: &SnapshotPackage) -> Result<()> {
|
||||||
|
info!(
|
||||||
|
"Generating snapshot tarball for root {}",
|
||||||
|
snapshot_package.root
|
||||||
|
);
|
||||||
|
let mut timer = Measure::start("snapshot_package-package_snapshots");
|
||||||
let tar_dir = snapshot_package
|
let tar_dir = snapshot_package
|
||||||
.tar_output_file
|
.tar_output_file
|
||||||
.parent()
|
.parent()
|
||||||
@ -125,6 +134,12 @@ impl SnapshotPackagerService {
|
|||||||
// can fetch this newly packaged snapshot
|
// can fetch this newly packaged snapshot
|
||||||
let _ = fs::remove_file(&snapshot_package.tar_output_file);
|
let _ = fs::remove_file(&snapshot_package.tar_output_file);
|
||||||
fs::hard_link(&temp_tar_path, &snapshot_package.tar_output_file)?;
|
fs::hard_link(&temp_tar_path, &snapshot_package.tar_output_file)?;
|
||||||
|
timer.stop();
|
||||||
|
info!(
|
||||||
|
"Successfully created tarball for root: {}, elapsed ms: {}",
|
||||||
|
snapshot_package.root,
|
||||||
|
timer.as_ms()
|
||||||
|
);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -162,7 +177,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_package_snapshots() {
|
fn test_package_snapshots() {
|
||||||
// Create temprorary placeholder directory for all test files
|
// Create temporary placeholder directory for all test files
|
||||||
let temp_dir = TempDir::new().unwrap();
|
let temp_dir = TempDir::new().unwrap();
|
||||||
let accounts_dir = temp_dir.path().join("accounts");
|
let accounts_dir = temp_dir.path().join("accounts");
|
||||||
let snapshots_dir = temp_dir.path().join("snapshots");
|
let snapshots_dir = temp_dir.path().join("snapshots");
|
||||||
@ -202,6 +217,7 @@ mod tests {
|
|||||||
// Create a packageable snapshot
|
// Create a packageable snapshot
|
||||||
let output_tar_path = snapshot_utils::get_snapshot_tar_path(&snapshot_package_output_path);
|
let output_tar_path = snapshot_utils::get_snapshot_tar_path(&snapshot_package_output_path);
|
||||||
let snapshot_package = SnapshotPackage::new(
|
let snapshot_package = SnapshotPackage::new(
|
||||||
|
5,
|
||||||
link_snapshots_dir,
|
link_snapshots_dir,
|
||||||
storage_entries.clone(),
|
storage_entries.clone(),
|
||||||
output_tar_path.clone(),
|
output_tar_path.clone(),
|
||||||
|
@ -84,6 +84,7 @@ pub fn package_snapshot<P: AsRef<Path>, Q: AsRef<Path>>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
let package = SnapshotPackage::new(
|
let package = SnapshotPackage::new(
|
||||||
|
bank.slot(),
|
||||||
snapshot_hard_links_dir,
|
snapshot_hard_links_dir,
|
||||||
account_storage_entries,
|
account_storage_entries,
|
||||||
snapshot_package_output_file.as_ref().to_path_buf(),
|
snapshot_package_output_file.as_ref().to_path_buf(),
|
||||||
|
Reference in New Issue
Block a user