use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "lowercase")]
pub enum BucketQosProfile {
Standard,
Ingest,
}
impl BucketQosProfile {
pub fn from_str(value: &str) -> Option<Self> {
match value {
"standard" => Some(Self::Standard),
"ingest" => Some(Self::Ingest),
_ => None,
}
}
}
pub fn compute_chunk_bytes(base_chunk_bytes: usize, profile: BucketQosProfile, active_mpu: usize) -> usize {
if profile == BucketQosProfile::Standard {
return base_chunk_bytes;
}
let mut scaled = base_chunk_bytes.max(8 * 1024 * 1024);
if active_mpu >= 16 {
scaled = 32 * 1024 * 1024;
}
if active_mpu >= 64 {
scaled = 64 * 1024 * 1024;
}
if active_mpu >= 128 {
scaled = 128 * 1024 * 1024;
}
scaled
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn standard_keeps_base_chunk() {
assert_eq!(compute_chunk_bytes(8 * 1024 * 1024, BucketQosProfile::Standard, 200), 8 * 1024 * 1024);
}
#[test]
fn ingest_scales_with_load() {
assert_eq!(compute_chunk_bytes(8 * 1024 * 1024, BucketQosProfile::Ingest, 1), 8 * 1024 * 1024);
assert_eq!(compute_chunk_bytes(8 * 1024 * 1024, BucketQosProfile::Ingest, 16), 32 * 1024 * 1024);
assert_eq!(compute_chunk_bytes(8 * 1024 * 1024, BucketQosProfile::Ingest, 200), 128 * 1024 * 1024);
}
}