pub struct Append<B: Blob> { /* private fields */ }Expand description
A Blob wrapper that supports write-cached appending of data, with checksums for data integrity and buffer pool managed caching.
Implementations§
Source§impl<B: Blob> Append<B>
impl<B: Blob> Append<B>
Sourcepub async fn new(
blob: B,
original_blob_size: u64,
capacity: usize,
pool_ref: PoolRef,
) -> Result<Self, Error>
pub async fn new( blob: B, original_blob_size: u64, capacity: usize, pool_ref: PoolRef, ) -> Result<Self, Error>
Create a new Append wrapper of the provided blob that is known to have blob_size
underlying physical bytes, using the provided pool for read caching, and a write buffer
with capacity capacity. Rewinds the blob if necessary to ensure it only contains
checksum-validated data.
Sourcepub async fn new_immutable(
blob: B,
blob_size: u64,
capacity: usize,
pool_ref: PoolRef,
) -> Result<Self, Error>
pub async fn new_immutable( blob: B, blob_size: u64, capacity: usize, pool_ref: PoolRef, ) -> Result<Self, Error>
Return a new Append wrapper of the provided blob that is known to have blob_size
underlying physical bytes, using the provided pool for read caching. The wrapper is for
read-only data, and any append attempts will return error. The provided capacity is used
only if the blob is later turned into a mutable one. Immutable blobs are assumed consistent
on disk, so any CRC verification failure results in an error without any recovery attempt.
Sourcepub async fn is_immutable(&self) -> bool
pub async fn is_immutable(&self) -> bool
Returns true if this blob is in the immutable state.
Sourcepub async fn to_immutable(&self) -> Result<(), Error>
pub async fn to_immutable(&self) -> Result<(), Error>
Convert this blob to the immutable state if it’s not already in it.
If there is unwritten data in the buffer, it will be flushed and synced before returning.
Sourcepub async fn to_mutable(&self)
pub async fn to_mutable(&self)
Convert this blob to the mutable state if it’s not already in it.
Sourcepub async fn append(&self, buf: &[u8]) -> Result<(), Error>
pub async fn append(&self, buf: &[u8]) -> Result<(), Error>
Append all bytes in buf to the tip of the blob.
§Errors
Error::ImmutableBlob- The blob is in the immutable state.
Sourcepub async fn size(&self) -> u64
pub async fn size(&self) -> u64
Returns the logical size of the blob. This accounts for both written and buffered data.
Sourcepub async fn read_up_to(
&self,
buf: impl Into<StableBuf> + Send,
logical_offset: u64,
) -> Result<(StableBuf, usize), Error>
pub async fn read_up_to( &self, buf: impl Into<StableBuf> + Send, logical_offset: u64, ) -> Result<(StableBuf, usize), Error>
Reads up to buf.len() bytes starting at logical_offset, but only as many as are
available.
This is useful for reading variable-length prefixes (like varints) where you want to read up to a maximum number of bytes but the actual data might be shorter.
Returns the number of bytes actually read into the buffer. Returns an error if no bytes are available at the given offset.
Sourcepub async fn read_into(
&self,
buf: &mut [u8],
logical_offset: u64,
) -> Result<(), Error>
pub async fn read_into( &self, buf: &mut [u8], logical_offset: u64, ) -> Result<(), Error>
Reads bytes starting at logical_offset into buf.
This method allows reading directly into a mutable slice without taking ownership of the buffer or requiring a specific buffer type.
Sourcepub async fn replay(
&self,
buffer_size: NonZeroUsize,
) -> Result<Replay<B>, Error>
pub async fn replay( &self, buffer_size: NonZeroUsize, ) -> Result<Replay<B>, Error>
Flushes any buffered data, then returns a Replay for the underlying blob.
The returned replay can be used to sequentially read all pages from the blob while ensuring all data passes integrity verification. CRCs are validated but not included in the output.
Trait Implementations§
Source§impl<B: Blob> Blob for Append<B>
impl<B: Blob> Blob for Append<B>
Source§async fn write_at(
&self,
_buf: impl Into<StableBuf> + Send,
_offset: u64,
) -> Result<(), Error>
async fn write_at( &self, _buf: impl Into<StableBuf> + Send, _offset: u64, ) -> Result<(), Error>
Source§async fn resize(&self, size: u64) -> Result<(), Error>
async fn resize(&self, size: u64) -> Result<(), Error>
Resize the blob to the provided logical size.
This truncates the blob to contain only size logical bytes. The physical blob size will
be adjusted to include the necessary CRC records for the remaining pages.
§Warning
- Concurrent mutable operations (append, resize) are not supported and will cause data loss.
- Concurrent readers which try to read past the new size during the resize may error.
- The resize is not guaranteed durable until the next sync.
Auto Trait Implementations§
impl<B> Freeze for Append<B>
impl<B> !RefUnwindSafe for Append<B>
impl<B> Send for Append<B>
impl<B> Sync for Append<B>
impl<B> Unpin for Append<B>
impl<B> !UnwindSafe for Append<B>
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
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