Skip to main content

rio_rs/object_placement/
mod.rs

1//! Maps object's location in the cluster
2
3use std::fmt::Debug;
4
5use async_trait::async_trait;
6
7use crate::ObjectId;
8
9#[cfg(feature = "local")]
10pub mod local;
11#[cfg(feature = "postgres")]
12pub mod postgres;
13#[cfg(feature = "redis")]
14pub mod redis;
15#[cfg(feature = "sqlite")]
16pub mod sqlite;
17
18/// Struct providing placement information
19pub struct ObjectPlacementItem {
20    pub object_id: ObjectId,
21    pub server_address: Option<String>,
22    // TODO: ttl
23    // TODO: last_seen
24}
25
26impl ObjectPlacementItem {
27    pub fn new(object_id: ObjectId, server_address: Option<String>) -> ObjectPlacementItem {
28        ObjectPlacementItem {
29            object_id,
30            server_address,
31        }
32    }
33}
34
35/// This trait decribes how to manipulate objects' allocation
36/// This is pretty much a CRUD for the mapping
37#[async_trait]
38pub trait ObjectPlacement: Send + Sync + Clone + Debug {
39    /// Setup step, one can define it for their [ObjectPlacement] so it does some
40    /// prep work before the server is running
41    async fn prepare(&self) {}
42    /// Insert or update the object placement
43    async fn update(&self, object_placement: ObjectPlacementItem);
44    /// Find the server address for a given object
45    async fn lookup(&self, object_id: &ObjectId) -> Option<String>;
46    /// Unassign all objects for a given server
47    async fn clean_server(&self, address: String);
48    /// Unassign a single object by its ID
49    async fn remove(&self, object_id: &ObjectId);
50}