Struct Journal

Source
pub struct Journal<B: Blob, E: Storage<B>> { /* private fields */ }
Expand description

Implementation of Journal storage.

Implementations§

Source§

impl<B: Blob, E: Storage<B>> Journal<B, E>

Source

pub async fn init(runtime: E, cfg: Config) -> Result<Self, Error>

Initialize a new Journal instance.

All backing blobs are opened but not read during initialization. The replay method can be used to iterate over all items in the Journal.

Source

pub async fn replay( &mut self, concurrency: usize, prefix: Option<u32>, ) -> Result<impl Stream<Item = Result<(u64, u32, u32, Bytes), Error>> + '_, Error>

Returns an unordered stream of all items in the journal.

§Repair

If any corrupted data is found, the stream will return an error.

If any trailing data is found (i.e. misaligned entries), the journal will be truncated to the last valid item. For this reason, it is recommended to call replay before calling append (as data added to trailing bytes will fail checksum after restart).

§Concurrency

The concurrency parameter controls how many blobs are replayed concurrently. This can dramatically speed up the replay process if the underlying storage supports concurrent reads across different blobs.

§Prefix

If prefix is provided, the stream will only read up to prefix bytes of each item. Consequently, this means we will not compute a checksum of the entire data and it is up to the caller to deal with the consequences of this.

Reading prefix bytes and skipping ahead to a future location in a blob is the theoretically optimal way to read only what is required from storage, however, different storage implementations may take the opportunity to readahead past what is required (needlessly). If the underlying storage can be tuned for random access prior to invoking replay, it may lead to less IO.

Source

pub async fn append(&mut self, section: u64, item: Bytes) -> Result<u32, Error>

Appends an item to Journal in a given section.

§Warning

If there exist trailing bytes in the Blob of a particular section and replay is not called before this, it is likely that subsequent data added to the Blob will be considered corrupted (as the trailing bytes will fail the checksum verification). It is recommended to call replay before calling append to prevent this.

Source

pub async fn get_prefix( &self, section: u64, offset: u32, prefix: u32, ) -> Result<Option<Bytes>, Error>

Retrieves the first prefix bytes of an item from Journal at a given section and offset.

This method bypasses the checksum verification and the caller is responsible for ensuring the integrity of any data read.

Source

pub async fn get( &self, section: u64, offset: u32, exact: Option<u32>, ) -> Result<Option<Bytes>, Error>

Retrieves an item from Journal at a given section and offset.

If exact is provided, it is assumed the item is of size exact (which allows the item to be read in a single read). If exact is provided, the checksum of the data is still verified.

Source

pub async fn sync(&self, section: u64) -> Result<(), Error>

Ensures that all data in a given section is synced to the underlying store.

If the section does not exist, no error will be returned.

Source

pub async fn prune(&mut self, min: u64) -> Result<(), Error>

Prunes all sections less than min.

Source

pub async fn close(self) -> Result<(), Error>

Closes all open sections.

Auto Trait Implementations§

§

impl<B, E> Freeze for Journal<B, E>
where E: Freeze,

§

impl<B, E> RefUnwindSafe for Journal<B, E>

§

impl<B, E> Send for Journal<B, E>

§

impl<B, E> Sync for Journal<B, E>

§

impl<B, E> Unpin for Journal<B, E>
where E: Unpin,

§

impl<B, E> UnwindSafe for Journal<B, E>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more