pub struct DefinitionStore { /* private fields */ }Implementations§
Source§impl DefinitionStore
impl DefinitionStore
Sourcepub fn open(root: PathBuf) -> Result<Self, DefStoreError>
pub fn open(root: PathBuf) -> Result<Self, DefStoreError>
Open or create the store rooted at root. Ensures the active dir
and retired/ subdir both exist.
pub fn root(&self) -> &Path
Sourcepub fn with_record_locked<T>(
&self,
id: &str,
f: impl FnOnce(&LockedRecord<'_>) -> Result<T, DefStoreError>,
) -> Result<T, DefStoreError>
pub fn with_record_locked<T>( &self, id: &str, f: impl FnOnce(&LockedRecord<'_>) -> Result<T, DefStoreError>, ) -> Result<T, DefStoreError>
Run f with record id locked against every other writer, in this
process or another (def_record_lock): a read, merge and write inside
it can’t interleave with another one. Every write below takes it;
a rename that has to read and rewrite the record takes it too. Waits
up to the store’s lock timeout, then fails with
DefStoreError::Locked having written nothing.
Sourcepub fn lock_slug_allocation(&self) -> Result<SlugAllocationLock, DefStoreError>
pub fn lock_slug_allocation(&self) -> Result<SlugAllocationLock, DefStoreError>
The host-wide slug allocation lock, held until the guard drops. A
new agent’s slug is picked against every slug the shared store holds
and then published by mirroring its record: whoever inserts holds this
across both, so two channels or instances creating agents at once
can’t both pick the same free slug. Same bounded wait as a record’s
lock; DefStoreError::Locked names it.
Sourcepub fn lock_seat_graph(&self) -> Result<SlugAllocationLock, DefStoreError>
pub fn lock_seat_graph(&self) -> Result<SlugAllocationLock, DefStoreError>
The host-wide seat lock, held until the guard drops. A seat’s lead is checked against every other agent’s (no cycles) and then written: two clients setting reciprocal leads at once could each pass the check before the other wrote, so a writer holds this across both.
Sourcepub fn upsert(&self, rec: &DefinitionRecord) -> Result<(), DefStoreError>
pub fn upsert(&self, rec: &DefinitionRecord) -> Result<(), DefStoreError>
Insert or update a definition. Preserves unknown top-level + data
fields on an existing file (forward-compat); refuses to overwrite a
corrupt or higher-schema file. An existing record’s slug and former
slugs are kept ([keep_slug_and_former_slugs]): a rename is not an
update. Holds the record’s lock across the read, merge and write.
Sourcepub fn retire(&self, id: &str) -> Result<(), DefStoreError>
pub fn retire(&self, id: &str) -> Result<(), DefStoreError>
Soft-delete → move into retired/ (tombstone). Idempotent. The
tombstone prevents another channel’s migration from resurrecting an
agent the user deliberately deleted.
Sourcepub fn unretire(&self, id: &str) -> Result<(), DefStoreError>
pub fn unretire(&self, id: &str) -> Result<(), DefStoreError>
Move a record back from retired/ to active. Idempotent.
Sourcepub fn hard_delete(&self, id: &str) -> Result<(), DefStoreError>
pub fn hard_delete(&self, id: &str) -> Result<(), DefStoreError>
Hard-delete (drops both active and retired files). Mirrors SQLite
agent_def_delete. Use Self::retire when a resurrection-proof
tombstone is wanted instead.
pub fn exists(&self, id: &str) -> bool
pub fn exists_anywhere(&self, id: &str) -> bool
Sourcepub fn get(&self, id: &str) -> Result<Option<DefinitionRecord>, DefStoreError>
pub fn get(&self, id: &str) -> Result<Option<DefinitionRecord>, DefStoreError>
Read a single active definition record by id. None if absent;
invalid/corrupt files surface as an error (caller logs + falls back).
Sourcepub fn list_active(&self) -> Result<Vec<DefinitionRecord>, DefStoreError>
pub fn list_active(&self) -> Result<Vec<DefinitionRecord>, DefStoreError>
Read every valid active definition. Invalid files are skipped + logged (left on disk for ops triage).
Sourcepub fn list_unreadable(&self) -> Result<Vec<UnreadableRecord>, DefStoreError>
pub fn list_unreadable(&self) -> Result<Vec<UnreadableRecord>, DefStoreError>
The active definition files Self::list_active leaves out, each with why (a newer AgentMux wrote it, it is damaged, it
is incomplete). Reads only: the files stay as they are, so a build that can read them reads them back unchanged.
Sourcepub fn unreadable_reason(&self, id: &str) -> Option<String>
pub fn unreadable_reason(&self, id: &str) -> Option<String>
Why the active definition id cannot be used by this build, or None when it is absent or reads fine.
Sourcepub fn slug_index(
&self,
) -> Result<Arc<HashMap<String, SlugEntry>>, DefStoreError>
pub fn slug_index( &self, ) -> Result<Arc<HashMap<String, SlugEntry>>, DefStoreError>
Every valid active record’s slug and former slugs, by id: what
Self::list_active would give, without reading a file that hasn’t
changed since the last call (def_slug_index). For lookups that run
per message.
Sourcepub fn slug_of_strict(
&self,
id: &str,
) -> Result<Option<SlugEntry>, DefStoreError>
pub fn slug_of_strict( &self, id: &str, ) -> Result<Option<SlugEntry>, DefStoreError>
One active record’s slug and former slugs, read from its file now,
for a caller that must not act on a guess (deleting the agent). None
only when there is no active file. A file that can’t be read, or whose
slug fields can’t be (def_slug_index::slug_fields), is an error. A
record this build otherwise can’t load (a newer schema, a missing name
or provider) still answers when its slug fields can be read.
Sourcepub fn slug_index_strict(
&self,
) -> Result<HashMap<String, SlugEntry>, DefStoreError>
pub fn slug_index_strict( &self, ) -> Result<HashMap<String, SlugEntry>, DefStoreError>
Every active record’s slug and former slugs, for allocating a new
slug: Self::slug_index’s cache, but every record counts, newer
schemas included, and anything that can’t be read (the directory, a
file, a record’s slug fields) is an error rather than skipped.
Sourcepub fn slug_of(&self, id: &str) -> Result<Option<SlugEntry>, DefStoreError>
pub fn slug_of(&self, id: &str) -> Result<Option<SlugEntry>, DefStoreError>
One active record’s slug and former slugs, from the same cache; stats only that record’s file.
Sourcepub fn set_seat(
&self,
id: &str,
seat: Option<&AgentSeat>,
) -> Result<bool, DefStoreError>
pub fn set_seat( &self, id: &str, seat: Option<&AgentSeat>, ) -> Result<bool, DefStoreError>
Set (Some) or remove (None) record id’s seat, leaving every other
field, known to this build or not, as it is on disk. The one writer of
seat: Self::upsert keeps the file’s copy, so a mirror write can’t
clear it. Ok(false) when there is no active record. A record this
build can’t write (unparseable, a newer schema) is an error, not
overwritten.
Source§impl DefinitionStore
impl DefinitionStore
Sourcepub fn handover_of(&self, id: &str) -> Result<Option<Handover>, DefStoreError>
pub fn handover_of(&self, id: &str) -> Result<Option<Handover>, DefStoreError>
Record id’s hand-over mark, read so that it fails closed: from the file’s own JSON, whatever else in the record
this build can or cannot read (a newer schema, a field it does not know). Ok(None): no record, or a record
with no mark. Err: the file could not be read or parsed, so nobody can say the agent is not handed over.
Sourcepub fn set_handover(
&self,
id: &str,
mark: Option<&Handover>,
) -> Result<bool, DefStoreError>
pub fn set_handover( &self, id: &str, mark: Option<&Handover>, ) -> Result<bool, DefStoreError>
Set (Some) or remove (None) record id’s hand-over mark, leaving every other field as it is on disk. The one
writer of handover: Self::upsert keeps the file’s copy, so a mirror write can’t clear it. Ok(false) when
there is no active record.
Auto Trait Implementations§
impl !Freeze for DefinitionStore
impl RefUnwindSafe for DefinitionStore
impl Send for DefinitionStore
impl Sync for DefinitionStore
impl Unpin for DefinitionStore
impl UnsafeUnpin for DefinitionStore
impl UnwindSafe for DefinitionStore
Blanket Implementations§
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
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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