pub struct AttachRegistry { /* private fields */ }Expand description
Live set of attachments keyed by alias. Thread-safe via an internal
Mutex; all operations are serial, which matches the rest of the
engine’s single-connection model.
The registry holds user-attached databases — the default persistent
database is attached directly by crate::engine::Engine and isn’t
tracked here. Replay-on-reconnect only re-issues the user attaches;
the engine re-attaches persistent itself when it’s reconstructed.
Implementations§
Source§impl AttachRegistry
impl AttachRegistry
pub fn new() -> Self
Sourcepub fn attach(
&self,
engine: &Engine,
req: AttachRequest,
) -> Result<AttachedDb, McpError>
pub fn attach( &self, engine: &Engine, req: AttachRequest, ) -> Result<AttachedDb, McpError>
Attach a database into the current engine’s connection and store
it in the registry. Caller is responsible for read-only
enforcement (--read-only + writable: true combination).
§Errors
- Returns
ErrorCode::InvalidArgumentif the alias failsvalidate_alias, if the alias is already in use, or ifon_missing=Createis combined withwritable=false. - Returns
ErrorCode::FileNotFoundwhenon_missing=Errorand the target.hyperpath does not exist. - Returns
ErrorCode::InternalErrorif the registry mutex is poisoned (bubbled up fromAttachRegistry::lock). - Propagates any error from the underlying
ATTACH DATABASE(and the optionalCREATE DATABASE IF NOT EXISTS) executed on the engine’s connection — surfaced through the?operator in the body.
Sourcepub fn detach(&self, engine: &Engine, alias: &str) -> Result<bool, McpError>
pub fn detach(&self, engine: &Engine, alias: &str) -> Result<bool, McpError>
Detach the alias from the current connection and drop it from
the registry. Returns Ok(false) if the alias was not present.
When the detachment leaves the registry empty, restores the
connection’s default schema_search_path so unqualified name
resolution returns to the single-database mode Hyper uses on a
fresh connection.
§Errors
- Returns
ErrorCode::InternalErrorif the registry mutex is poisoned. - Propagates any error from the
DETACH DATABASEstatement executed viaengine.execute_command. A failure to reset theschema_search_pathafterwards is logged but NOT surfaced as an error — the detach itself already succeeded.
Sourcepub fn list(&self) -> Vec<AttachedDb>
pub fn list(&self) -> Vec<AttachedDb>
Read-only snapshot of the current registry. Order matches the insertion order of still-live entries.
Sourcepub fn get(&self, alias: &str) -> Option<AttachedDb>
pub fn get(&self, alias: &str) -> Option<AttachedDb>
Lookup by alias (case-insensitive). None if absent.
Aliases are stored lowercased (see AttachRegistry::attach),
so any caller supplying a mixed-case alias still finds the
stored entry.
Sourcepub fn replay_all(&self, engine: &Engine) -> Result<(), McpError>
pub fn replay_all(&self, engine: &Engine) -> Result<(), McpError>
Re-issue ATTACH DATABASE for every tracked entry. Used after
crate::server::HyperMcpServer’s with_engine rebuilds a
fresh Engine following a ConnectionLost error.
Attachments that fail to replay (file moved, corrupted, held by another process) are dropped from the registry with a WARN log so the rest of the session can continue — a single stale entry should not poison the whole reconnect path.
§Errors
Returns ErrorCode::InternalError if the registry mutex is
poisoned. Per-entry replay failures are logged and swallowed —
the method only returns Err for errors that prevent it from
running at all.
Trait Implementations§
Source§impl Debug for AttachRegistry
impl Debug for AttachRegistry
Auto Trait Implementations§
impl !Freeze for AttachRegistry
impl RefUnwindSafe for AttachRegistry
impl Send for AttachRegistry
impl Sync for AttachRegistry
impl Unpin for AttachRegistry
impl UnsafeUnpin for AttachRegistry
impl UnwindSafe for AttachRegistry
Blanket Implementations§
impl<T> Allocation for T
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> 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