Journal

Struct Journal 

Source
pub struct Journal<E, C, H, S: State<H::Digest> = Dirty>
where E: Storage + Clock + Metrics, C: Contiguous<Item: Encode>, H: Hasher,
{ /* private fields */ }
Expand description

An append-only data structure that maintains a sequential journal of items alongside a Merkle Mountain Range (MMR). The item at index i in the journal corresponds to the leaf at Location i in the MMR. This structure enables efficient proofs that an item is included in the journal at a specific location.

Implementations§

Source§

impl<E, C, H, S> Journal<E, C, H, S>
where E: Storage + Clock + Metrics, C: Contiguous<Item: Encode>, H: Hasher, S: State<DigestOf<H>>,

Source

pub fn size(&self) -> Location

Returns the number of items in the journal.

Source

pub fn oldest_retained_loc(&self) -> Option<Location>

Returns the oldest retained location in the journal.

Source

pub fn pruning_boundary(&self) -> Location

Returns the pruning boundary for the journal.

Source

pub async fn read(&self, loc: Location) -> Result<C::Item, Error>

Read an item from the journal at the given location.

Source§

impl<E, C, H, S> Journal<E, C, H, S>
where E: Storage + Clock + Metrics, C: MutableContiguous<Item: Encode>, H: Hasher, S: State<DigestOf<H>>,

Source

pub async fn append(&mut self, item: C::Item) -> Result<Location, Error>

Source§

impl<E, C, H, S> Journal<E, C, H, S>
where E: Storage + Clock + Metrics, C: PersistableContiguous<Item: Encode>, H: Hasher, S: State<DigestOf<H>>,

Source

pub async fn commit(&mut self) -> Result<(), Error>

Durably persist the journal. This is faster than sync() but does not persist the MMR, meaning recovery will be required on startup if we crash before sync() or close().

Source§

impl<E, C, H> Journal<E, C, H, Clean<H::Digest>>
where E: Storage + Clock + Metrics, C: MutableContiguous<Item: Encode>, H: Hasher,

Source

pub async fn from_components( mmr: CleanMmr<E, H::Digest>, journal: C, hasher: StandardHasher<H>, apply_batch_size: u64, ) -> Result<Self, Error>

Create a new Journal from the given components after aligning the MMR with the journal.

Source

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

Prune both the MMR and journal to the given location.

§Returns

The new pruning boundary, which may be less than the requested prune_loc.

Source§

impl<E, C, H> Journal<E, C, H, Clean<H::Digest>>
where E: Storage + Clock + Metrics, C: Contiguous<Item: Encode>, H: Hasher,

Source

pub async fn proof( &self, start_loc: Location, max_ops: NonZeroU64, ) -> Result<(Proof<H::Digest>, Vec<C::Item>), Error>

Generate a proof of inclusion for items starting at start_loc.

Returns a proof and the items corresponding to the leaves in the range start_loc..end_loc, where end_loc is the minimum of the current item count and start_loc + max_ops.

§Errors
Source

pub async fn historical_proof( &self, historical_size: Location, start_loc: Location, max_ops: NonZeroU64, ) -> Result<(Proof<H::Digest>, Vec<C::Item>), Error>

Generate a historical proof with respect to the state of the MMR when it had historical_size items.

Returns a proof and the items corresponding to the leaves in the range start_loc..end_loc, where end_loc is the minimum of historical_size and start_loc + max_ops.

§Errors
Source

pub const fn root(&self) -> H::Digest

Return the root of the MMR.

Source

pub fn into_dirty(self) -> Journal<E, C, H, Dirty>

Convert this journal into its dirty counterpart for batched updates.

Source§

impl<E, C, H> Journal<E, C, H, Clean<H::Digest>>

Source

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

Close the authenticated journal, syncing all pending writes.

Source

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

Destroy the authenticated journal, removing all data from disk.

Source

pub async fn sync(&mut self) -> Result<(), Error>

Durably persist the journal, ensuring no recovery is required on startup.

Source§

impl<E, C, H> Journal<E, C, H, Dirty>
where E: Storage + Clock + Metrics, C: Contiguous<Item: Encode>, H: Hasher,

Source

pub fn merkleize(self) -> Journal<E, C, H, Clean<H::Digest>>

Merkleize the journal and compute the root digest.

Source§

impl<E, C, H> Journal<E, C, H, Dirty>
where E: Storage + Clock + Metrics, C: MutableContiguous<Item: Encode>, H: Hasher,

Source

pub async fn from_components( mmr: CleanMmr<E, H::Digest>, journal: C, hasher: StandardHasher<H>, apply_batch_size: u64, ) -> Result<Self, Error>

Create a new dirty journal from aligned components.

Source§

impl<E, O, H> Journal<E, Journal<E, O>, H, Clean<H::Digest>>
where E: Storage + Clock + Metrics, O: CodecFixed<Cfg = ()>, H: Hasher,

Source

pub async fn new( context: E, mmr_cfg: Config, journal_cfg: Config, rewind_predicate: fn(&O) -> bool, ) -> Result<Self, Error>

Create a new Journal for fixed-length items.

