Skip to main content

AttachRegistry

Struct AttachRegistry 

Source
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

Source

pub fn new() -> Self

Source

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::InvalidArgument if the alias fails validate_alias, if the alias is already in use, or if on_missing=Create is combined with writable=false.
  • Returns ErrorCode::FileNotFound when on_missing=Error and the target .hyper path does not exist.
  • Returns ErrorCode::InternalError if the registry mutex is poisoned (bubbled up from AttachRegistry::lock).
  • Propagates any error from the underlying ATTACH DATABASE (and the optional CREATE DATABASE IF NOT EXISTS) executed on the engine’s connection — surfaced through the ? operator in the body.
Source

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::InternalError if the registry mutex is poisoned.
  • Propagates any error from the DETACH DATABASE statement executed via engine.execute_command. A failure to reset the schema_search_path afterwards is logged but NOT surfaced as an error — the detach itself already succeeded.
Source

pub fn list(&self) -> Vec<AttachedDb>

Read-only snapshot of the current registry. Order matches the insertion order of still-live entries.

Source

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.

Source

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

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for AttachRegistry

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,

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

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<L> LayerExt<L> for L

Source§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
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 = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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