2021-03-23 11:00:50 +01:00
|
|
|
mod actor;
|
|
|
|
mod handle_impl;
|
|
|
|
mod message;
|
|
|
|
mod store;
|
|
|
|
|
2021-04-22 10:14:29 +02:00
|
|
|
use std::collections::HashSet;
|
2021-03-23 11:00:50 +01:00
|
|
|
use std::path::PathBuf;
|
|
|
|
|
|
|
|
use thiserror::Error;
|
|
|
|
use uuid::Uuid;
|
|
|
|
|
|
|
|
use actor::UuidResolverActor;
|
|
|
|
use message::UuidResolveMsg;
|
2021-05-10 20:23:12 +02:00
|
|
|
use store::UuidStore;
|
2021-03-23 11:00:50 +01:00
|
|
|
|
2021-03-23 16:19:01 +01:00
|
|
|
#[cfg(test)]
|
|
|
|
use mockall::automock;
|
|
|
|
|
2021-03-23 11:00:50 +01:00
|
|
|
pub use handle_impl::UuidResolverHandleImpl;
|
2021-05-24 16:05:43 +02:00
|
|
|
pub use store::HeedUuidStore;
|
2021-03-23 11:00:50 +01:00
|
|
|
|
|
|
|
const UUID_STORE_SIZE: usize = 1_073_741_824; //1GiB
|
|
|
|
|
2021-05-24 16:05:43 +02:00
|
|
|
pub type Result<T> = std::result::Result<T, UuidResolverError>;
|
2021-03-23 11:00:50 +01:00
|
|
|
|
|
|
|
#[async_trait::async_trait]
|
2021-03-23 16:19:01 +01:00
|
|
|
#[cfg_attr(test, automock)]
|
2021-03-23 11:00:50 +01:00
|
|
|
pub trait UuidResolverHandle {
|
2021-03-25 14:21:05 +01:00
|
|
|
async fn get(&self, name: String) -> Result<Uuid>;
|
|
|
|
async fn insert(&self, name: String, uuid: Uuid) -> anyhow::Result<()>;
|
2021-03-23 11:00:50 +01:00
|
|
|
async fn create(&self, name: String) -> anyhow::Result<Uuid>;
|
|
|
|
async fn delete(&self, name: String) -> anyhow::Result<Uuid>;
|
|
|
|
async fn list(&self) -> anyhow::Result<Vec<(String, Uuid)>>;
|
2021-04-22 10:14:29 +02:00
|
|
|
async fn snapshot(&self, path: PathBuf) -> Result<HashSet<Uuid>>;
|
2021-04-09 14:41:24 +02:00
|
|
|
async fn get_size(&self) -> Result<u64>;
|
2021-05-24 16:05:43 +02:00
|
|
|
async fn dump(&self, path: PathBuf) -> Result<HashSet<Uuid>>;
|
2021-03-23 11:00:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Error)]
|
2021-05-24 16:05:43 +02:00
|
|
|
pub enum UuidResolverError {
|
2021-03-23 11:00:50 +01:00
|
|
|
#[error("Name already exist.")]
|
|
|
|
NameAlreadyExist,
|
|
|
|
#[error("Index \"{0}\" doesn't exist.")]
|
|
|
|
UnexistingIndex(String),
|
|
|
|
#[error("Badly formatted index uid: {0}")]
|
|
|
|
BadlyFormatted(String),
|
2021-05-24 16:05:43 +02:00
|
|
|
#[error("Internal error resolving index uid: {0}")]
|
|
|
|
Internal(String),
|
2021-03-23 11:00:50 +01:00
|
|
|
}
|
2021-05-24 16:05:43 +02:00
|
|
|
|
|
|
|
macro_rules! internal_error {
|
|
|
|
($($other:path), *) => {
|
|
|
|
$(
|
|
|
|
impl From<$other> for UuidResolverError {
|
|
|
|
fn from(other: $other) -> Self {
|
|
|
|
Self::Internal(other.to_string())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)*
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
internal_error!(
|
|
|
|
heed::Error,
|
|
|
|
uuid::Error,
|
|
|
|
std::io::Error,
|
|
|
|
tokio::task::JoinError,
|
|
|
|
serde_json::Error
|
|
|
|
);
|