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 page cache 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,
cache_ref: CacheRef,
) -> Result<Self, Error>
pub async fn new( blob: B, original_blob_size: u64, capacity: usize, cache_ref: CacheRef, ) -> 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 cache_ref 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 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.
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_at(&self, offset: u64, len: usize) -> Result<IoBufs, Error>
pub async fn read_at(&self, offset: u64, len: usize) -> Result<IoBufs, Error>
Read exactly len immutable bytes starting at offset.
Sourcepub async fn read_up_to(
&self,
logical_offset: u64,
len: usize,
bufs: impl Into<IoBufMut> + Send,
) -> Result<(IoBufMut, usize), Error>
pub async fn read_up_to( &self, logical_offset: u64, len: usize, bufs: impl Into<IoBufMut> + Send, ) -> Result<(IoBufMut, 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 buffer (truncated to actual bytes read) and the number of bytes read. 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.
Source§impl<B: Blob> Append<B>
impl<B: Blob> Append<B>
pub async fn sync(&self) -> Result<(), Error>
Sourcepub async fn resize(&self, size: u64) -> Result<(), Error>
pub 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.
Trait Implementations§
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> UnsafeUnpin 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