Struct ax_banyan::Transaction

source ·
pub struct Transaction<T: TreeTypes, R, W> { /* private fields */ }
Expand description

Everything that is needed to write trees. To write trees, you also have to read trees.

Implementations§

source§

impl<T, R, W> Transaction<T, R, W>
where T: TreeTypes, R: ReadOnlyStore<T::Link>, W: BlockWriter<T::Link>,

basic random access append only tree

source

pub fn read(&self) -> &Forest<T, R>

source§

impl<T: TreeTypes, R, W> Transaction<T, R, W>

source

pub fn into_writer(self) -> W

Get the writer of the transaction.

This can be used to finally commit the transaction or manually store the content.

source

pub fn writer(&self) -> &W

source

pub fn writer_mut(&mut self) -> &mut W

source§

impl<T: TreeTypes, R, W> Transaction<T, R, W>
where R: ReadOnlyStore<T::Link>, W: BlockWriter<T::Link>,

source

pub fn new(read: Forest<T, R>, writer: W) -> Self

create a new transaction.

It is up to the caller to ensure that the reader reads the writes of the writer, if complex operations that require that should be performed in the transaction.

source§

impl<T: TreeTypes, R: ReadOnlyStore<T::Link>, W: BlockWriter<T::Link>> Transaction<T, R, W>

source

pub fn pack<V: BanyanValue>( &mut self, tree: &mut StreamBuilder<T, V> ) -> Result<()>

Packs the tree to the left.

For an already packed tree, this is a noop. Otherwise, all packed subtrees will be reused without touching them. Likewise, sealed subtrees or leafs will be reused if possible.

packing illustration

source

pub fn push<V: BanyanValue>( &mut self, tree: &mut StreamBuilder<T, V>, key: T::Key, value: V ) -> Result<()>

append a single element. This is just a shortcut for extend.

source

pub fn extend<I, V>( &mut self, tree: &mut StreamBuilder<T, V>, from: I ) -> Result<()>
where I: IntoIterator<Item = (T::Key, V)>, I::IntoIter: Send, V: BanyanValue,

extend the node with the given iterator of key/value pairs

extend illustration

source

pub fn extend_unpacked<I, V>( &mut self, tree: &mut StreamBuilder<T, V>, from: I ) -> Result<()>
where I: IntoIterator<Item = (T::Key, V)>, I::IntoIter: Send, V: BanyanValue,

extend the node with the given iterator of key/value pairs

This variant will not pack the tree, but just create a new tree from the new values and join it with the previous tree via an unpacked branch node. Essentially this will produce a degenerate tree that resembles a linked list.

To pack a tree, use the pack method.

extend_unpacked illustration

source

pub fn retain<'a, Q: Query<T> + Send + Sync, V>( &'a mut self, tree: &mut StreamBuilder<T, V>, query: &'a Q ) -> Result<()>

Retain just data matching the query

this is done as best effort and will not be precise. E.g. if a chunk of data contains just a tiny bit that needs to be retained, the entire chunk will be retained.

from this follows that this is not a suitable method if you want to ensure that the non-matching data is completely gone.

note that offsets will not be affected by this. Also, unsealed nodes will not be forgotten even if they do not match the query.

source

pub fn repair<V>( &mut self, tree: &mut StreamBuilder<T, V> ) -> Result<Vec<String>>

repair a tree by purging parts of the tree that can not be resolved.

produces a report of links that could not be resolved.

Note that this is an emergency measure to recover data if the tree is not completely available. It might result in a degenerate tree that can no longer be safely added to, especially if there are repaired blocks in the non-packed part.

Methods from Deref<Target = Forest<T, R>>§

source

pub fn store(&self) -> &R

source

pub fn stream_trees<Q, S, V>( &self, query: Q, trees: S ) -> impl Stream<Item = Result<(u64, T::Key, V)>> + Send
where Q: Query<T> + Clone, S: Stream<Item = Tree<T, V>> + Send + 'static, V: BanyanValue,

Given a sequence of roots, will stream matching events in ascending order indefinitely.

This is implemented by calling stream_trees_chunked and just flattening the chunks.

source

