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§
Sourcepub fn new(label: &'static str, db: DB) -> Self
pub fn new(label: &'static str, db: DB) -> Self
Create a cell holding db, identified by label in lock traces.
Sourcepub async fn read(&self) -> ReadGuard<'_, DB>
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.
Sourcepub async fn write(&self) -> (WriteSlot<'_, DB>, DB)
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§type Unmerkleized = <T as ManagedDb<E>>::Unmerkleized
type Unmerkleized = <T as ManagedDb<E>>::Unmerkleized
ManagedDb::Unmerkleized for every database in the set.Source§type Merkleized = <T as ManagedDb<E>>::Merkleized
type Merkleized = <T as ManagedDb<E>>::Merkleized
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>
type Readers = Reader<T>
Source§type Config = <T as ManagedDb<E>>::Config
type Config = <T as ManagedDb<E>>::Config
Source§type SyncTargets = <T as ManagedDb<E>>::SyncTarget
type SyncTargets = <T as ManagedDb<E>>::SyncTarget
Source§async fn init(context: E, config: Self::Config) -> Self
async fn init(context: E, config: Self::Config) -> Self
Source§fn initial_sync_targets() -> Self::SyncTargets
fn initial_sync_targets() -> Self::SyncTargets
Source§async fn new_batches(&self) -> Self::Unmerkleized
async fn new_batches(&self) -> Self::Unmerkleized
Source§fn fork_batches(parent: &Self::Merkleized) -> Self::Unmerkleized
fn fork_batches(parent: &Self::Merkleized) -> Self::Unmerkleized
Source§fn matches_sync_targets(
batches: &Self::Merkleized,
targets: &Self::SyncTargets,
) -> bool
fn matches_sync_targets( batches: &Self::Merkleized, targets: &Self::SyncTargets, ) -> bool
Source§async fn apply(&self, batches: Self::Merkleized)
async fn apply(&self, batches: Self::Merkleized)
Source§async fn finalize(&self) -> Barrier
async fn finalize(&self) -> Barrier
Source§async fn prune(&self, target: &Self::SyncTargets)
async fn prune(&self, target: &Self::SyncTargets)
Source§async fn committed_targets(&self) -> Self::SyncTargets
async fn committed_targets(&self) -> Self::SyncTargets
Source§async fn rewind_to_targets(&self, target: Self::SyncTargets)
async fn rewind_to_targets(&self, target: Self::SyncTargets)
Source§type Family = <Arc<TracedAsyncRwLock<Option<DB>>> as Source>::Family
type Family = <Arc<TracedAsyncRwLock<Option<DB>>> as Source>::Family
Source§type Digest = <Arc<TracedAsyncRwLock<Option<DB>>> as Source>::Digest
type Digest = <Arc<TracedAsyncRwLock<Option<DB>>> as Source>::Digest
Source§type Op = <Arc<TracedAsyncRwLock<Option<DB>>> as Source>::Op
type Op = <Arc<TracedAsyncRwLock<Option<DB>>> as Source>::Op
Source§type Error = <T as StateSyncDb<E, R>>::SyncError
type Error = <T as StateSyncDb<E, R>>::SyncError
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>
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>
Auto Trait Implementations§
Blanket Implementations§
Source§async fn attach_databases(&self, db: Shared<DB>)
async fn attach_databases(&self, db: Shared<DB>)
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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