The journal will be rewound to the last item that matches the rewind_predicate on initialization.

Source§

impl<E, O, H> Journal<E, Journal<E, O>, H, Clean<H::Digest>>
where E: Storage + Clock + Metrics, O: Codec + Encode, H: Hasher,

Source

pub async fn new( context: E, mmr_cfg: Config, journal_cfg: Config<O::Cfg>, rewind_predicate: fn(&O) -> bool, ) -> Result<Self, Error>

Create a new Journal for variable-length items.

The journal will be rewound to the last item that matches the rewind_predicate on initialization.

Trait Implementations§

Source§

impl<E, C, H, S> Contiguous for Journal<E, C, H, S>
where E: Storage + Clock + Metrics, C: MutableContiguous<Item: Encode>, H: Hasher, S: State<DigestOf<H>>,

Source§

type Item = <C as Contiguous>::Item

The type of items stored in the journal.
Source§

fn size(&self) -> u64

Return the total number of items that have been appended to the journal. Read more
Source§

fn oldest_retained_pos(&self) -> Option<u64>

Return the position of the oldest item still retained in the journal. Read more
Source§

fn pruning_boundary(&self) -> u64

Return the location before which all items have been pruned. Read more
Source§

async fn replay( &self, start_pos: u64, buffer: NonZeroUsize, ) -> Result<impl Stream<Item = Result<(u64, Self::Item), JournalError>> + '_, JournalError>

Return a stream of all items in the journal starting from start_pos. Read more
Source§

async fn read(&self, position: u64) -> Result<Self::Item, JournalError>

Read the item at the given position. Read more
Source§

impl<E, C, H> MutableContiguous for Journal<E, C, H, Dirty>
where E: Storage + Clock + Metrics, C: MutableContiguous<Item: Encode>, H: Hasher,

Source§

async fn append(&mut self, item: Self::Item) -> Result<u64, JournalError>

Append a new item to the journal, returning its position. Read more
Source§

async fn prune(&mut self, min_position: u64) -> Result<bool, JournalError>

Prune items at positions strictly less than min_position. Read more
Source§

async fn rewind(&mut self, size: u64) -> Result<(), JournalError>

Rewind the journal to the given size, discarding items from the end. Read more
Source§

fn rewind_to<'a, P>( &'a mut self, predicate: P, ) -> impl Future<Output = Result<u64, Error>> + 'a
where P: FnMut(&Self::Item) -> bool + 'a,

Rewinds the journal to the last item matching predicate. If no item matches, the journal is rewound to the pruning boundary, discarding all unpruned items. Read more
Source§

impl<E, C, H> MutableContiguous for Journal<E, C, H, Clean<H::Digest>>
where E: Storage + Clock + Metrics, C: MutableContiguous<Item: Encode>, H: Hasher,

Source§

async fn append(&mut self, item: Self::Item) -> Result<u64, JournalError>

Append a new item to the journal, returning its position. Read more
Source§

async fn prune(&mut self, min_position: u64) -> Result<bool, JournalError>

Prune items at positions strictly less than min_position. Read more
Source§

async fn rewind(&mut self, size: u64) -> Result<(), JournalError>

Rewind the journal to the given size, discarding items from the end. Read more
Source§

fn rewind_to<'a, P>( &'a mut self, predicate: P, ) -> impl Future<Output = Result<u64, Error>> + 'a
where P: FnMut(&Self::Item) -> bool + 'a,

Rewinds the journal to the last item matching predicate. If no item matches, the journal is rewound to the pruning boundary, discarding all unpruned items. Read more
Source§

impl<E, C, H> PersistableContiguous for Journal<E, C, H, Clean<H::Digest>>

Source§

async fn commit(&mut self) -> Result<(), JournalError>

Durably persist the journal but does not write all data, potentially leaving recovery required on startup. Read more
Source§

async fn sync(&mut self) -> Result<(), JournalError>

Durably persist the journal and write all data, guaranteeing no recovery will be required on startup. Read more
Source§

async fn close(self) -> Result<(), JournalError>

Close the journal, syncing all pending writes and releasing resources.
Source§

async fn destroy(self) -> Result<(), JournalError>

Destroy the journal, removing all associated storage. Read more

Auto Trait Implementations§

§

impl<E, C, H, S> Freeze for Journal<E, C, H, S>
where C: Freeze, H: Freeze, S: Freeze, E: Freeze, <E as Storage>::Blob: Freeze,

§

impl<E, C, H, S = Dirty> !RefUnwindSafe for Journal<E, C, H, S>

§

impl<E, C, H, S> Send for Journal<E, C, H, S>
where C: Send, S: Send,

§

impl<E, C, H, S> Sync for Journal<E, C, H, S>
where C: Sync, S: Sync,

§

impl<E, C, H, S> Unpin for Journal<E, C, H, S>
where C: Unpin, H: Unpin, S: Unpin, E: Unpin, <E as Storage>::Blob: Unpin, <H as Hasher>::Digest: Unpin,

§

impl<E, C, H, S = Dirty> !UnwindSafe for Journal<E, C, H, S>

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
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
§

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

§

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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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

§

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

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

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

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,