Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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: 1 addition & 1 deletion accounts-db/benches/bench_accounts_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ fn bench_write_accounts_file(c: &mut Criterion) {
|| {
let path = temp_dir.path().join(format!("append_vec_{accounts_count}"));
let file_size = accounts.len() * (space + append_vec::STORE_META_OVERHEAD);
AppendVec::new(&path, true, file_size)
AppendVec::new(path, true, file_size)
},
|append_vec| {
let res = append_vec.append_accounts(&storable_accounts, 0).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion accounts-db/src/accounts_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1034,7 +1034,7 @@ impl AccountStorageEntry {
pub fn new(path: &Path, slot: Slot, id: AccountsFileId, file_size: u64) -> Self {
let tail = AccountsFile::file_name(slot, id);
let path = Path::new(path).join(tail);
let accounts = AccountsFile::AppendVec(AppendVec::new(&path, true, file_size as usize));
let accounts = AccountsFile::AppendVec(AppendVec::new(path, true, file_size as usize));

Self {
id,
Expand Down
2 changes: 1 addition & 1 deletion accounts-db/src/accounts_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl AccountsFile {
/// The second element of the returned tuple is the number of accounts in the
/// accounts file.
pub fn new_from_file(path: impl AsRef<Path>, current_len: usize) -> Result<(Self, usize)> {
let (av, num_accounts) = AppendVec::new_from_file(path, current_len)?;
let (av, num_accounts) = AppendVec::new_from_file(path.as_ref(), current_len)?;
Ok((Self::AppendVec(av), num_accounts))
}

Expand Down
23 changes: 13 additions & 10 deletions accounts-db/src/append_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use {
fs::{remove_file, OpenOptions},
io::{Seek, SeekFrom, Write},
mem,
path::{Path, PathBuf},
path::PathBuf,
sync::{
atomic::{AtomicU64, AtomicUsize, Ordering},
Mutex,
Expand Down Expand Up @@ -237,19 +237,20 @@ impl Drop for AppendVec {
}

impl AppendVec {
pub fn new(file: &Path, create: bool, size: usize) -> Self {
pub fn new(file: impl Into<PathBuf>, create: bool, size: usize) -> Self {
let file = file.into();
let initial_len = 0;
AppendVec::sanitize_len_and_size(initial_len, size).unwrap();

if create {
let _ignored = remove_file(file);
let _ignored = remove_file(&file);
}

let mut data = OpenOptions::new()
.read(true)
.write(true)
.create(create)
.open(file)
.open(&file)
.map_err(|e| {
panic!(
"Unable to {} data file {} in current dir({:?}): {:?}",
Expand Down Expand Up @@ -282,7 +283,7 @@ impl AppendVec {
APPEND_VEC_MMAPPED_FILES_OPEN.fetch_add(1, Ordering::Relaxed);

AppendVec {
path: file.to_path_buf(),
path: file,
map,
// This mutex forces append to be single threaded, but concurrent with reads
// See UNSAFE usage in `append_ptr`
Expand Down Expand Up @@ -347,23 +348,25 @@ impl AppendVec {
format!("{slot}.{id}")
}

pub fn new_from_file<P: AsRef<Path>>(path: P, current_len: usize) -> Result<(Self, usize)> {
let new = Self::new_from_file_unchecked(&path, current_len)?;
pub fn new_from_file(path: impl Into<PathBuf>, current_len: usize) -> Result<(Self, usize)> {
let path = path.into();
let new = Self::new_from_file_unchecked(path, current_len)?;

let (sanitized, num_accounts) = new.sanitize_layout_and_length();
if !sanitized {
// This info show the failing accountvec file path. It helps debugging
// the appendvec data corrupution issues related to recycling.
return Err(AccountsFileError::AppendVecError(
AppendVecError::IncorrectLayout(path.as_ref().to_path_buf()),
AppendVecError::IncorrectLayout(new.path.clone()),
));
}

Ok((new, num_accounts))
}

/// Creates an appendvec from file without performing sanitize checks or counting the number of accounts
pub fn new_from_file_unchecked<P: AsRef<Path>>(path: P, current_len: usize) -> Result<Self> {
pub fn new_from_file_unchecked(path: impl Into<PathBuf>, current_len: usize) -> Result<Self> {
let path = path.into();
let file_size = std::fs::metadata(&path)?.len();
Self::sanitize_len_and_size(current_len, file_size as usize)?;

Expand All @@ -384,7 +387,7 @@ impl AppendVec {
APPEND_VEC_MMAPPED_FILES_OPEN.fetch_add(1, Ordering::Relaxed);

Ok(AppendVec {
path: path.as_ref().to_path_buf(),
path,
map,
append_lock: Mutex::new(()),
current_len: AtomicUsize::new(current_len),
Expand Down