pub struct Store { /* private fields */ }Expand description
The owner-only store under the state root.
Implementations§
Source§impl Store
impl Store
Sourcepub fn checked(fingerprint: &str) -> Result<&str, AppError>
pub fn checked(fingerprint: &str) -> Result<&str, AppError>
Refuse an id that is not a fingerprint.
Every public entry takes the id as a string, and the strings reach
Path::join, which appends whatever it is given. An id carrying a
path component would name a directory outside the store, and a
terminal result removes the directory its plan names. So the shape
is checked once, at the boundary: exactly a lowercase hex sha256.
§Errors
AppError::Refused naming the id.
Sourcepub fn directory(&self, fingerprint: &str) -> PlanDirectory
pub fn directory(&self, fingerprint: &str) -> PlanDirectory
Where one fingerprint’s executable plan lives.
The caller has already run Store::checked on the id: every
public entry does, and this is reachable only through one of them.
Sourcepub fn results(&self, fingerprint: &str) -> Utf8PathBuf
pub fn results(&self, fingerprint: &str) -> Utf8PathBuf
Where one fingerprint’s terminal results live.
Sourcepub fn lock_path(&self) -> Utf8PathBuf
pub fn lock_path(&self) -> Utf8PathBuf
Where the store keeps the lock that orders a whole-store walk.
Only the prune takes it, and only for as long as the walk. A
per-plan write takes Store::plan_lock_path instead, because two
planners for different fingerprints touch nothing in common and
serializing them would make one landing wait on another’s target.
Sourcepub fn plan_lock_path(&self, fingerprint: &str) -> Result<Utf8PathBuf, AppError>
pub fn plan_lock_path(&self, fingerprint: &str) -> Result<Utf8PathBuf, AppError>
Where one fingerprint’s own lock lives.
Two planners that computed the same plan race to publish it, and this is what makes the second reuse the first rather than meet a half-written directory.
§Errors
AppError::Refused for an id that is not a fingerprint.
Sourcepub fn create(&self) -> Result<(), AppError>
pub fn create(&self) -> Result<(), AppError>
Create the store, owner-only.
A plan carries bytes out of a target, and some of those are not the world’s business. The directory mode says so on the filesystem rather than only in a document.
§Errors
Any I/O error creating the directories or setting their mode.
Sourcepub fn holds(&self, fingerprint: &str) -> bool
pub fn holds(&self, fingerprint: &str) -> bool
Whether an executable plan exists for this fingerprint.
Sourcepub fn put(
&self,
plan: &Plan,
blobs: &BTreeMap<Sha256, Vec<u8>>,
) -> Result<PlanDirectory, AppError>
pub fn put( &self, plan: &Plan, blobs: &BTreeMap<Sha256, Vec<u8>>, ) -> Result<PlanDirectory, AppError>
Write one plan and every byte it will land.
§Errors
Any I/O error creating the directory or writing the plan.
Sourcepub fn get(&self, fingerprint: &str) -> Result<Plan, AppError>
pub fn get(&self, fingerprint: &str) -> Result<Plan, AppError>
Read one stored plan.
§Errors
AppError::Refused when no executable plan carries that
fingerprint, and I/O errors when it cannot be read.
Sourcepub fn blob(
&self,
fingerprint: &str,
digest: &Sha256,
) -> Result<Vec<u8>, AppError>
pub fn blob( &self, fingerprint: &str, digest: &Sha256, ) -> Result<Vec<u8>, AppError>
One byte string the plan will write.
§Errors
AppError::Refused when the plan’s blob store does not carry it.
Sourcepub fn record(&self, plan: &Plan, result: &Result) -> Result<(), AppError>
pub fn record(&self, plan: &Plan, result: &Result) -> Result<(), AppError>
Record one attempt’s outcome.
A terminal disposition moves the redacted plan out with its result and frees the fingerprint. Anything else leaves the executable plan where it is, because the same plan can still be applied.
§Errors
Any I/O error writing the result or moving the plan.
Sourcepub fn latest_result(&self, fingerprint: &str) -> Option<Result>
pub fn latest_result(&self, fingerprint: &str) -> Option<Result>
The latest result for one fingerprint, where any exists.
Sourcepub fn prune(
&self,
now: Timestamp,
keep: Option<&str>,
) -> Result<Vec<Utf8PathBuf>, AppError>
pub fn prune( &self, now: Timestamp, keep: Option<&str>, ) -> Result<Vec<Utf8PathBuf>, AppError>
Remove what the lifecycle says is over.
Never removes the fingerprint the caller named, and never removes a directory that still holds a journal: a run that did not finish keeps everything recovery needs, whatever the calendar says.
§Errors
Any I/O error reading the store.