Skip to main content

spawn_db/store/pinner/
latest.rs

1use super::Pinner;
2use anyhow::Result;
3use async_trait::async_trait;
4use opendal::Operator;
5
6/// Uses the latest versions of files, rather than any pinned version.
7#[derive(Debug)]
8pub struct Latest {
9    store_path: String,
10}
11
12/// Represents a snapshot of files and folders at a particular point in time.
13/// Used to retrieve files as they were at that moment.
14impl Latest {
15    /// Folder represents the path to our history storage and latest files.
16    /// If root is provided then store will use the files from archive rather
17    /// than the latest live files.
18    pub fn new(store_path: &str) -> Result<Self> {
19        Ok(Self {
20            store_path: store_path.to_string(),
21        })
22    }
23}
24
25#[async_trait]
26impl Pinner for Latest {
27    /// Returns the file from the live file system if it exists.
28    async fn load_bytes(&self, name: &str, object_store: &Operator) -> Result<Option<Vec<u8>>> {
29        let path_str = format!("{}/components/{}", self.store_path, name);
30
31        let get_result = object_store.read(&path_str).await?;
32        let bytes = get_result.to_bytes();
33
34        Ok(Some(bytes.to_vec()))
35    }
36
37    async fn snapshot(&mut self, _object_store: &Operator) -> Result<String> {
38        Err(anyhow::anyhow!("Latest pinner does not support pinning"))
39    }
40}