Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid shell out tar for genesis archive creation #3079

Merged
merged 3 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions ledger/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ assert_matches = { workspace = true }
bincode = { workspace = true }
bitflags = { workspace = true, features = ["serde"] }
byteorder = { workspace = true }
bzip2 = { workspace = true }
chrono = { workspace = true, features = ["default", "serde"] }
chrono-humanize = { workspace = true }
crossbeam-channel = { workspace = true }
Expand Down Expand Up @@ -73,6 +74,7 @@ spl-token-2022 = { workspace = true, features = ["no-entrypoint"] }
static_assertions = { workspace = true }
strum = { workspace = true, features = ["derive"] }
strum_macros = { workspace = true }
tar = { workspace = true }
tempfile = { workspace = true }
thiserror = { workspace = true }
tokio = { workspace = true, features = ["full"] }
Expand Down
35 changes: 8 additions & 27 deletions ledger/src/blockstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ use {
},
convert::TryInto,
fmt::Write,
fs,
fs::{self, File},
io::{Error as IoError, ErrorKind},
ops::Bound,
path::{Path, PathBuf},
Expand All @@ -81,6 +81,7 @@ use {
Arc, Mutex, RwLock,
},
},
tar,
tempfile::{Builder, TempDir},
thiserror::Error,
trees::{Tree, TreeWalk},
Expand Down Expand Up @@ -4835,32 +4836,12 @@ pub fn create_new_ledger(
drop(blockstore);

let archive_path = ledger_path.join(DEFAULT_GENESIS_ARCHIVE);
let args = vec![
"jcfhS",
archive_path.to_str().unwrap(),
"-C",
ledger_path.to_str().unwrap(),
DEFAULT_GENESIS_FILE,
blockstore_dir,
];
let output = std::process::Command::new("tar")
.env("COPYFILE_DISABLE", "1")
.args(args)
.output()
.unwrap();
if !output.status.success() {
use std::str::from_utf8;
error!("tar stdout: {}", from_utf8(&output.stdout).unwrap_or("?"));
error!("tar stderr: {}", from_utf8(&output.stderr).unwrap_or("?"));

return Err(BlockstoreError::Io(IoError::new(
ErrorKind::Other,
format!(
"Error trying to generate snapshot archive: {}",
output.status
),
)));
}
let archive_file = File::create(&archive_path)?;
let encoder = bzip2::write::BzEncoder::new(archive_file, bzip2::Compression::best());
let mut archive = tar::Builder::new(encoder);
archive.append_path_with_name(ledger_path.join(DEFAULT_GENESIS_FILE), DEFAULT_GENESIS_FILE)?;
archive.append_dir_all(blockstore_dir, ledger_path.join(blockstore_dir))?;
archive.into_inner()?;

// ensure the genesis archive can be unpacked and it is under
// max_genesis_archive_unpacked_size, immediately after creating it above.
Expand Down
2 changes: 2 additions & 0 deletions programs/sbf/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading