mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-25 21:46:50 +00:00
chore(rustfs): remove the orphan starshard bucket-cache backend (#6038)
This commit is contained in:
Generated
-1
@@ -9201,7 +9201,6 @@ dependencies = [
|
|||||||
"sha2 0.11.0",
|
"sha2 0.11.0",
|
||||||
"shadow-rs",
|
"shadow-rs",
|
||||||
"socket2",
|
"socket2",
|
||||||
"starshard",
|
|
||||||
"subtle",
|
"subtle",
|
||||||
"sysinfo",
|
"sysinfo",
|
||||||
"temp-env",
|
"temp-env",
|
||||||
|
|||||||
@@ -243,7 +243,6 @@ rustfs-object-data-cache = { workspace = true, features = ["cache"] }
|
|||||||
rustfs-concurrency = { workspace = true }
|
rustfs-concurrency = { workspace = true }
|
||||||
rustfs-scanner = { workspace = true }
|
rustfs-scanner = { workspace = true }
|
||||||
tempfile = { workspace = true }
|
tempfile = { workspace = true }
|
||||||
starshard = { workspace = true, features = ["rayon", "async", "serde"] }
|
|
||||||
|
|
||||||
# Async Runtime and Networking
|
# Async Runtime and Networking
|
||||||
async-trait = { workspace = true }
|
async-trait = { workspace = true }
|
||||||
|
|||||||
@@ -765,76 +765,44 @@ where
|
|||||||
|
|
||||||
/// Bucket validation cache to avoid repeated stat_volume() calls on every GET.
|
/// Bucket validation cache to avoid repeated stat_volume() calls on every GET.
|
||||||
///
|
///
|
||||||
/// **Adaptive strategy** (selected once at startup via env var):
|
/// Backend: `RwLock<HashMap>`. A parallel opt-in starshard backend
|
||||||
///
|
/// (`RUSTFS_BUCKET_CACHE_STARSHARD`) used to double-write every operation
|
||||||
/// | Backend | Env var | Best for |
|
/// here; no deployment ever set the variable and the branch was removed in
|
||||||
/// |---------|---------|----------|
|
/// backlog#1832.
|
||||||
/// | `RwLock<HashMap>` | default | < 100 buckets — lower per-op overhead |
|
|
||||||
/// | `starshard::ShardedHashMap` | `RUSTFS_BUCKET_CACHE_STARSHARD=1` | >= 100 buckets — sharded locks reduce contention |
|
|
||||||
///
|
///
|
||||||
/// Entries expire after `BUCKET_VALIDATION_TTL` (checked on read).
|
/// Entries expire after `BUCKET_VALIDATION_TTL` (checked on read).
|
||||||
/// Write operations (delete/make bucket) invalidate the cache explicitly.
|
/// Write operations (delete/make bucket) invalidate the cache explicitly.
|
||||||
const BUCKET_VALIDATION_TTL: Duration = Duration::from_secs(5);
|
const BUCKET_VALIDATION_TTL: Duration = Duration::from_secs(5);
|
||||||
|
|
||||||
/// Tracks which backend is active: `false` = HashMap, `true` = starshard.
|
|
||||||
static USE_STARSHARD_CACHE: OnceLock<bool> = OnceLock::new();
|
|
||||||
|
|
||||||
fn use_starshard() -> bool {
|
|
||||||
*USE_STARSHARD_CACHE.get_or_init(|| {
|
|
||||||
std::env::var("RUSTFS_BUCKET_CACHE_STARSHARD")
|
|
||||||
.ok()
|
|
||||||
.and_then(|v| v.parse::<bool>().ok())
|
|
||||||
.unwrap_or(false)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
/// --- HashMap backend (default) ---
|
|
||||||
static BUCKET_CACHE_SMALL: OnceLock<RwLock<HashMap<String, Instant>>> = OnceLock::new();
|
static BUCKET_CACHE_SMALL: OnceLock<RwLock<HashMap<String, Instant>>> = OnceLock::new();
|
||||||
|
|
||||||
fn small_cache() -> &'static RwLock<HashMap<String, Instant>> {
|
fn small_cache() -> &'static RwLock<HashMap<String, Instant>> {
|
||||||
BUCKET_CACHE_SMALL.get_or_init(|| RwLock::new(HashMap::new()))
|
BUCKET_CACHE_SMALL.get_or_init(|| RwLock::new(HashMap::new()))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// --- starshard backend (opt-in) ---
|
/// Get a value from the cache.
|
||||||
static BUCKET_CACHE_LARGE: OnceLock<starshard::ShardedHashMap<String, Instant>> = OnceLock::new();
|
|
||||||
|
|
||||||
fn large_cache() -> &'static starshard::ShardedHashMap<String, Instant> {
|
|
||||||
BUCKET_CACHE_LARGE.get_or_init(|| starshard::ShardedHashMap::new(128))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get a value from the active cache backend.
|
|
||||||
fn cache_get(bucket: &str) -> Option<Instant> {
|
fn cache_get(bucket: &str) -> Option<Instant> {
|
||||||
if use_starshard() {
|
small_cache().read().ok()?.get(bucket).copied()
|
||||||
large_cache().get(&bucket.to_string())
|
|
||||||
} else {
|
|
||||||
small_cache().read().ok()?.get(bucket).copied()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Insert a value into the active cache backend.
|
/// Insert a value into the cache.
|
||||||
fn cache_insert(bucket: String, ts: Instant) {
|
fn cache_insert(bucket: String, ts: Instant) {
|
||||||
if use_starshard() {
|
if let Ok(mut map) = small_cache().write() {
|
||||||
large_cache().insert(bucket, ts);
|
|
||||||
} else if let Ok(mut map) = small_cache().write() {
|
|
||||||
map.insert(bucket, ts);
|
map.insert(bucket, ts);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Remove a value from the active cache backend.
|
/// Remove a value from the cache.
|
||||||
fn cache_remove(bucket: &str) {
|
fn cache_remove(bucket: &str) {
|
||||||
if use_starshard() {
|
if let Ok(mut map) = small_cache().write() {
|
||||||
large_cache().remove(&bucket.to_string());
|
|
||||||
} else if let Ok(mut map) = small_cache().write() {
|
|
||||||
map.remove(bucket);
|
map.remove(bucket);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Clear all entries in the active cache backend.
|
/// Clear all entries in the cache.
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
fn cache_clear() {
|
fn cache_clear() {
|
||||||
if use_starshard() {
|
if let Ok(mut map) = small_cache().write() {
|
||||||
large_cache().clear();
|
|
||||||
} else if let Ok(mut map) = small_cache().write() {
|
|
||||||
map.clear();
|
map.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user