pub struct Tx<'c> { /* private fields */ }Expand description
A transaction over the store: every query and change is one of its methods; the changes need
&mut, so they are made only in Store::write.
Implementations§
Source§impl Tx<'_>
impl Tx<'_>
Sourcepub fn record_download(
&mut self,
run: Option<&RunName>,
item: &DownloadItem,
) -> Result<bool>
pub fn record_download( &mut self, run: Option<&RunName>, item: &DownloadItem, ) -> Result<bool>
Records that run run’s tool fetched item (no run: adopted); one recorded already keeps
its row. Whether it was new to the record.
§Errors
The store can’t be written.
Sourcepub fn downloads(&self) -> Result<Vec<Download>>
pub fn downloads(&self) -> Result<Vec<Download>>
Every recorded download, oldest first (its size unread).
§Errors
The store can’t be read, or a row holds what this runner doesn’t write.
Sourcepub fn forget_download(&mut self, id: DownloadId) -> Result<()>
pub fn forget_download(&mut self, id: DownloadId) -> Result<()>
Forgets download id (removed, or found gone); one not recorded is fine.
§Errors
The store can’t be written.
Source§impl Tx<'_>
impl Tx<'_>
Sourcepub fn queue_operation(
&mut self,
run: &RunName,
op: Op,
owner: &Owner,
) -> Result<OperationRow>
pub fn queue_operation( &mut self, run: &RunName, op: Op, owner: &Owner, ) -> Result<OperationRow>
Journals operation op on run as queued by owner (a service answering a command): its
id is the one every later event and the client see; Tx::start_operation starts it.
§Errors
The store can’t be written.
Sourcepub fn start_operation(
&mut self,
id: OperationId,
run: &RunName,
owner: &Owner,
resumed_from: Option<OperationId>,
) -> Result<OperationRow>
pub fn start_operation( &mut self, id: OperationId, run: &RunName, owner: &Owner, resumed_from: Option<OperationId>, ) -> Result<OperationRow>
Starts queued operation id of run, owned now by owner, recovering resumed_from when
it found that one unfinished.
§Errors
illegal_transition when id isn’t a queued operation of run (started or ended
already, another run’s, or none); the store’s.
Sourcepub fn begin_operation(
&mut self,
run: &RunName,
op: Op,
owner: &Owner,
resumed_from: Option<OperationId>,
) -> Result<OperationRow>
pub fn begin_operation( &mut self, run: &RunName, op: Op, owner: &Owner, resumed_from: Option<OperationId>, ) -> Result<OperationRow>
Journals operation op on run as queued and started at once by owner (the command
line, an embedder with no service), recovering resumed_from when it found that one
unfinished.
§Errors
The store can’t be written.
Sourcepub fn steps(&self, id: OperationId) -> Result<Vec<(String, StepState)>>
pub fn steps(&self, id: OperationId) -> Result<Vec<(String, StepState)>>
Operation id’s journaled steps, in order: each step and where it reached.
§Errors
The store can’t be read.
Sourcepub fn end_operation(
&mut self,
id: OperationId,
outcome: Outcome,
code: Option<ErrorCode>,
) -> Result<()>
pub fn end_operation( &mut self, id: OperationId, outcome: Outcome, code: Option<ErrorCode>, ) -> Result<()>
Journals how operation id ended. An operation already ended keeps its first end. A
queued one that never started can only be cancelled: it never ran.
§Errors
illegal_transition when a queued operation is ended otherwise than cancelled; the
store’s.
Sourcepub fn request_cancel(&mut self, id: OperationId) -> Result<bool>
pub fn request_cancel(&mut self, id: OperationId) -> Result<bool>
Sourcepub fn operation(&self, id: OperationId) -> Result<Option<OperationRow>>
pub fn operation(&self, id: OperationId) -> Result<Option<OperationRow>>
Sourcepub fn operations(
&self,
run: &RunName,
limit: usize,
) -> Result<Vec<OperationRow>>
pub fn operations( &self, run: &RunName, limit: usize, ) -> Result<Vec<OperationRow>>
Sourcepub fn in_flight(&self) -> Result<Vec<OperationRow>>
pub fn in_flight(&self) -> Result<Vec<OperationRow>>
The home’s operations that never ended, every run’s, queued or started, oldest first: those still in their owner’s queue or running while it lives, else left by a process that died.
§Errors
As Tx::operation.
Sourcepub fn unfinished(&self, run: &RunName) -> Result<Vec<OperationRow>>
pub fn unfinished(&self, run: &RunName) -> Result<Vec<OperationRow>>
Run run’s operations that never ended, queued or started, oldest first. Called with the
run held (its lock, or its lease), so none of the started ones runs: each is one whose
process died, or whose future was dropped before it could say how it ended. A queued one
still waits in its owner’s queue while that owner lives.
§Errors
As Tx::operation.
Sourcepub fn cancel_orphaned_queued(&mut self) -> Result<Vec<OperationId>>
pub fn cancel_orphaned_queued(&mut self) -> Result<Vec<OperationId>>
Ends cancelled every queued operation of the home (any run) that never started and whose
owner is gone (another boot, a dead process): a service that died with operations in its
queue. Returns their ids. A live owner’s queued rows stay: they wait in its queue.
§Errors
The store can’t be read or written.
Sourcepub fn append_event(
&mut self,
operation: Option<OperationId>,
event: &Event,
) -> Result<EventCursor>
pub fn append_event( &mut self, operation: Option<OperationId>, event: &Event, ) -> Result<EventCursor>
Appends event (of operation operation, if any) to the event table: its cursor.
§Errors
The store can’t be written.
Sourcepub fn append_raw_event(
&mut self,
run: Option<&str>,
operation: Option<OperationId>,
body: &str,
) -> Result<EventCursor>
pub fn append_raw_event( &mut self, run: Option<&str>, operation: Option<OperationId>, body: &str, ) -> Result<EventCursor>
Appends an event already written as JSON, as written (another version’s kind): it is read back as an event when this runner reads it, else counted unreadable.
§Errors
The store can’t be written.
Sourcepub fn events_after(
&self,
after: EventCursor,
run: Option<&RunName>,
limit: usize,
) -> Result<(Vec<(EventCursor, Event)>, usize)>
pub fn events_after( &self, after: EventCursor, run: Option<&RunName>, limit: usize, ) -> Result<(Vec<(EventCursor, Event)>, usize)>
Up to limit events after cursor after, of run run or of every run, oldest first,
with how many rows it couldn’t read as an event (another version’s kind).
§Errors
The store can’t be read.
Sourcepub fn events_page(
&self,
after: EventCursor,
run: Option<&RunName>,
limit: usize,
) -> Result<EventPage>
pub fn events_page( &self, after: EventCursor, run: Option<&RunName>, limit: usize, ) -> Result<EventPage>
Up to limit event rows after cursor after, of run run or of every run, oldest first:
the events it reads, how many rows it couldn’t read as one, and the cursor of the last row
it scanned, read or not (after when there was none). A reader resumes from last: a
page of rows another version wrote, none of them readable, still moves it on.
§Errors
The store can’t be read.
Sourcepub fn last_cursor(&self) -> Result<EventCursor>
pub fn last_cursor(&self) -> Result<EventCursor>
Source§impl Tx<'_>
impl Tx<'_>
Sourcepub fn acquire_lease(
&mut self,
scope: &str,
owner: &Owner,
ttl: Duration,
) -> Result<LeaseOutcome>
pub fn acquire_lease( &mut self, scope: &str, owner: &Owner, ttl: Duration, ) -> Result<LeaseOutcome>
Takes lease scope for owner for ttl: when nobody holds it, when its holder’s lease
expired or its process is gone (taken over: the lease it left is returned), or when
owner holds it already (renewed). A live holder keeps it.
§Errors
The store can’t be written.
Sourcepub fn renew_lease(
&mut self,
scope: &str,
owner: &Owner,
ttl: Duration,
) -> Result<bool>
pub fn renew_lease( &mut self, scope: &str, owner: &Owner, ttl: Duration, ) -> Result<bool>
Extends owner’s lease scope by ttl from now: false when owner doesn’t hold it
(another took it over).
§Errors
The store can’t be written.
Sourcepub fn release_lease(&mut self, scope: &str, owner: &Owner) -> Result<()>
pub fn release_lease(&mut self, scope: &str, owner: &Owner) -> Result<()>
Lets go of owner’s lease scope (nothing when another holds it), and of the ports
reserved under it.
§Errors
The store can’t be written.
Sourcepub fn reserve_port(
&mut self,
reserver: &Reserver<'_>,
port: HostPort,
protocol: Protocol,
) -> Result<bool>
pub fn reserve_port( &mut self, reserver: &Reserver<'_>, port: HostPort, protocol: Protocol, ) -> Result<bool>
Reserves host port over protocol for reserver: false when another run’s live
reservation holds it. A reservation whose lease is gone, expired or another’s now (its
process died) is taken over.
§Errors
The store can’t be written.
Sourcepub fn port_holder(
&self,
port: HostPort,
protocol: Protocol,
) -> Result<Option<PortReservation>>
pub fn port_holder( &self, port: HostPort, protocol: Protocol, ) -> Result<Option<PortReservation>>
The live reservation of port over protocol, if one holds it: one whose lease its
reserver still holds, live.
§Errors
The store can’t be read.
Sourcepub fn release_ports(&mut self, by: OperationId) -> Result<()>
pub fn release_ports(&mut self, by: OperationId) -> Result<()>
Sourcepub fn port_reservations(&self) -> Result<Vec<PortReservation>>
pub fn port_reservations(&self) -> Result<Vec<PortReservation>>
Source§impl Tx<'_>
impl Tx<'_>
Sourcepub fn creating(&mut self, new: &NewResource<'_>) -> Result<ResourceId>
pub fn creating(&mut self, new: &NewResource<'_>) -> Result<ResourceId>
Writes new as creating, before the call that makes it: commit it before the call.
§Errors
illegal_transition when new gives a local kind a lifetime other than its own, or a
provider kind none; the store’s.
Sourcepub fn created(&mut self, id: ResourceId, native_id: &str) -> Result<()>
pub fn created(&mut self, id: ResourceId, native_id: &str) -> Result<()>
Records that resource id was made, as native_id.
§Errors
illegal_transition when the row isn’t creating or created (a made resource made
again keeps its row: an idempotent retry); the store’s.
Sourcepub fn destroying(&mut self, id: ResourceId, by: OperationId) -> Result<()>
pub fn destroying(&mut self, id: ResourceId, by: OperationId) -> Result<()>
Records that operation by is removing resource id: before the call that removes it.
§Errors
illegal_transition when the row is gone already; the store’s.
Sourcepub fn gone(&mut self, id: ResourceId) -> Result<()>
pub fn gone(&mut self, id: ResourceId) -> Result<()>
Records that resource id is gone: removed, or found missing. Gone twice is fine.
§Errors
The store’s.
Sourcepub fn resource(&self, id: ResourceId) -> Result<Option<ResourceRow>>
pub fn resource(&self, id: ResourceId) -> Result<Option<ResourceRow>>
Sourcepub fn left_by_dead_operations(
&self,
run: &RunName,
current: OperationId,
) -> Result<Vec<ResourceRow>>
pub fn left_by_dead_operations( &self, run: &RunName, current: OperationId, ) -> Result<Vec<ResourceRow>>
The live provider rows of run that operations whose process died made: each made by an
operation that ended abandoned, or never ended and isn’t current (called with the run
held, so none of those runs). What a recovery removes by recorded id, newest first. A row
still creating with no id is left out: nothing to remove by, and the next reading of what
the tool reports gives it its id or lets it go.
§Errors
The store can’t be read.
Sourcepub fn live_resources(&self, run: &RunName) -> Result<Vec<ResourceRow>>
pub fn live_resources(&self, run: &RunName) -> Result<Vec<ResourceRow>>
Run run’s resources not gone, oldest first (a down walks them newest first).
§Errors
The store can’t be read.
Sourcepub fn resources_of(&self, by: OperationId) -> Result<Vec<ResourceRow>>
pub fn resources_of(&self, by: OperationId) -> Result<Vec<ResourceRow>>
The resources operation by made that aren’t gone: what a recovery of it removes.
§Errors
The store can’t be read.
Sourcepub fn resource_named(
&self,
run: &RunName,
key: &str,
name: &CopyName,
) -> Result<Option<ResourceRow>>
pub fn resource_named( &self, run: &RunName, key: &str, name: &CopyName, ) -> Result<Option<ResourceRow>>
Source§impl Tx<'_>
impl Tx<'_>
Sourcepub fn run(&self, name: &RunName) -> Result<Option<RunRow>>
pub fn run(&self, name: &RunName) -> Result<Option<RunRow>>
Run name’s row, when it has one.
§Errors
The store can’t be read, or the row holds what this runner doesn’t write.
Sourcepub fn set_source_digest(&mut self, name: &RunName, digest: &str) -> Result<()>
pub fn set_source_digest(&mut self, name: &RunName, digest: &str) -> Result<()>
Records the digest of the project files run name now runs from
(crate::Project::digest).
§Errors
The store can’t be written.
Sourcepub fn apply(&mut self, name: &RunName, transition: Transition) -> Result<()>
pub fn apply(&mut self, name: &RunName, transition: Transition) -> Result<()>
Moves run name by transition, and keeps the move with what made it. A compare-and-set:
refused (state_conflict) when the run no longer stands where the transition starts.
§Errors
state_conflict when the run moved meanwhile or has no row; the store’s.
Sourcepub fn transitions(
&self,
name: &RunName,
) -> Result<Vec<(RunState, RunState, Option<OperationId>)>>
pub fn transitions( &self, name: &RunName, ) -> Result<Vec<(RunState, RunState, Option<OperationId>)>>
Run name’s moves, oldest first: from, to, the operation that made each (none for an
observation).
§Errors
The store can’t be read.
Sourcepub fn keep_observed(
&mut self,
name: &RunName,
observed: &LastObserved,
) -> Result<bool>
pub fn keep_observed( &mut self, name: &RunName, observed: &LastObserved, ) -> Result<bool>
Keeps observed as what the runner last saw of run name (no row: nothing kept), its
state left as it is: an operation’s own reads.
§Errors
The store can’t be written.
Sourcepub fn observe(
&mut self,
name: &RunName,
observed: &LastObserved,
to: RunState,
) -> Result<Option<Transition>>
pub fn observe( &mut self, name: &RunName, observed: &LastObserved, to: RunState, ) -> Result<Option<Transition>>
Status = reconcile(desired, observed): keeps observed, and when a settled run shows as
to (what its machines say), moves it there by an observation. A moving run (an
operation owns it) or a move the table doesn’t allow keeps its state. The move made, if
one was.
§Errors
The store can’t be written.