use super::history_cache::{RegistryHistoryCache, RegistryHistoryCacheDisposition};
use super::key_family::RegistryKeyFamilyCheckpoint;
use std::path::PathBuf;
use std::{collections::BTreeMap, sync::Mutex};
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct SubnetCatalogProgress {
pub endpoint: String,
pub query_call_count: u64,
pub phase: SubnetCatalogProgressPhase,
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum SubnetCatalogProgressPhase {
EndpointStarted,
Pinned {
registry_version: u64,
},
History {
registry_version: u64,
through_version: u64,
reused: bool,
},
HistoryCache {
path: PathBuf,
disposition: RegistryHistoryCacheDisposition,
through_version: u64,
reason: Option<String>,
},
Record {
registry_version: u64,
key: String,
completed: bool,
},
Retry {
method: &'static str,
next_attempt: u8,
delay_millis: u64,
},
}
#[derive(Default)]
pub struct RegistryAcquisition {
pub(super) history: Mutex<BTreeMap<(String, String), RegistryKeyFamilyCheckpoint>>,
pub(crate) progress: Option<std::sync::Arc<dyn Fn(SubnetCatalogProgress) + Send + Sync>>,
pub(super) history_cache: Option<RegistryHistoryCache>,
}
impl RegistryAcquisition {
pub(crate) fn history_cache_paths(&self) -> Option<(&std::path::Path, &std::path::Path)> {
self.history_cache.as_ref().map(RegistryHistoryCache::paths)
}
pub(crate) fn with_history_cache(
root: PathBuf,
progress: Option<std::sync::Arc<dyn Fn(SubnetCatalogProgress) + Send + Sync>>,
) -> Self {
Self {
progress,
history_cache: Some(RegistryHistoryCache::new(root)),
..Self::default()
}
}
}