Skip to main content

Shared

Struct Shared 

Source
pub struct Shared<DB>(/* private fields */);
Expand description

A database shared across tasks.

Owned mutations (apply, finalize, prune, rewind) take the database out of the cell under the write lock (Self::write) and put it back on success (WriteSlot::put). A failure, panic, or cancellation mid-operation leaves the cell empty permanently, and every later Self::read or Self::write panics. A lost database is fatal here by design and requires a restart. Serve calls instead report the source as missing, so remote sync degrades without crashing.

Implementations§

Source§

impl<DB> Shared<DB>

Source

pub fn new(label: &'static str, db: DB) -> Self

Create a cell holding db, identified by label in lock traces.

Source

pub async fn read(&self) -> ReadGuard<'_, DB>

Acquire shared read access to the database.

The lock is write-preferring: once a writer is queued, new readers wait behind it. Holding a guard across an await that acquires this cell again therefore deadlocks once a writer arrives in between.

§Panics

Panics if the database was lost by an earlier failed or interrupted mutation.

Source

pub async fn write(&self) -> (WriteSlot<'_, DB>, DB)

Take the database out for a by-value mutation.

The returned WriteSlot holds the cell locked and empty until WriteSlot::put restores the database. Dropping the slot without a put leaves the database lost.

§Panics

Panics if the database was lost by an earlier failed or interrupted mutation.

Trait Implementations§

Source§

impl<DB> Clone for Shared<DB>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<E: Send + Sync, T: ManagedDb<E> + 'static> DatabaseSet<E> for Shared<T>

Implement DatabaseSet for a single ManagedDb behind a lock.

Source§

type Unmerkleized = <T as ManagedDb<E>>::Unmerkleized

Tuple of ManagedDb::Unmerkleized for every database in the set.
Source§

type Merkleized = <T as ManagedDb<E>>::Merkleized

Tuple of ManagedDb::Merkleized for every database in the set. Cloning must preserve the same sealed branch state and should be cheap.
Source§

type Readers = Reader<T>

Read-only handles for observing the applied database state. Read more
Source§

type Config = <T as ManagedDb<E>>::Config

Configuration needed to construct every database in the set. Read more
Source§

type SyncTargets = <T as ManagedDb<E>>::SyncTarget

Per-database sync targets extracted from a finalized block. Read more
Source§

async fn init(context: E, config: Self::Config) -> Self

Construct the database set from its configuration.
Source§

fn initial_sync_targets() -> Self::SyncTargets

Return the sync targets produced by a newly initialized database set.
Source§

async fn new_batches(&self) -> Self::Unmerkleized

Create unmerkleized batches from each database’s applied state. Read more
Source§

fn fork_batches(parent: &Self::Merkleized) -> Self::Unmerkleized

Create child unmerkleized batches from a pending merkleized parent. Read more
Source§

fn matches_sync_targets( batches: &Self::Merkleized, targets: &Self::SyncTargets, ) -> bool

Return true if merkleized batches match the sync targets.
Source§

fn readers(&self) -> Self::Readers

Return read-only handles for every database in the set.
Source§

async fn apply(&self, batches: Self::Merkleized)

Apply each merkleized batch’s changeset. Read more
Source§

async fn finalize(&self) -> Barrier

Begin persisting every checkpoint applied before this call. Read more
Source§

async fn prune(&self, target: &Self::SyncTargets)

Prune each database to the provided per-database targets. Read more
Source§

async fn committed_targets(&self) -> Self::SyncTargets

Return the latest applied recovery targets. Read more
Source§

async fn rewind_to_targets(&self, target: Self::SyncTargets)

Rewind the set to the provided per-database targets. Read more
Source§

impl<DB> Source for Shared<DB>
where DB: Send + Sync + 'static, Arc<TracedAsyncRwLock<Option<DB>>>: Source,

Source§

type Family = <Arc<TracedAsyncRwLock<Option<DB>>> as Source>::Family

The merkle family backing this source’s proofs.
Source§

type Digest = <Arc<TracedAsyncRwLock<Option<DB>>> as Source>::Digest

The digest type used in this source’s proofs.
Source§

type Op = <Arc<TracedAsyncRwLock<Option<DB>>> as Source>::Op

The type of operations this source yields.
Source§

type Error = <Arc<TracedAsyncRwLock<Option<DB>>> as Source>::Error

Why this source could not answer.
Source§

async fn serve( &self, request: Request<Self::Family>, ) -> Result<(Response<Self::Family, Self::Op, Self::Digest>, FeedbackTx), Self::Error>

Serve a request.
Source§

impl<E, T, R, D> StateSyncSet<E, R, D> for Shared<T>
where E: Send + Sync + Metrics, T: StateSyncDb<E, R> + 'static, R: Send + 'static, D: Digest,

Source§

type Error = <T as StateSyncDb<E, R>>::SyncError

Error returned if any database in the set fails state sync.
Source§

async fn sync( context: E, config: Self::Config, source: R, anchor: Anchor<D>, target: Self::SyncTargets, tip_updates: Receiver<TipUpdate<D, Self::SyncTargets>>, sync_config: SyncEngineConfig, ) -> Result<(Self, Anchor<D>), Self::Error>

Run one-time state sync and return the initialized set together with the anchor all databases converged on.

Auto Trait Implementations§

§

impl<DB> !RefUnwindSafe for Shared<DB>

§

impl<DB> !UnwindSafe for Shared<DB>

§

impl<DB> Freeze for Shared<DB>

§

impl<DB> Send for Shared<DB>

§

impl<DB> Sync for Shared<DB>

§

impl<DB> Unpin for Shared<DB>

§

impl<DB> UnsafeUnpin for Shared<DB>

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<R, DB> AttachableResolverSet<Shared<DB>> for R
where R: AttachableResolver<DB>, DB: Send + Sync + 'static,

Source§

async fn attach_databases(&self, db: Shared<DB>)

Attach all databases to their corresponding resolvers.
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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
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<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + 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: Sized + 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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<DB, S> SourceFor<DB> for S
where S: Source<Family = <DB as Database>::Family, Op = <DB as Database>::Op, Digest = <DB as Database>::Digest> + 'static, DB: Database,

Source§

impl<T> Threaded<T> for T

Source§

type Rest = ()

The outputs beyond the threaded value.
Source§

fn split(self) -> (T, ())

Splits into the threaded value and the extra outputs.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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