Skip to main content

PoolRegistry

Struct PoolRegistry 

Source
pub struct PoolRegistry {
    pub sessions: Vec<PoolSessionEntry>,
}
Expand description

In-memory view of registry.json.

This struct must always be loaded from and saved to disk within a single advisory-lock region (see with_registry_lock). Do not hold a PoolRegistry value across lock boundaries.

§Crux: registry.json is the persistent source of truth

MCP processes must not rely on any in-memory state to discover live workers after a restart. Every mutation path must call save before dropping the lock.

Fields§

§sessions: Vec<PoolSessionEntry>

All currently-registered worker sessions.

Implementations§

Source§

impl PoolRegistry

Source

pub fn load_or_default(path: &Path) -> Result<Self, PoolError>

Load registry.json from disk, returning an empty registry if the file does not exist.

§Arguments
  • path — absolute path to registry.json.
§Returns

Ok(PoolRegistry) — either the parsed on-disk state or an empty registry when the file is absent.

§Errors

Returns PoolError::RegistryCorrupted(reason) if the file exists but cannot be parsed as valid JSON. Never falls back to an empty registry on parse failure — callers must handle the error explicitly and propagate it to the MCP wire layer.

§Concurrency

This is a synchronous file read. The caller must hold the advisory fs4::fs_std::FileExt::lock_exclusive on registry.lock before calling this method to prevent concurrent read-modify-write races between multiple MCP processes.

Source

pub fn save(&self, path: &Path) -> Result<(), PoolError>

Atomically persist the registry to registry.json via tempfile::NamedTempFile::persist (POSIX rename(2)).

§Arguments
  • path — absolute path to registry.json.
§Returns

Ok(()) on success.

§Errors

Returns PoolError::RegistryCorrupted if parent-directory creation, serialization, temp-file creation/write/fsync, or the atomic rename fails.

§Atomicity

NamedTempFile::persist is atomic on modern Linux filesystems and macOS. It is not guaranteed atomic on all platforms.

§Concurrency

Callers must hold the advisory fs4::fs_std::FileExt::lock_exclusive on registry.lock for the entire read-modify-write cycle (load → mutate → save) to prevent last-writer-wins data loss when multiple MCP processes write concurrently.

Source

pub fn scan_and_gc(&mut self) -> Result<Vec<PoolSessionEntry>, PoolError>

Scan all registered sessions and remove entries whose worker process is no longer alive, returning the surviving (live) entries.

Liveness is tested with kill(pid, 0) (POSIX signal 0 — does not send a signal, only checks whether the process exists). An ESRCH return value means the process does not exist and the entry is pruned.

§Arguments

None — operates on &mut self in place.

§Returns

Ok(Vec<PoolSessionEntry>) — the subset of sessions that survived GC (i.e. whose worker process is still alive).

§Errors

Currently infallible on POSIX; the Result wrapper is kept for future extension.

§Platform support

On non-Unix targets the liveness check is omitted and all entries are assumed live (conservative).

Source

pub fn add(&mut self, entry: PoolSessionEntry)

Add a session entry to the registry.

§Arguments
  • entry — the PoolSessionEntry to insert.
§Notes

Does not persist to disk. Call save after mutating to ensure durability.

Source

pub fn remove(&mut self, sid: &str) -> bool

Remove the entry with the given session ID.

§Arguments
  • sid — session ID to remove.
§Returns

true if an entry was found and removed, false if no matching entry existed.

§Notes

Does not persist to disk. Call save after mutating to ensure durability.

Source

pub fn find(&self, sid: &str) -> Option<&PoolSessionEntry>

Look up a session entry by ID.

§Arguments
  • sid — session ID to search for.
§Returns

Some(&PoolSessionEntry) if found, None otherwise.

Trait Implementations§

Source§

impl Clone for PoolRegistry

Source§

fn clone(&self) -> PoolRegistry

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PoolRegistry

Source§

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

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

impl Default for PoolRegistry

Source§

fn default() -> PoolRegistry

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

impl<'de> Deserialize<'de> for PoolRegistry

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for PoolRegistry

Source§

fn eq(&self, other: &PoolRegistry) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for PoolRegistry

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for PoolRegistry

Auto Trait Implementations§

Blanket Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> MaybeSend for T
where T: Send,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> Scalar for T
where T: 'static + Clone + PartialEq + Debug,

Source§

impl<T> Serialize for T
where T: Serialize + ?Sized,

Source§

fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<(), Error>

Source§

fn do_erased_serialize( &self, serializer: &mut dyn Serializer, ) -> Result<(), ErrorImpl>

Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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