Clean up comments

This commit is contained in:
Silas Brack 2026-03-08 13:31:44 +01:00
parent 5cdaeddc0e
commit 5daa983034
3 changed files with 5 additions and 31 deletions

View file

@ -15,17 +15,12 @@ pub struct AppState {
pub http: reqwest::Client,
}
/// Result of probing volumes for a key.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ProbeResult {
/// Found a healthy volume at this URL
Found(String),
/// All volumes were probed, none healthy
AllFailed,
}
/// Pure function: given volumes and their probe results (true = healthy),
/// returns the first healthy volume URL for the key, or None.
pub fn first_healthy_volume(key: &str, volumes: &[String], results: &[bool]) -> ProbeResult {
for (vol, &healthy) in volumes.iter().zip(results) {
if healthy {
@ -35,8 +30,6 @@ pub fn first_healthy_volume(key: &str, volumes: &[String], results: &[bool]) ->
ProbeResult::AllFailed
}
/// Pure function: shuffle volumes for load balancing.
/// Takes a seed for deterministic testing.
pub fn shuffle_volumes(volumes: Vec<String>, seed: u64) -> Vec<String> {
use rand::seq::SliceRandom;
use rand::SeedableRng;
@ -55,14 +48,12 @@ pub async fn get_key(
return Err(AppError::CorruptRecord { key });
}
// Shuffle for load balancing (random seed in production)
let seed = std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.map(|d| d.as_nanos() as u64)
.unwrap_or(0);
let volumes = shuffle_volumes(record.volumes, seed);
// Probe volumes and collect results
let mut results = Vec::with_capacity(volumes.len());
for vol in &volumes {
let url = format!("{vol}/{key}");
@ -78,7 +69,6 @@ pub async fn get_key(
}
};
results.push(healthy);
// Early exit on first healthy volume
if healthy {
break;
}
@ -107,7 +97,6 @@ pub async fn put_key(
});
}
// Fan out PUTs to all target volumes concurrently
let mut handles = Vec::with_capacity(target_volumes.len());
for vol in &target_volumes {
let url = format!("{vol}/{key}");
@ -243,7 +232,3 @@ pub async fn list_keys(
Ok((StatusCode::OK, keys.join("\n")).into_response())
}
// Note: first_healthy_volume and shuffle_volumes are trivial functions
// (essentially .find() and .shuffle()). Testing them would just test
// that standard library functions work. The real test is integration:
// does failover work with actual down volumes?