Skip to main content

microvms_app/
run_store.rs

1// SPDX-License-Identifier: Apache-2.0
2//! Storage for outstanding runs and append-only VM history.
3//!
4//! The namespaces stay separate: clearing a resolved run must not erase its history.
5
6use std::fmt::Debug;
7use std::io;
8
9/// One stored ledger document, including unreadable records that must stay visible.
10#[derive(Clone, Debug)]
11pub struct StoredLedger {
12    pub key: String,
13    pub location: String,
14    pub text: Option<String>,
15}
16
17/// Durable storage used by the run ledger and history policies.
18///
19/// Writes report errors here; the policies deliberately swallow them on teardown so
20/// housekeeping never replaces a command's real outcome. Keys are opaque store identifiers.
21pub trait RunStore: Debug + Send + Sync {
22    /// Lists every ledger, including an unreadable document as `text: None`.
23    fn ledgers(&self) -> Vec<StoredLedger>;
24    /// Replaces a ledger while keeping history separate.
25    fn write_ledger(&self, key: &str, text: &str) -> io::Result<()>;
26    /// Removes a ledger. The caller has decided whether its resources are resolved.
27    fn remove_ledger(&self, key: &str) -> io::Result<()>;
28    /// Reads the complete history text, preserving line order and malformed lines.
29    fn read_history(&self, vm_id: &str) -> io::Result<String>;
30    /// Appends one serialized record and a newline, without replacing earlier bytes.
31    fn append_history(&self, vm_id: &str, line: &str) -> io::Result<()>;
32}