Skip to main content

PreparedStatements

Struct PreparedStatements 

Source
pub struct PreparedStatements { /* private fields */ }
Expand description

Per-connection prepared-statement state for the proxy: which canonical statements are prepared on this backend (LRU-bounded), plus the bookkeeping to filter the backend’s ParseComplete/CloseComplete replies that answer messages halephant injected on the client’s behalf.

halephant proxies the extended query protocol with statement-name rewriting and transparent (re)preparation, so it emits Parse/Close messages the client never sent (re-prepares, LRU evictions) and absorbs others (client statement closes). The backend’s reply stream therefore carries ParseComplete/CloseComplete messages that do not match what the client expects, and the proxy must filter them — in FIFO order, correct under pipelining, and rolled back if a Parse is rejected.

The cache and the reply bookkeeping are deliberately one type so the invariant between them — every optimistic insert pairs with a queued reply disposition, and the error path reverts both — is enforced inside these methods rather than by convention across call sites. The methods are pure and return intents; the async proxy layer executes the wire actions. See docs/superpowers/specs/2026-06-30-halephant-prepared-statement-state-design.md for the alternatives considered.

Lives next to ServerConn because it is state that follows a connection through its lifetime — created at connect_server time, travelling through checkout and checkin.

Construct only via PreparedStatements::new so the LRU cap is always explicit; there is no Default (which would silently mean an unbounded cache). Pass max = 0 to opt into unlimited caching.

Implementations§

Source§

impl PreparedStatements

Source

pub fn new(max: u32) -> Self

Source

pub fn note_client_parse(&mut self, canon: &str) -> ClientParse

Handle a client Parse for canon. On a cache hit the statement is already on the backend, so the caller answers synthetically; on a miss the caller forwards the rewritten Parse and the backend’s real ParseComplete flows back to the client in order.

Source

pub fn note_reprepare(&mut self, canon: &str) -> Reprepare

Handle an internal re-prepare triggered by a Bind/Describe whose statement the client never (re-)Parsed. The injected ParseComplete is suppressed.

Source

pub fn note_portal_close(&mut self)

Record that a client portal Close is being forwarded, so its CloseComplete is delivered to the client.

Source

pub fn next_parse_reply(&mut self) -> Reply

Disposition of the next ParseComplete from the backend. Defaults to forwarding when nothing is tracked, so an unexpected reply surfaces to the client rather than being silently dropped.

Source

pub fn next_close_reply(&mut self) -> Reply

Disposition of the next CloseComplete from the backend.

Source

pub fn roll_back_after_error(&mut self)

Reconcile after a backend ErrorResponse aborts the current extended-protocol batch: every message after the error is skipped, so the still-pending replies never arrive. Roll back the optimistic inserts of the unconfirmed Parses and drop the orphaned Close bookkeeping.

Source

pub fn discard_all(&mut self)

DISCARD ALL deallocated every prepared statement on the backend.

Source

pub fn reset_pending(&mut self)

Drop pending reply bookkeeping at a transaction or session boundary. A client that disconnected mid-batch can leave a disposition whose reply the backend skipped and will never send; the cache itself persists across the boundary.

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

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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<'src, T> IntoMaybe<'src, T> for T
where T: 'src,

Source§

type Proj<U: 'src> = U

Source§

fn map_maybe<R>( self, _f: impl FnOnce(&'src T) -> &'src R, g: impl FnOnce(T) -> R, ) -> <T as IntoMaybe<'src, T>>::Proj<R>
where R: 'src,

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> Same for T

Source§

type Output = T

Should always be Self
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