Struct LivePostgresProjectionStore
#[non_exhaustive]pub struct LivePostgresProjectionStore { /* private fields */ }projection-store only.Expand description
A Postgres-backed projection store whose batches are live transactions.
See the module documentation for what this store is for and what it cannot do.
Implementations§
Trait Implementations§
§impl Clone for LivePostgresProjectionStore
impl Clone for LivePostgresProjectionStore
§impl Debug for LivePostgresProjectionStore
impl Debug for LivePostgresProjectionStore
§impl ProjectionProbe for LivePostgresProjectionStore
The conformance suite’s write and read seam — and here every member is a
statement on the open transaction.
impl ProjectionProbe for LivePostgresProjectionStore
The conformance suite’s write and read seam — and here every member is a statement on the open transaction.
§const READS_THROUGH_BATCH: bool = true
const READS_THROUGH_BATCH: bool = true
true, and true of the store: a SELECT through the open transaction
sees the transaction’s own uncommitted writes. This is the declaration a
live-transaction adapter could not make honestly before ADR-0062, and the
one that makes the two ends of PS-2’s axis distinguishable to the suite.
§async fn probe_write(
&self,
batch: &mut Self::Batch,
key: &str,
value: u64,
) -> Result<(), Self::Error>
async fn probe_write( &self, batch: &mut Self::Batch, key: &str, value: u64, ) -> Result<(), Self::Error>
Upserts one probe row on the server, inside the open transaction.
§async fn probe_delete_all(
&self,
batch: &mut Self::Batch,
) -> Result<(), Self::Error>
async fn probe_delete_all( &self, batch: &mut Self::Batch, ) -> Result<(), Self::Error>
Deletes every probe row inside the open transaction.
§async fn probe_read(&self, key: &str) -> Result<Option<u64>, Self::Error>
async fn probe_read(&self, key: &str) -> Result<Option<u64>, Self::Error>
Reads one probe row from committed state, through the pool.
§async fn probe_read_through(
&self,
batch: &mut Self::Batch,
key: &str,
) -> Result<Option<u64>, Self::Error>
async fn probe_read_through( &self, batch: &mut Self::Batch, key: &str, ) -> Result<Option<u64>, Self::Error>
Reads one probe row through the open transaction: committed state, with this batch’s own pending writes layered over it by the server.
Not refused on a Poisoned
batch: it is the suite’s seam rather than a write, and the transaction
it reads through is still open on the server.
§impl SendProjectionStore for LivePostgresProjectionStore
impl SendProjectionStore for LivePostgresProjectionStore
§type Batch = LivePostgresBatch
type Batch = LivePostgresBatch
A live transaction. This is the binding the phase-2 skeleton declared
and could not discharge while begin was synchronous; ADR-0062 is what
made it inhabitable.
§async fn begin(&self) -> Result<Self::Batch, Self::Error>
async fn begin(&self) -> Result<Self::Batch, Self::Error>
Acquires a pooled connection and issues BEGIN on it.
A round trip, and the failure begin’s Result exists for: a pool with
no free connection, a server that refused the session.
§Errors
PostgresProjectionStoreError::Driver if the pool or the server
refused to open a transaction.
§async fn checkpoint(&self, id: &ProjectionId) -> Result<Checkpoint, Self::Error>
async fn checkpoint(&self, id: &ProjectionId) -> Result<Checkpoint, Self::Error>
Reads id’s checkpoint, or Checkpoint::NeverRun when it has no row.
Through the pool rather than through any open batch: a checkpoint read is committed state, and a batch is not a parameter here.
§Errors
PostgresProjectionStoreError::Driverif the pool or the server rejected the read;CheckpointOutOfRangeorInvalidAuthorityif the row is one this adapter could not have written.
§async fn commit(
&self,
batch: Self::Batch,
id: &ProjectionId,
position: SequencePosition,
authority: Authority,
) -> Result<(), CommitError<Self::Error>>
async fn commit( &self, batch: Self::Batch, id: &ProjectionId, position: SequencePosition, authority: Authority, ) -> Result<(), CommitError<Self::Error>>
Advances id’s checkpoint to position on the batch’s own transaction,
then commits it.
The regression guard is the same guarded upsert the buffered store uses,
for the same reason: ON CONFLICT DO UPDATE takes the row lock, so two
runners racing on one ProjectionId are serialised by Postgres rather
than by this adapter. What differs is what a refusal costs. The caller’s
statements are already on the server inside this transaction, so the
refusal path issues an explicit ROLLBACK rather than relying on a drop —
and it does so before building the error, so that a rollback failure is
reported rather than swallowed behind a regression that was only half of
what went wrong.
§Errors
CommitError::ForeignBatchifbatchwas begun on a different store instance, decided before any statement is issued — the foreign batch’s transaction is dropped, which rolls it back;CommitError::CheckpointRegressionifpositionis below the one recorded;CommitError::StorecarryingPoisonedif a statement was refused before it reached the server — the transaction is rolled back first, and a rollback failure is reported in its place;CommitError::Storeif the driver or the server failed, including a transaction already aborted by an earlier failed statement.
§async fn reset(
&self,
batch: Self::Batch,
id: &ProjectionId,
) -> Result<(), ResetError<Self::Error>>
async fn reset( &self, batch: Self::Batch, id: &ProjectionId, ) -> Result<(), ResetError<Self::Error>>
Deletes id’s checkpoint on the batch’s own transaction, then commits
it. The caller’s deletes are already in the transaction.
§Errors
ResetError::ForeignBatchifbatchwas begun on a different store instance;ResetError::StorecarryingPoisonedif a statement was refused before it reached the server — the transaction is rolled back first, and a rollback failure is reported in its place;ResetError::Storeif the driver or the server failed.
ResetError::Refused is never returned: this store holds no protection
policy, for the reason its buffered sibling gives.
§async fn rollback(&self, batch: Self::Batch) -> Result<(), Self::Error>
async fn rollback(&self, batch: Self::Batch) -> Result<(), Self::Error>
Rolls the transaction back and returns its connection to the pool.
Not a drop: the statements are on the server, and ROLLBACK is a round
trip that can fail, which is the whole reason the port keeps rollback
as a method beside Drop.
§Errors
PostgresProjectionStoreError::ForeignBatchifbatchwas begun on a different store instance — the batch is consumed and its transaction dropped either way;PostgresProjectionStoreError::Driverif theROLLBACKfailed.
§type Error = PostgresProjectionStoreError
type Error = PostgresProjectionStoreError
Auto Trait Implementations§
impl !RefUnwindSafe for LivePostgresProjectionStore
impl !UnwindSafe for LivePostgresProjectionStore
impl Freeze for LivePostgresProjectionStore
impl Send for LivePostgresProjectionStore
impl Sync for LivePostgresProjectionStore
impl Unpin for LivePostgresProjectionStore
impl UnsafeUnpin for LivePostgresProjectionStore
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> 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