Struct mz_adapter::session::Session
source · pub struct Session<T = Timestamp>{ /* private fields */ }
Expand description
A session holds per-connection state.
Implementations§
source§impl<T: TimestampManipulation> Session<T>
impl<T: TimestampManipulation> Session<T>
sourcepub fn meta(&self) -> SessionMeta
pub fn meta(&self) -> SessionMeta
Returns a reference-less collection of data usable by other tasks that don’t have ownership of the Session.
sourcepub fn uuid(&self) -> Uuid
pub fn uuid(&self) -> Uuid
Returns a unique ID for the session.
Not to be confused with connection_id
, which can be reused.
sourcepub fn dummy() -> Session<T>
pub fn dummy() -> Session<T>
Creates a new dummy session.
Dummy sessions are intended for use when executing queries on behalf of the system itself, rather than on behalf of a user.
sourcepub fn secret_key(&self) -> u32
pub fn secret_key(&self) -> u32
Returns the secret key associated with the session.
sourcepub fn start_transaction(
&mut self,
wall_time: DateTime<Utc>,
access: Option<TransactionAccessMode>,
isolation_level: Option<TransactionIsolationLevel>
) -> Result<(), AdapterError>
pub fn start_transaction( &mut self, wall_time: DateTime<Utc>, access: Option<TransactionAccessMode>, isolation_level: Option<TransactionIsolationLevel> ) -> Result<(), AdapterError>
Starts an explicit transaction, or changes an implicit to an explicit transaction.
sourcepub fn start_transaction_implicit(
&mut self,
wall_time: DateTime<Utc>,
stmts: usize
)
pub fn start_transaction_implicit( &mut self, wall_time: DateTime<Utc>, stmts: usize )
Starts either a single statement or implicit transaction based on the number of statements, but only if no transaction has been started already.
sourcepub fn start_transaction_single_stmt(&mut self, wall_time: DateTime<Utc>)
pub fn start_transaction_single_stmt(&mut self, wall_time: DateTime<Utc>)
Starts a single statement transaction, but only if no transaction has been started already.
sourcepub fn clear_transaction(&mut self) -> TransactionStatus<T>
pub fn clear_transaction(&mut self) -> TransactionStatus<T>
Clears a transaction, setting its state to Default and destroying all portals. Returned are:
- sinks that were started in this transaction and need to be dropped
- the cleared transaction so its operations can be handled
The Postgres protocol docs specify:
a named portal object lasts till the end of the current transaction and An unnamed portal is destroyed at the end of the transaction
sourcepub fn fail_transaction(self) -> Self
pub fn fail_transaction(self) -> Self
Marks the current transaction as failed.
sourcepub fn transaction(&self) -> &TransactionStatus<T>
pub fn transaction(&self) -> &TransactionStatus<T>
Returns the current transaction status.
sourcepub fn transaction_mut(&mut self) -> &mut TransactionStatus<T>
pub fn transaction_mut(&mut self) -> &mut TransactionStatus<T>
Returns the current transaction status.
sourcepub fn transaction_code(&self) -> TransactionCode
pub fn transaction_code(&self) -> TransactionCode
Returns the session’s transaction code.
sourcepub fn add_transaction_ops(
&mut self,
add_ops: TransactionOps<T>
) -> Result<(), AdapterError>
pub fn add_transaction_ops( &mut self, add_ops: TransactionOps<T> ) -> Result<(), AdapterError>
Adds operations to the current transaction. An error is produced if they cannot be merged (i.e., a timestamp-dependent read cannot be merged to an insert).
sourcepub fn retain_notice_transmitter(&self) -> UnboundedSender<AdapterNotice>
pub fn retain_notice_transmitter(&self) -> UnboundedSender<AdapterNotice>
Returns a channel on which to send notices to the session.
sourcepub fn add_notice(&self, notice: AdapterNotice)
pub fn add_notice(&self, notice: AdapterNotice)
Adds a notice to the session.
sourcepub fn add_notices(&self, notices: impl IntoIterator<Item = AdapterNotice>)
pub fn add_notices(&self, notices: impl IntoIterator<Item = AdapterNotice>)
Adds multiple notices to the session.
sourcepub async fn recv_notice(&mut self) -> AdapterNotice
pub async fn recv_notice(&mut self) -> AdapterNotice
Awaits a possible notice.
This method is cancel safe.
sourcepub fn drain_notices(&mut self) -> Vec<AdapterNotice>
pub fn drain_notices(&mut self) -> Vec<AdapterNotice>
Returns a draining iterator over the notices attached to the session.
sourcepub fn clear_transaction_ops(&mut self)
pub fn clear_transaction_ops(&mut self)
Sets the transaction ops to TransactionOps::None
. Must only be used after
verifying that no transaction anomalies will occur if cleared.
sourcepub fn take_transaction_timestamp_context(
&mut self
) -> Option<TimestampContext<T>>
pub fn take_transaction_timestamp_context( &mut self ) -> Option<TimestampContext<T>>
If the current transaction ops belong to a read, then sets the
ops to None
, returning the old read timestamp context if
any existed. Must only be used after verifying that no transaction
anomalies will occur if cleared.
sourcepub fn get_transaction_timestamp_determination(
&self
) -> Option<TimestampDetermination<T>>
pub fn get_transaction_timestamp_determination( &self ) -> Option<TimestampDetermination<T>>
Returns the transaction’s read timestamp determination, if set.
Returns None
if there is no active transaction, or if the active
transaction is not a read transaction.
sourcepub fn contains_read_timestamp(&self) -> bool
pub fn contains_read_timestamp(&self) -> bool
Whether this session has a timestamp for a read transaction.
sourcepub fn set_prepared_statement(
&mut self,
name: String,
stmt: Option<Statement<Raw>>,
raw_sql: String,
desc: StatementDesc,
catalog_revision: u64,
now: EpochMillis
)
pub fn set_prepared_statement( &mut self, name: String, stmt: Option<Statement<Raw>>, raw_sql: String, desc: StatementDesc, catalog_revision: u64, now: EpochMillis )
Registers the prepared statement under name
.
sourcepub fn remove_prepared_statement(&mut self, name: &str) -> bool
pub fn remove_prepared_statement(&mut self, name: &str) -> bool
Removes the prepared statement associated with name
.
Returns whether a statement previously existed.
sourcepub fn remove_all_prepared_statements(&mut self)
pub fn remove_all_prepared_statements(&mut self)
Removes all prepared statements.
sourcepub fn get_prepared_statement_unverified(
&self,
name: &str
) -> Option<&PreparedStatement>
pub fn get_prepared_statement_unverified( &self, name: &str ) -> Option<&PreparedStatement>
Retrieves the prepared statement associated with name
.
This is unverified and could be incorrect if the underlying catalog has changed.
sourcepub fn get_prepared_statement_mut_unverified(
&mut self,
name: &str
) -> Option<&mut PreparedStatement>
pub fn get_prepared_statement_mut_unverified( &mut self, name: &str ) -> Option<&mut PreparedStatement>
Retrieves the prepared statement associated with name
.
This is unverified and could be incorrect if the underlying catalog has changed.
sourcepub fn prepared_statements(&self) -> &BTreeMap<String, PreparedStatement>
pub fn prepared_statements(&self) -> &BTreeMap<String, PreparedStatement>
Returns the prepared statements for the session.
sourcepub fn set_portal(
&mut self,
portal_name: String,
desc: StatementDesc,
stmt: Option<Statement<Raw>>,
logging: Arc<QCell<PreparedStatementLoggingInfo>>,
params: Vec<(Datum<'_>, ScalarType)>,
result_formats: Vec<Format>,
catalog_revision: u64
) -> Result<(), AdapterError>
pub fn set_portal( &mut self, portal_name: String, desc: StatementDesc, stmt: Option<Statement<Raw>>, logging: Arc<QCell<PreparedStatementLoggingInfo>>, params: Vec<(Datum<'_>, ScalarType)>, result_formats: Vec<Format>, catalog_revision: u64 ) -> Result<(), AdapterError>
Binds the specified portal to the specified prepared statement.
If the prepared statement contains parameters, the values and types of
those parameters must be provided in params
. It is the caller’s
responsibility to ensure that the correct number of parameters is
provided.
The results_formats
parameter sets the desired format of the results,
and is stored on the portal.
sourcepub fn remove_portal(&mut self, portal_name: &str) -> bool
pub fn remove_portal(&mut self, portal_name: &str) -> bool
Removes the specified portal.
If there is no such portal, this method does nothing. Returns whether that portal existed.
sourcepub fn get_portal_unverified(&self, portal_name: &str) -> Option<&Portal>
pub fn get_portal_unverified(&self, portal_name: &str) -> Option<&Portal>
Retrieves a reference to the specified portal.
If there is no such portal, returns None
.
sourcepub fn get_portal_unverified_mut(
&mut self,
portal_name: &str
) -> Option<&mut Portal>
pub fn get_portal_unverified_mut( &mut self, portal_name: &str ) -> Option<&mut Portal>
Retrieves a mutable reference to the specified portal.
If there is no such portal, returns None
.
sourcepub fn create_new_portal(
&mut self,
stmt: Option<Statement<Raw>>,
logging: Arc<QCell<PreparedStatementLoggingInfo>>,
desc: StatementDesc,
parameters: Params,
result_formats: Vec<Format>,
catalog_revision: u64
) -> Result<String, AdapterError>
pub fn create_new_portal( &mut self, stmt: Option<Statement<Raw>>, logging: Arc<QCell<PreparedStatementLoggingInfo>>, desc: StatementDesc, parameters: Params, result_formats: Vec<Format>, catalog_revision: u64 ) -> Result<String, AdapterError>
Creates and installs a new portal.
sourcepub fn reset(&mut self)
pub fn reset(&mut self)
Resets the session to its initial state. Returns sinks that need to be dropped.
sourcepub fn application_name(&self) -> &str
pub fn application_name(&self) -> &str
Returns the application_name that created this session.
sourcepub fn vars(&self) -> &SessionVars
pub fn vars(&self) -> &SessionVars
Returns a reference to the variables in this session.
sourcepub fn vars_mut(&mut self) -> &mut SessionVars
pub fn vars_mut(&mut self) -> &mut SessionVars
Returns a mutable reference to the variables in this session.
sourcepub fn grant_write_lock(&mut self, guard: OwnedMutexGuard<()>)
pub fn grant_write_lock(&mut self, guard: OwnedMutexGuard<()>)
Grants the coordinator’s write lock guard to this session’s inner transaction.
Panics
If the inner transaction is idle. See
TransactionStatus::grant_write_lock
.
sourcepub fn has_write_lock(&self) -> bool
pub fn has_write_lock(&self) -> bool
Returns whether or not this session currently holds the write lock.
sourcepub fn apply_external_metadata_updates(&mut self)
pub fn apply_external_metadata_updates(&mut self)
Drains any external metadata updates and applies the changes from the latest update.
sourcepub fn initialize_role_metadata(&mut self, role_id: RoleId)
pub fn initialize_role_metadata(&mut self, role_id: RoleId)
Initializes the session’s role metadata.
sourcepub fn ensure_timestamp_oracle(
&mut self,
timeline: Timeline
) -> &mut InMemoryTimestampOracle<T, NowFn<T>>
pub fn ensure_timestamp_oracle( &mut self, timeline: Timeline ) -> &mut InMemoryTimestampOracle<T, NowFn<T>>
Ensures that a timestamp oracle exists for timeline
and returns a mutable reference to
the timestamp oracle.
sourcepub fn ensure_local_timestamp_oracle(
&mut self
) -> &mut InMemoryTimestampOracle<T, NowFn<T>>
pub fn ensure_local_timestamp_oracle( &mut self ) -> &mut InMemoryTimestampOracle<T, NowFn<T>>
Ensures that a timestamp oracle exists for reads and writes from/to a local input and returns a mutable reference to the timestamp oracle.
sourcepub fn get_timestamp_oracle(
&self,
timeline: &Timeline
) -> Option<&InMemoryTimestampOracle<T, NowFn<T>>>
pub fn get_timestamp_oracle( &self, timeline: &Timeline ) -> Option<&InMemoryTimestampOracle<T, NowFn<T>>>
Returns a reference to the timestamp oracle for timeline
.
sourcepub fn apply_write(&mut self, timestamp: T)
pub fn apply_write(&mut self, timestamp: T)
If the current session is using the Strong Session Serializable isolation level advance the
session local timestamp oracle to write_ts
.
Trait Implementations§
source§impl<T> SessionMetadata for Session<T>
impl<T> SessionMetadata for Session<T>
source§fn conn_id(&self) -> &ConnectionId
fn conn_id(&self) -> &ConnectionId
source§fn pcx(&self) -> &PlanContext
fn pcx(&self) -> &PlanContext
source§fn role_metadata(&self) -> &RoleMetadata
fn role_metadata(&self) -> &RoleMetadata
source§fn vars(&self) -> &SessionVars
fn vars(&self) -> &SessionVars
source§fn current_role_id(&self) -> &RoleId
fn current_role_id(&self) -> &RoleId
source§fn session_role_id(&self) -> &RoleId
fn session_role_id(&self) -> &RoleId
fn user(&self) -> &User
fn database(&self) -> &str
fn search_path(&self) -> &[Ident]
fn is_superuser(&self) -> bool
fn enable_session_rbac_checks(&self) -> bool
Auto Trait Implementations§
impl<T = Timestamp> !RefUnwindSafe for Session<T>
impl<T> Send for Session<T>
impl<T> Sync for Session<T>
impl<T> Unpin for Session<T>where
T: Unpin,
impl<T = Timestamp> !UnwindSafe for Session<T>
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
source§impl<T> FmtForward for T
impl<T> FmtForward for T
source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self
to use its Binary
implementation when Debug
-formatted.source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self
to use its Display
implementation when
Debug
-formatted.source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self
to use its LowerExp
implementation when
Debug
-formatted.source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self
to use its LowerHex
implementation when
Debug
-formatted.source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self
to use its Octal
implementation when Debug
-formatted.source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self
to use its Pointer
implementation when
Debug
-formatted.source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self
to use its UpperExp
implementation when
Debug
-formatted.source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self
to use its UpperHex
implementation when
Debug
-formatted.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>
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> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request
source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read moresource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read moresource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R ) -> R
source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self
, then passes self.as_ref()
into the pipe function.source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self
, then passes self.as_mut()
into the pipe
function.source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self
, then passes self.deref()
into the pipe function.source§impl<T> Pointable for T
impl<T> Pointable for T
source§impl<P, R> ProtoType<R> for Pwhere
R: RustType<P>,
impl<P, R> ProtoType<R> for Pwhere
R: RustType<P>,
source§fn into_rust(self) -> Result<R, TryFromProtoError>
fn into_rust(self) -> Result<R, TryFromProtoError>
RustType::from_proto
.source§fn from_rust(rust: &R) -> P
fn from_rust(rust: &R) -> P
RustType::into_proto
.source§impl<T> Tap for T
impl<T> Tap for T
source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B>
of a value. Read moresource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B>
of a value. Read moresource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R>
view of a value. Read moresource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R>
view of a value. Read moresource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target
of a value. Read moresource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target
of a value. Read moresource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap()
only in debug builds, and is erased in release builds.source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut()
only in debug builds, and is erased in release
builds.source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow()
only in debug builds, and is erased in release
builds.source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut()
only in debug builds, and is erased in release
builds.source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref()
only in debug builds, and is erased in release
builds.source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut()
only in debug builds, and is erased in release
builds.source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref()
only in debug builds, and is erased in release
builds.