pub trait VersionedDataSource: Send + Sync {
type Transaction<'a>: Transaction
where Self: 'a;
type ReadOnly<'a>: Transaction
where Self: 'a;
// Required methods
fn write(
&self,
) -> impl Future<Output = Result<Self::Transaction<'_>>> + Send;
fn read(&self) -> impl Future<Output = Result<Self::ReadOnly<'_>>> + Send;
}
Expand description
A data source with an atomic transaction-based synchronization interface.
Changes are made to a versioned data source through a Transaction
. Any changes made in a
Transaction
are initially visible only when queried through that same Transaction
. They
are not immediately written back to storage, which means that a new data source object opened
against the same persistent storage will not reflect the changes. In particular, this means that
if the process restarts and reopens its storage, uncommitted changes will be lost.
Only when a Transaction
is committed are changes written back to storage, synchronized with
any concurrent changes, and made visible to other connections to the same data source.
Required Associated Types§
Sourcetype Transaction<'a>: Transaction
where
Self: 'a
type Transaction<'a>: Transaction where Self: 'a
A transaction which can read and modify the data source.
type ReadOnly<'a>: Transaction where Self: 'a
Required Methods§
Sourcefn write(&self) -> impl Future<Output = Result<Self::Transaction<'_>>> + Send
fn write(&self) -> impl Future<Output = Result<Self::Transaction<'_>>> + Send
Start an atomic transaction on the data source.
Sourcefn read(&self) -> impl Future<Output = Result<Self::ReadOnly<'_>>> + Send
fn read(&self) -> impl Future<Output = Result<Self::ReadOnly<'_>>> + Send
Start a read-only transaction on the data source.
A read-only transaction allows the owner to string together multiple queries of the data
source, which otherwise would not be atomic with respect to concurrent writes, in an atomic
fashion. Upon returning, read
locks in a fully consistent snapshot of the
data source, and any read operations performed upon the transaction thereafter read from the
same consistent snapshot. Concurrent modifications to the data source may occur (for
example, from concurrent write
transactions being committed), but their
results will not be reflected in a successful read-only transaction which was opened before
the write was committed.
Read-only transactions do not need to be committed, and reverting has no effect.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.