pub struct Journal<F, E, C, H, S>{ /* private fields */ }Expand description
An append-only data structure that maintains a sequential journal of items alongside a Merkle-family structure. The item at index i in the journal corresponds to the leaf at Location i in the Merkle structure. This structure enables efficient proofs that an item is included in the journal at a specific location.
Implementations§
Source§impl<F, E, C, H, S> Journal<F, E, C, H, S>
impl<F, E, C, H, S> Journal<F, E, C, H, S>
Sourcepub fn size(&self) -> Location<F>
pub fn size(&self) -> Location<F>
Returns the Location of the next item appended to the journal.
Sourcepub fn root(&self, inactive_peaks: usize) -> Result<H::Digest, Error<F>>
pub fn root(&self, inactive_peaks: usize) -> Result<H::Digest, Error<F>>
Compute the root of the Merkle structure using inactive_peaks and the bagging carried by
the journal’s hasher.
Sourcepub fn new_batch(&self) -> UnmerkleizedBatch<F, H, C::Item, S>
pub fn new_batch(&self) -> UnmerkleizedBatch<F, H, C::Item, S>
Create a speculative batch atop this journal.
Sourcepub async fn proof(
&self,
start_loc: Location<F>,
max_ops: NonZeroU64,
inactive_peaks: usize,
) -> Result<(Proof<F, H::Digest>, Vec<C::Item>), Error<F>>
pub async fn proof( &self, start_loc: Location<F>, max_ops: NonZeroU64, inactive_peaks: usize, ) -> Result<(Proof<F, H::Digest>, Vec<C::Item>), Error<F>>
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
- Returns Error::Merkle with merkle::Error::RangeOutOfBounds if
start_loc>= current item count. - Returns Error::Journal with crate::journal::Error::ItemPruned or Error::Merkle with merkle::Error::ElementPruned if a required item or Merkle node has been pruned.
Sourcepub fn speculative_proof(
&self,
batch: &MerkleizedBatch<F, H::Digest, C::Item, S>,
inactive_peaks: usize,
) -> Result<Proof<F, H::Digest>, Error<F>>
pub fn speculative_proof( &self, batch: &MerkleizedBatch<F, H::Digest, C::Item, S>, inactive_peaks: usize, ) -> Result<Proof<F, H::Digest>, Error<F>>
Inclusion proof for the items batch appends, anchored at the batch’s speculative tip.
Nodes below the batch chain are read from this journal’s Merkle store, which retains them at least until the batch’s changes are flushed.
Sourcepub fn speculative_pinned_nodes(
&self,
batch: &MerkleizedBatch<F, H::Digest, C::Item, S>,
) -> Result<Vec<H::Digest>, Error<F>>
pub fn speculative_pinned_nodes( &self, batch: &MerkleizedBatch<F, H::Digest, C::Item, S>, ) -> Result<Vec<H::Digest>, Error<F>>
Merkle frontier at the first item batch appends (Family::nodes_to_pin).
Nodes below the batch chain are read from this journal’s Merkle store, which retains them at least until the batch’s changes are flushed.
Sourcepub async fn historical_proof(
&self,
historical_leaves: Location<F>,
start_loc: Location<F>,
max_ops: NonZeroU64,
inactive_peaks: usize,
) -> Result<(Proof<F, H::Digest>, Vec<C::Item>), Error<F>>
pub async fn historical_proof( &self, historical_leaves: Location<F>, start_loc: Location<F>, max_ops: NonZeroU64, inactive_peaks: usize, ) -> Result<(Proof<F, H::Digest>, Vec<C::Item>), Error<F>>
Generate a historical proof with respect to the state of the Merkle structure when it had
historical_leaves leaves.
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_leaves and start_loc + max_ops.
§Errors
- Returns Error::Merkle with merkle::Error::RangeOutOfBounds if
start_loc>=historical_leavesorhistorical_leaves> number of items in the journal. - Returns Error::Journal with crate::journal::Error::ItemPruned or Error::Merkle with merkle::Error::ElementPruned if a required item or Merkle node has been pruned.
Source§impl<F, E, C, H, S> Journal<F, E, C, H, S>
impl<F, E, C, H, S> Journal<F, E, C, H, S>
Sourcepub async fn start_sync(self) -> Result<(Self, Handle<()>), Error<F>>
pub async fn start_sync(self) -> Result<(Self, Handle<()>), Error<F>>
Begin durably persisting the journal.
Awaiting the returned Handle provides the same durability guarantee as Self::commit. Also tries to advance the recovery watermarks to bound startup recovery. Use Self::sync to guarantee no recovery is needed.
Sourcepub async fn commit(self) -> Result<Self, Error<F>>
pub async fn commit(self) -> Result<Self, Error<F>>
Durably persist the journal. This is faster than sync() but does not guarantee that the
Merkle structure is durably persisted, meaning recovery may be required on startup in the
event of a crash.
Sourcepub async fn from_components(
merkle: Merkle<F, E, H::Digest, S>,
journal: C,
hasher: StandardHasher<H>,
apply_batch_size: NonZeroU64,
) -> Result<Self, Error<F>>
pub async fn from_components( merkle: Merkle<F, E, H::Digest, S>, journal: C, hasher: StandardHasher<H>, apply_batch_size: NonZeroU64, ) -> Result<Self, Error<F>>
Create a Journal, replaying any journal operations missing from Merkle.
Returns an error if the Merkle tree extends past the journal end.
Sourcepub async fn append(
self,
item: &C::Item,
) -> Result<(Self, Location<F>), Error<F>>
pub async fn append( self, item: &C::Item, ) -> Result<(Self, Location<F>), Error<F>>
Append an item to the journal and update the Merkle structure.
Sourcepub async fn apply_batch(
self,
batch: &MerkleizedBatch<F, H::Digest, C::Item, S>,
) -> Result<Self, Error<F>>
pub async fn apply_batch( self, batch: &MerkleizedBatch<F, H::Digest, C::Item, S>, ) -> Result<Self, Error<F>>
Apply a batch to the journal.
A batch is valid if the journal has not been modified since the batch chain was created, or if only ancestors of this batch have been applied. Already-committed ancestors are skipped automatically. Applying a batch from a different fork returns an error.
Sourcepub async fn prune(
self,
prune_loc: Location<F>,
) -> Result<(Self, Location<F>), Error<F>>
pub async fn prune( self, prune_loc: Location<F>, ) -> Result<(Self, Location<F>), Error<F>>
Prune journal items before prune_loc, then raise the Merkle pruning boundary to the
journal’s retained start if it is lower.
§Returns
The journal’s retained start, which may be less than prune_loc. After state sync, the
Merkle pruning boundary can remain above the returned start.
Source§impl<F, E, C, H, S> Journal<F, E, C, H, S>
impl<F, E, C, H, S> Journal<F, E, C, H, S>
Sourcepub async fn new(
context: E,
merkle_cfg: Config<S>,
journal_cfg: C::Config,
predicate: fn(&C::Item) -> bool,
bagging: Bagging,
) -> Result<Self, Error<F>>
pub async fn new( context: E, merkle_cfg: Config<S>, journal_cfg: C::Config, predicate: fn(&C::Item) -> bool, bagging: Bagging, ) -> Result<Self, Error<F>>
Create an authenticated journal ending at its last matching item.
An empty retained range preserves its append position.
Sourcepub async fn init_at_most(
context: E,
merkle_cfg: Config<S>,
journal_cfg: C::Config,
max_size: u64,
predicate: fn(&C::Item) -> bool,
bagging: Bagging,
) -> Result<Self, Error<F>>
pub async fn init_at_most( context: E, merkle_cfg: Config<S>, journal_cfg: C::Config, max_size: u64, predicate: fn(&C::Item) -> bool, bagging: Bagging, ) -> Result<Self, Error<F>>
Recover a journal whose last matching item ends at or below max_size.
Initialization durably discards the suffix before returning. A cap below retained history, or pruned history with no matching retained item, returns a pruning error.
Trait Implementations§
Source§impl<F, E, C, H, S> Contiguous for Journal<F, E, C, H, S>
impl<F, E, C, H, S> Contiguous for Journal<F, E, C, H, S>
Source§type Item = <C as Contiguous>::Item
type Item = <C as Contiguous>::Item
Source§fn bounds(&self) -> Range<u64> ⓘ
fn bounds(&self) -> Range<u64> ⓘ
Source§async fn read(&self, position: u64) -> Result<C::Item, JournalError>
async fn read(&self, position: u64) -> Result<C::Item, JournalError>
Source§async fn read_many(
&self,
positions: &[u64],
) -> Result<Vec<C::Item>, JournalError>
async fn read_many( &self, positions: &[u64], ) -> Result<Vec<C::Item>, JournalError>
Source§fn try_read_sync(&self, position: u64) -> Option<C::Item>
fn try_read_sync(&self, position: u64) -> Option<C::Item>
None
otherwise. Decode failures surface as None and the async read path reports the error.Source§fn try_read_many_sync(&self, positions: &[u64]) -> Vec<Option<C::Item>>
fn try_read_many_sync(&self, positions: &[u64]) -> Vec<Option<C::Item>>
bounds() decline to None. The
async read paths are the sole error authority for declined positions.Source§async fn replay(
&self,
range: Range<u64>,
buffer: NonZeroUsize,
read_options: ReadOptions,
) -> Result<impl Stream<Item = Result<Batch<C::Item>, JournalError>> + Send, JournalError>
async fn replay( &self, range: Range<u64>, buffer: NonZeroUsize, read_options: ReadOptions, ) -> Result<impl Stream<Item = Result<Batch<C::Item>, JournalError>> + Send, JournalError>
Source§impl<F, E, C, H, S> Mutable for Journal<F, E, C, H, S>
impl<F, E, C, H, S> Mutable for Journal<F, E, C, H, S>
Source§async fn append(self, item: &Self::Item) -> Result<(Self, u64), JournalError>
async fn append(self, item: &Self::Item) -> Result<(Self, u64), JournalError>
Source§async fn append_many(
self,
items: Many<'_, Self::Item>,
) -> Result<(Self, u64), JournalError>
async fn append_many( self, items: Many<'_, Self::Item>, ) -> Result<(Self, u64), JournalError>
Source§async fn prune(self, min_position: u64) -> Result<(Self, bool), JournalError>
async fn prune(self, min_position: u64) -> Result<(Self, bool), JournalError>
min_position. Read moreSource§async fn start_sync(self) -> Result<(Self, Handle<()>), JournalError>
async fn start_sync(self) -> Result<(Self, Handle<()>), JournalError>
Source§async fn commit(self) -> Result<Self, JournalError>
async fn commit(self) -> Result<Self, JournalError>
Auto Trait Implementations§
impl<F, E, C, H, S> !RefUnwindSafe for Journal<F, E, C, H, S>
impl<F, E, C, H, S> !UnwindSafe for Journal<F, E, C, H, S>
impl<F, E, C, H, S> Freeze for Journal<F, E, C, H, S>
impl<F, E, C, H, S> Send for Journal<F, E, C, H, S>
impl<F, E, C, H, S> Sync for Journal<F, E, C, H, S>
impl<F, E, C, H, S> Unpin for Journal<F, E, C, H, S>
impl<F, E, C, H, S> UnsafeUnpin for Journal<F, E, C, H, S>where
Merkle<F, E, <H as Hasher>::Digest, S>: UnsafeUnpin,
C: UnsafeUnpin,
Standard<H>: UnsafeUnpin,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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> ⓘ
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
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