| 71 | #[derive(Derivative)] |
| 72 | #[derivative(Debug)] |
| 73 | pub struct Session { |
| 74 | conn_id: ConnectionId, |
| 75 | /// A globally unique identifier for the session. Not to be confused |
| 76 | /// with `conn_id`, which may be reused. |
| 77 | uuid: Uuid, |
| 78 | prepared_statements: BTreeMap<String, PreparedStatement>, |
| 79 | portals: BTreeMap<String, Portal>, |
| 80 | transaction: TransactionStatus, |
| 81 | pcx: Option<PlanContext>, |
| 82 | metrics: SessionMetrics, |
| 83 | #[derivative(Debug = "ignore")] |
| 84 | builtin_updates: Option<BuiltinTableAppendNotify>, |
| 85 | |
| 86 | /// The role metadata of the current session. |
| 87 | /// |
| 88 | /// Invariant: role_metadata must be `Some` after the user has |
| 89 | /// successfully connected to and authenticated with Materialize. |
| 90 | /// |
| 91 | /// Prefer using this value over [`SessionConfig::user`]. |
| 92 | // |
| 93 | // It would be better for this not to be an Option, but the |
| 94 | // `Session` is initialized before the user has connected to |
| 95 | // Materialize and is able to look up the `RoleMetadata`. The `Session` |
| 96 | // is also used to return an error when no role exists and |
| 97 | // therefore there is no valid `RoleMetadata`. |
| 98 | role_metadata: Option<RoleMetadata>, |
| 99 | client_ip: Option<IpAddr>, |
| 100 | vars: SessionVars, |
| 101 | notices_tx: mpsc::UnboundedSender<AdapterNotice>, |
| 102 | notices_rx: mpsc::UnboundedReceiver<AdapterNotice>, |
| 103 | next_transaction_id: TransactionId, |
| 104 | secret_key: u32, |
| 105 | external_metadata_rx: Option<watch::Receiver<ExternalUserMetadata>>, |
| 106 | // Token allowing us to access `Arc<QCell<StatementLogging>>` |
| 107 | // metadata. We want these to be reference-counted, because the same |
| 108 | // statement might be referenced from multiple portals simultaneously. |
| 109 | // |
| 110 | // However, they can't be `Rc<RefCell<StatementLogging>>`, because |
| 111 | // the `Session` is sent around to different threads. |
| 112 | // |
| 113 | // On the other hand, they don't need to be |
| 114 | // `Arc<Mutex<StatementLogging>>`, because they will always be |
| 115 | // accessed from the same thread that the `Session` is currently |
| 116 | // on. We express this by gating access with this token. |
| 117 | #[derivative(Debug = "ignore")] |
| 118 | qcell_owner: QCellOwner, |
| 119 | session_oracles: BTreeMap<Timeline, InMemoryTimestampOracle>, |
| 120 | /// Incremented when session state that is relevant to prepared statement planning changes. |
| 121 | /// Currently, only changes to `portals` are tracked. Changes to `prepared_statements` don't |
| 122 | /// need to be tracked, because prepared statements can't depend on other prepared statements. |
| 123 | /// TODO: We might want to track changes also to session variables. |
| 124 | /// (`Catalog::transient_revision` similarly tracks changes on the catalog side.) |
| 125 | state_revision: u64, |
| 126 | } |
| 127 | |
| 128 | impl SessionMetadata for Session { |
| 129 | fn conn_id(&self) -> &ConnectionId { |
no outgoing calls
no test coverage detected