pub struct Session<T = Timestamp> {
conn_id: u32,
prepared_statements: HashMap<String, PreparedStatement>,
portals: HashMap<String, Portal>,
transaction: TransactionStatus<T>,
pcx: Option<PlanContext>,
user: String,
vars: Vars,
drop_sinks: Vec<(ComputeInstanceId, GlobalId)>,
}Expand description
A session holds per-connection state.
Fields
conn_id: u32prepared_statements: HashMap<String, PreparedStatement>portals: HashMap<String, Portal>transaction: TransactionStatus<T>pcx: Option<PlanContext>user: Stringvars: Varsdrop_sinks: Vec<(ComputeInstanceId, GlobalId)>Implementations
sourceimpl<T: CoordTimestamp> Session<T>
impl<T: CoordTimestamp> Session<T>
sourcepub fn new(conn_id: u32, user: String) -> Session<T>
pub fn new(conn_id: u32, user: String) -> Session<T>
Creates a new session for the specified connection ID.
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.
fn new_internal(conn_id: u32, user: String) -> Session<T>
sourcepub fn pcx(&self) -> &PlanContext
pub fn pcx(&self) -> &PlanContext
Returns the current transaction’s PlanContext. Panics if there is not a current transaction.
sourcepub fn start_transaction(
self,
wall_time: DateTime<Utc>,
access: Option<TransactionAccessMode>
) -> Self
pub fn start_transaction(
self,
wall_time: DateTime<Utc>,
access: Option<TransactionAccessMode>
) -> Self
Starts an explicit transaction, or changes an implicit to an explicit transaction.
sourcepub fn start_transaction_implicit(
self,
wall_time: DateTime<Utc>,
stmts: usize
) -> Self
pub fn start_transaction_implicit(
self,
wall_time: DateTime<Utc>,
stmts: usize
) -> Self
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 clear_transaction(
&mut self
) -> (Vec<(ComputeInstanceId, GlobalId)>, TransactionStatus<T>)
pub fn clear_transaction(
&mut self
) -> (Vec<(ComputeInstanceId, GlobalId)>, 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 add_transaction_ops(
&mut self,
add_ops: TransactionOps<T>
) -> Result<(), CoordError>
pub fn add_transaction_ops(
&mut self,
add_ops: TransactionOps<T>
) -> Result<(), CoordError>
Adds operations to the current transaction. An error is produced if they cannot be merged (i.e., a read cannot be merged to an insert).
sourcepub fn add_drop_sink(
&mut self,
compute_instance: ComputeInstanceId,
name: GlobalId
)
pub fn add_drop_sink(
&mut self,
compute_instance: ComputeInstanceId,
name: GlobalId
)
Adds a sink that will need to be dropped when the current transaction is cleared.
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 get_transaction_timestamp(&self) -> Option<T>
pub fn get_transaction_timestamp(&self) -> Option<T>
Returns the transaction’s read timestamp, if set.
Returns None if there is no active transaction, or if the active
transaction is not a read transaction.
sourcepub fn set_prepared_statement(
&mut self,
name: String,
statement: PreparedStatement
)
pub fn set_prepared_statement(
&mut self,
name: String,
statement: PreparedStatement
)
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) -> &HashMap<String, PreparedStatement>
pub fn prepared_statements(&self) -> &HashMap<String, PreparedStatement>
Returns the prepared statements for the session.
sourcepub fn set_portal(
&mut self,
portal_name: String,
desc: StatementDesc,
stmt: Option<Statement<Raw>>,
params: Vec<(Datum<'_>, ScalarType)>,
result_formats: Vec<Format>,
catalog_revision: u64
) -> Result<(), CoordError>
pub fn set_portal(
&mut self,
portal_name: String,
desc: StatementDesc,
stmt: Option<Statement<Raw>>,
params: Vec<(Datum<'_>, ScalarType)>,
result_formats: Vec<Format>,
catalog_revision: u64
) -> Result<(), CoordError>
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.
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>>,
desc: StatementDesc,
parameters: Params,
result_formats: Vec<Format>,
catalog_revision: u64
) -> Result<String, CoordError>
pub fn create_new_portal(
&mut self,
stmt: Option<Statement<Raw>>,
desc: StatementDesc,
parameters: Params,
result_formats: Vec<Format>,
catalog_revision: u64
) -> Result<String, CoordError>
Creates and installs a new portal.
sourcepub fn reset(&mut self) -> Vec<(ComputeInstanceId, GlobalId)>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
pub fn reset(&mut self) -> Vec<(ComputeInstanceId, GlobalId)>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
Resets the session to its initial state. Returns sinks that need to be dropped.
sourcepub fn vars_mut(&mut self) -> &mut Vars
pub fn vars_mut(&mut self) -> &mut Vars
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.
Trait Implementations
Auto Trait Implementations
impl<T = u64> !RefUnwindSafe for Session<T>
impl<T> Send for Session<T> where
T: Send,
impl<T> Sync for Session<T> where
T: Sync,
impl<T> Unpin for Session<T> where
T: Unpin,
impl<T = u64> !UnwindSafe for Session<T>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> FutureExt for T
impl<T> FutureExt for T
sourcefn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
sourcefn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
sourcefn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message T in a tonic::Request
sourceimpl<P, R> ProtoType<R> for P where
R: RustType<P>,
impl<P, R> ProtoType<R> for P where
R: RustType<P>,
sourcefn into_rust(self) -> Result<R, TryFromProtoError>
fn into_rust(self) -> Result<R, TryFromProtoError>
See RustType::from_proto.
sourcefn from_rust(rust: &R) -> P
fn from_rust(rust: &R) -> P
See RustType::into_proto.
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
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
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber to this type, returning a
WithDispatch wrapper. Read more