pub fn stream_trees_chunked<S, Q, V, E, F>( &self, query: Q, trees: S, range: RangeInclusive<u64>, mk_extra: &'static F ) -> impl Stream<Item = Result<FilteredChunk<(u64, T::Key, V), E>>> + Send + 'static
where S: Stream<Item = Tree<T, V>> + Send + 'static, Q: Query<T> + Clone, V: BanyanValue, E: Send + 'static, F: Send + Sync + 'static + Fn(&NodeInfo<T, R>) -> E,

Given a sequence of roots, will stream chunks in ascending order until it arrives at range.end().

  • query: the query
  • roots: the stream of roots. It is assumed that trees later in this stream will be bigger
  • range: the range which to stream. It is up to the caller to ensure that we have events for this range.
  • mk_extra: a fn that allows to compute extra info from indices. this can be useful to get progress info even if the query does not match any events
source

pub fn stream_trees_chunked_threaded<S, Q, V, E, F>( &self, query: Q, trees: S, range: RangeInclusive<u64>, mk_extra: &'static F, thread_pool: ThreadPool ) -> impl Stream<Item = Result<FilteredChunk<(u64, T::Key, V), E>>> + Send + 'static
where S: Stream<Item = Tree<T, V>> + Send + 'static, Q: Query<T> + Clone, V: BanyanValue, E: Send + 'static, F: Send + Sync + 'static + Fn(&NodeInfo<T, R>) -> E,

Given a sequence of roots, will stream chunks in ascending order indefinitely.

Note that this method has no way to know when the query is done. So ending this stream, if desired, will have to be done by the caller using e.g. take_while(...).

  • query: the query
  • roots: the stream of roots. It is assumed that trees later in this stream will be bigger
  • range: the range which to stream. It is up to the caller to ensure that we have events for this range.
  • mk_extra: a fn that allows to compute extra info from indices. this can be useful to get progress info even if the query does not match any events
source

pub fn stream_trees_chunked_reverse<S, Q, V, E, F>( &self, query: Q, trees: S, range: RangeInclusive<u64>, mk_extra: &'static F ) -> impl Stream<Item = Result<FilteredChunk<(u64, T::Key, V), E>>> + Send + 'static
where S: Stream<Item = Tree<T, V>> + Send + 'static, Q: Query<T> + Clone, V: BanyanValue, E: Send + 'static, F: Send + Sync + 'static + Fn(&NodeInfo<T, R>) -> E,

Given a sequence of roots, will stream chunks in reverse order until it arrives at range.start().

Values within chunks are in ascending offset order, so if you flatten them you have to reverse them first.

  • query: the query
  • trees: the stream of roots. It is assumed that trees later in this stream will be bigger
  • range: the range which to stream. It is up to the caller to ensure that we have events for this range.
  • mk_extra: a fn that allows to compute extra info from indices. this can be useful to get progress info even if the query does not match any events
source

pub fn transaction<W: BlockWriter<TT::Link>>( &self, f: impl FnOnce(R) -> (R, W) ) -> Transaction<TT, R, W>

source

pub fn load_stream_builder<V>( &self, secrets: Secrets, config: Config, link: T::Link ) -> Result<StreamBuilder<T, V>>

source

pub fn load_tree<V>( &self, secrets: Secrets, link: T::Link ) -> Result<Tree<T, V>>

source

pub fn dump<V>(&self, tree: &Tree<T, V>) -> Result<()>

dumps the tree structure

source

pub fn dump_graph<S, V>( &self, tree: &Tree<T, V>, f: impl Fn((usize, &NodeInfo<T, R>)) -> S + Clone ) -> Result<(Vec<(usize, usize)>, BTreeMap<usize, S>)>

dumps the tree structure

source

pub fn roots<V>(&self, tree: &StreamBuilder<T, V>) -> Result<Vec<Index<T>>>

sealed roots of the tree

source

pub fn left_roots<V>(&self, tree: &Tree<T, V>) -> Result<Vec<Tree<T, V>>>

leftmost branches of the tree as separate trees

source

pub fn check_invariants<V>( &self, tree: &StreamBuilder<T, V> ) -> Result<Vec<String>>

source

pub fn is_packed<V>(&self, tree: &Tree<T, V>) -> Result<bool>

source

pub fn assert_invariants<V>(&self, tree: &StreamBuilder<T, V>) -> Result<()>

source

pub fn stream_filtered<V: BanyanValue>( &self, tree: &Tree<T, V>, query: impl Query<T> + Clone + 'static ) -> impl Stream<Item = Result<(u64, T::Key, V)>> + 'static

source

pub fn iter_index<V>( &self, tree: &Tree<T, V>, query: impl Query<T> + Clone + 'static ) -> impl Iterator<Item = Result<Index<T>>> + 'static

Returns an iterator yielding all indexes that have values matching the provided query.

source

pub fn iter_index_reverse<V>( &self, tree: &Tree<T, V>, query: impl Query<T> + Clone + 'static ) -> impl Iterator<Item = Result<Index<T>>> + 'static

Returns an iterator yielding all indexes that have values matching the provided query in reverse order.

source

pub fn iter_filtered<V: BanyanValue>( &self, tree: &Tree<T, V>, query: impl Query<T> + Clone + 'static ) -> impl Iterator<Item = Result<(u64, T::Key, V)>> + 'static

source

pub fn iter_filtered_reverse<V: BanyanValue>( &self, tree: &Tree<T, V>, query: impl Query<T> + Clone + 'static ) -> impl Iterator<Item = Result<(u64, T::Key, V)>> + 'static

source

pub fn iter_from<V: BanyanValue>( &self, tree: &Tree<T, V> ) -> impl Iterator<Item = Result<(u64, T::Key, V)>> + 'static

source

pub fn iter_filtered_chunked<Q, V, E, F>( &self, tree: &Tree<T, V>, query: Q, mk_extra: &'static F ) -> impl Iterator<Item = Result<FilteredChunk<(u64, T::Key, V), E>>> + 'static
where Q: Query<T>, V: BanyanValue, E: Send + 'static, F: Fn(&NodeInfo<T, R>) -> E + Send + Sync + 'static,

source

pub fn iter_filtered_chunked_reverse<Q, V, E, F>( &self, tree: &Tree<T, V>, query: Q, mk_extra: &'static F ) -> impl Iterator<Item = Result<FilteredChunk<(u64, T::Key, V), E>>> + 'static
where Q: Query<T>, V: BanyanValue, E: Send + 'static, F: Fn(&NodeInfo<T, R>) -> E + Send + Sync + 'static,

source

pub fn stream_filtered_chunked<Q, V, E, F>( &self, tree: &Tree<T, V>, query: Q, mk_extra: &'static F ) -> impl Stream<Item = Result<FilteredChunk<(u64, T::Key, V), E>>> + 'static
where Q: Query<T>, V: BanyanValue, E: Send + 'static, F: Fn(&NodeInfo<T, R>) -> E + Send + Sync + 'static,

source

pub fn stream_filtered_chunked_reverse<Q, V, E, F>( &self, tree: &Tree<T, V>, query: Q, mk_extra: &'static F ) -> impl Stream<Item = Result<FilteredChunk<(u64, T::Key, V), E>>> + 'static
where Q: Query<T>, V: BanyanValue, E: Send + 'static, F: Fn(&NodeInfo<T, R>) -> E + Send + Sync + 'static,

source

pub fn get<V: BanyanValue>( &self, tree: &Tree<T, V>, offset: u64 ) -> Result<Option<(T::Key, V)>>

element at index

returns Ok(None) when offset is larger than count, or when hitting a purged part of the tree. Returns an error when part of the tree should be there, but could not be read.

source

pub fn collect<V: BanyanValue>( &self, tree: &Tree<T, V> ) -> Result<Vec<Option<(T::Key, V)>>>

Collects all elements from a stream. Might produce an OOM for large streams.

source

pub fn collect_from<V: BanyanValue>( &self, tree: &Tree<T, V>, offset: u64 ) -> Result<Vec<Option<(T::Key, V)>>>

Collects all elements from the given offset. Might produce an OOM for large streams.

Trait Implementations§

source§

impl<T: TreeTypes, R, W> Deref for Transaction<T, R, W>

§

type Target = Forest<T, R>

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.

Auto Trait Implementations§

§

impl<T, R, W> !RefUnwindSafe for Transaction<T, R, W>

§

impl<T, R, W> Send for Transaction<T, R, W>
where R: Send + Sync, W: Send,

§

impl<T, R, W> Sync for Transaction<T, R, W>
where R: Send + Sync, W: Sync,

§

impl<T, R, W> Unpin for Transaction<T, R, W>
where W: Unpin,

§

impl<T, R, W> !UnwindSafe for Transaction<T, R, W>

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.

§

impl<T> References<RawCodec> for T

§

fn references<R, E>(_c: RawCodec, _r: &mut R, _set: &mut E) -> Result<(), Error>
where R: Read, E: Extend<Cid<64>>,

Scrape the references from an impl Read. Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

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

§

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>,

§

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