Struct solana_runtime::append_vec::AppendVec
source · pub struct AppendVec {
path: PathBuf,
map: MmapMut,
append_lock: Mutex<()>,
current_len: AtomicUsize,
file_size: u64,
remove_on_drop: bool,
}
Expand description
A thread-safe, file-backed block of memory used to store Account
instances. Append operations
are serialized such that only one thread updates the internal append_lock
at a time. No
restrictions are placed on reading. That is, one may read items from one thread while another
is appending new items.
Fields§
§path: PathBuf
The file path where the data is stored.
map: MmapMut
A file-backed block of memory that is used to store the data for each appended item.
append_lock: Mutex<()>
A lock used to serialize append operations.
current_len: AtomicUsize
The number of bytes used to store items, not the number of items.
file_size: u64
The number of bytes available for storing items.
remove_on_drop: bool
True if the file should automatically be deleted when this AppendVec is dropped.
Implementations§
source§impl AppendVec
impl AppendVec
pub fn new(file: &Path, create: bool, size: usize) -> Self
pub fn set_no_remove_on_drop(&mut self)
fn sanitize_len_and_size(current_len: usize, file_size: usize) -> Result<()>
pub fn flush(&self) -> Result<()>
pub fn reset(&self)
sourcepub fn remaining_bytes(&self) -> u64
pub fn remaining_bytes(&self) -> u64
how many more bytes can be stored in this append vec
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
pub fn capacity(&self) -> u64
pub fn file_name(slot: Slot, id: impl Display) -> String
pub fn new_from_file<P: AsRef<Path>>( path: P, current_len: usize ) -> Result<(Self, usize)>
sourcepub fn new_from_file_unchecked<P: AsRef<Path>>(
path: P,
current_len: usize
) -> Result<Self>
pub fn new_from_file_unchecked<P: AsRef<Path>>( path: P, current_len: usize ) -> Result<Self>
Creates an appendvec from file without performing sanitize checks or counting the number of accounts
fn sanitize_layout_and_length(&self) -> (bool, usize)
sourcefn get_slice(&self, offset: usize, size: usize) -> Option<(&[u8], usize)>
fn get_slice(&self, offset: usize, size: usize) -> Option<(&[u8], usize)>
Get a reference to the data at offset
of size
bytes if that slice
doesn’t overrun the internal buffer. Otherwise return None.
Also return the offset of the first byte after the requested data that
falls on a 64-byte boundary.
sourcefn append_ptr(&self, offset: &mut usize, src: *const u8, len: usize)
fn append_ptr(&self, offset: &mut usize, src: *const u8, len: usize)
Copy len
bytes from src
to the first 64-byte boundary after position offset
of
the internal buffer. Then update offset
to the first byte after the copied data.
sourcefn append_ptrs_locked(
&self,
offset: &mut usize,
vals: &[(*const u8, usize)]
) -> Option<usize>
fn append_ptrs_locked( &self, offset: &mut usize, vals: &[(*const u8, usize)] ) -> Option<usize>
Copy each value in vals
, in order, to the first 64-byte boundary after position offset
.
If there is sufficient space, then update offset
and the internal current_len
to the
first byte after the copied data and return the starting position of the copied data.
Otherwise return None and leave offset
unchanged.
sourcefn get_type<'a, T>(&self, offset: usize) -> Option<(&'a T, usize)>
fn get_type<'a, T>(&self, offset: usize) -> Option<(&'a T, usize)>
Return a reference to the type at offset
if its data doesn’t overrun the internal buffer.
Otherwise return None. Also return the offset of the first byte after the requested data
that falls on a 64-byte boundary.
sourcepub fn get_account<'a>(
&'a self,
offset: usize
) -> Option<(StoredAccountMeta<'a>, usize)>
pub fn get_account<'a>( &'a self, offset: usize ) -> Option<(StoredAccountMeta<'a>, usize)>
Return stored account metadata for the account at offset
if its data doesn’t overrun
the internal buffer. Otherwise return None. Also return the offset of the first byte
after the requested data that falls on a 64-byte boundary.
fn get_account_meta<'a>(&self, offset: usize) -> Option<&'a AccountMeta>
sourcepub fn account_matches_owners(
&self,
offset: usize,
owners: &[&Pubkey]
) -> Result<usize, MatchAccountOwnerError>
pub fn account_matches_owners( &self, offset: usize, owners: &[&Pubkey] ) -> Result<usize, MatchAccountOwnerError>
Return Ok(index_of_matching_owner) if the account owner at offset
is one of the pubkeys in owners
.
Return Err(MatchAccountOwnerError::NoMatch) if the account has 0 lamports or the owner is not one of
the pubkeys in owners
.
Return Err(MatchAccountOwnerError::UnableToLoad) if the offset
value causes a data overrun.
pub fn get_path(&self) -> PathBuf
sourcepub fn account_iter(&self) -> AppendVecAccountsIter<'_> ⓘ
pub fn account_iter(&self) -> AppendVecAccountsIter<'_> ⓘ
Return iterator for account metadata
sourcepub fn accounts(&self, offset: usize) -> Vec<StoredAccountMeta<'_>>
pub fn accounts(&self, offset: usize) -> Vec<StoredAccountMeta<'_>>
Return a vector of account metadata for each account, starting from offset
.
sourcepub fn append_accounts<'a, 'b, T: ReadableAccount + Sync, U: StorableAccounts<'a, T>, V: Borrow<Hash>>(
&self,
accounts: &StorableAccountsWithHashesAndWriteVersions<'a, 'b, T, U, V>,
skip: usize
) -> Option<Vec<StoredAccountInfo>>
pub fn append_accounts<'a, 'b, T: ReadableAccount + Sync, U: StorableAccounts<'a, T>, V: Borrow<Hash>>( &self, accounts: &StorableAccountsWithHashesAndWriteVersions<'a, 'b, T, U, V>, skip: usize ) -> Option<Vec<StoredAccountInfo>>
Copy each account metadata, account and hash to the internal buffer.
If there is no room to write the first entry, None is returned.
Otherwise, returns the starting offset of each account metadata.
Plus, the final return value is the offset where the next entry would be appended.
So, return.len() is 1 + (number of accounts written)
After each account is appended, the internal current_len
is updated
and will be available to other threads.