pub struct AppendVec { /* private fields */ }
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.
Implementations§
Source§impl AppendVec
impl AppendVec
pub fn new(file: impl Into<PathBuf>, create: bool, size: usize) -> Self
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 new_from_file( path: impl Into<PathBuf>, current_len: usize, storage_access: StorageAccess, ) -> Result<(Self, usize)>
Sourcepub fn new_from_file_unchecked(
path: impl Into<PathBuf>,
current_len: usize,
storage_access: StorageAccess,
) -> Result<Self>
pub fn new_from_file_unchecked( path: impl Into<PathBuf>, current_len: usize, storage_access: StorageAccess, ) -> Result<Self>
Creates an appendvec from file without performing sanitize checks or counting the number of accounts
Sourcepub fn get_stored_account_meta_callback<Ret>(
&self,
offset: usize,
callback: impl for<'local> FnMut(StoredAccountMeta<'local>) -> Ret,
) -> Option<Ret>
pub fn get_stored_account_meta_callback<Ret>( &self, offset: usize, callback: impl for<'local> FnMut(StoredAccountMeta<'local>) -> Ret, ) -> Option<Ret>
calls callback
with the stored account metadata for the account at offset
if its data doesn’t overrun
the internal buffer. Otherwise return None.
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.
Sourcepub fn scan_accounts(
&self,
callback: impl for<'local> FnMut(StoredAccountMeta<'local>),
)
pub fn scan_accounts( &self, callback: impl for<'local> FnMut(StoredAccountMeta<'local>), )
Iterate over all accounts and call callback
with each account.
Sourcepub fn scan_pubkeys(&self, callback: impl FnMut(&Pubkey))
pub fn scan_pubkeys(&self, callback: impl FnMut(&Pubkey))
iterate over all pubkeys and call callback
.
This iteration does not deserialize and populate each field in StoredAccountMeta
.
data
is completely ignored, for example.
Also, no references have to be maintained/returned from an iterator function.
This fn can operate on a batch of data at once.
Sourcepub fn append_accounts<'a>(
&self,
accounts: &impl StorableAccounts<'a>,
skip: usize,
) -> Option<StoredAccountsInfo>
pub fn append_accounts<'a>( &self, accounts: &impl StorableAccounts<'a>, skip: usize, ) -> Option<StoredAccountsInfo>
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.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for AppendVec
impl RefUnwindSafe for AppendVec
impl Send for AppendVec
impl Sync for AppendVec
impl Unpin for AppendVec
impl UnwindSafe for AppendVec
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more