Skip to main content

LivePostgresProjectionStore

Struct LivePostgresProjectionStore 

#[non_exhaustive]
pub struct LivePostgresProjectionStore { /* private fields */ }
Available on crate feature 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§

§

impl LivePostgresProjectionStore

pub fn new(pool: PgPool) -> Self

Wraps an existing pool.

pub fn pool(&self) -> &PgPool

The pool this store opens transactions on.

Trait Implementations§

§

impl Clone for LivePostgresProjectionStore

§

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
§

impl Debug for LivePostgresProjectionStore

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
§

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

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>

Upserts one probe row on the server, inside the open transaction.

§

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>

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>

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

§

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>

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>

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
§

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::ForeignBatch if batch was begun on a different store instance, decided before any statement is issued — the foreign batch’s transaction is dropped, which rolls it back;
  • CommitError::CheckpointRegression if position is below the one recorded;
  • CommitError::Store carrying Poisoned if 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::Store if 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>>

Deletes id’s checkpoint on the batch’s own transaction, then commits it. The caller’s deletes are already in the transaction.

§Errors

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>

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
§

type Error = PostgresProjectionStoreError

How this adapter fails.

Auto Trait Implementations§

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
§

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

§

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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

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<TraitVariantBlanketType> ProjectionStore for TraitVariantBlanketType
where TraitVariantBlanketType: SendProjectionStore,

Source§

type Error = <TraitVariantBlanketType as SendProjectionStore>::Error

How this adapter fails.
Source§

type Batch = <TraitVariantBlanketType as SendProjectionStore>::Batch

The adapter’s write set. Read more
Source§

async fn begin( &self, ) -> Result<<TraitVariantBlanketType as ProjectionStore>::Batch, <TraitVariantBlanketType as ProjectionStore>::Error>

Opens a write set. Read more
Source§

async fn checkpoint( &self, id: &ProjectionId, ) -> Result<Checkpoint, <TraitVariantBlanketType as ProjectionStore>::Error>

How far this projection has been brought, and whether its rows are authoritative. Read more
Source§

async fn commit( &self, batch: <TraitVariantBlanketType as ProjectionStore>::Batch, id: &ProjectionId, position: SequencePosition, authority: Authority, ) -> Result<(), CommitError<<TraitVariantBlanketType as ProjectionStore>::Error>>

Applies batch and moves id’s checkpoint to position, as one unit. Read more
Source§

async fn reset( &self, batch: <TraitVariantBlanketType as ProjectionStore>::Batch, id: &ProjectionId, ) -> Result<(), ResetError<<TraitVariantBlanketType as ProjectionStore>::Error>>

Applies batch and returns id to Checkpoint::NeverRun, as one unit. Read more
Source§

async fn rollback( &self, batch: <TraitVariantBlanketType as ProjectionStore>::Batch, ) -> Result<(), <TraitVariantBlanketType as ProjectionStore>::Error>

Discards the batch without committing. Read more
§

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more