mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-11 23:56:53 +00:00
fix(runtime): remove startup panic fallbacks (#3754)
* fix(runtime): remove startup panic fallbacks * test(runtime): cover buffer profile fallback safety * test(runtime): reduce panic-style assertions * fix(runtime): expose fallible env config setup * test(runtime): simplify permit acquisition assertion * test(runtime): tighten operation helper assertions * fix(filemeta): stop panicking on invalid free version ids * fix(init): satisfy buffer profile clippy lints * fix(lock): harden fast lock config construction * chore(checks): refresh layer dependency baseline --------- Signed-off-by: houseme <housemecn@gmail.com>
This commit is contained in:
@@ -15,7 +15,9 @@
|
||||
use std::sync::Arc;
|
||||
use tokio::sync::RwLock;
|
||||
use tokio::time::{Instant, interval};
|
||||
use tracing::warn;
|
||||
|
||||
use crate::LockError;
|
||||
use crate::fast_lock::{
|
||||
guard::FastLockGuard,
|
||||
manager_trait::LockManager,
|
||||
@@ -42,8 +44,37 @@ impl FastObjectLockManager {
|
||||
|
||||
/// Create new lock manager with custom config
|
||||
pub fn with_config(config: LockConfig) -> Self {
|
||||
if let Err(err) = Self::validate_config(&config) {
|
||||
warn!(
|
||||
error = %err,
|
||||
shard_count = config.shard_count,
|
||||
fallback_shard_count = crate::fast_lock::DEFAULT_SHARD_COUNT,
|
||||
"Invalid lock manager configuration, falling back to defaults"
|
||||
);
|
||||
return Self::build(LockConfig::default());
|
||||
}
|
||||
|
||||
Self::build(config)
|
||||
}
|
||||
|
||||
/// Create new lock manager with custom config, returning an explicit error for invalid input.
|
||||
pub fn try_with_config(config: LockConfig) -> crate::Result<Self> {
|
||||
Self::validate_config(&config)?;
|
||||
Ok(Self::build(config))
|
||||
}
|
||||
|
||||
fn validate_config(config: &LockConfig) -> crate::Result<()> {
|
||||
if config.shard_count == 0 || !config.shard_count.is_power_of_two() {
|
||||
return Err(LockError::configuration(format!(
|
||||
"shard count must be a non-zero power of 2, got {}",
|
||||
config.shard_count
|
||||
)));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn build(config: LockConfig) -> Self {
|
||||
let shard_count = config.shard_count;
|
||||
assert!(shard_count.is_power_of_two(), "Shard count must be power of 2");
|
||||
|
||||
let shards: Vec<Arc<LockShard>> = (0..shard_count).map(|i| Arc::new(LockShard::new(i))).collect();
|
||||
|
||||
|
||||
@@ -14,8 +14,9 @@
|
||||
|
||||
#[cfg(test)]
|
||||
mod fast_lock_tests {
|
||||
use crate::fast_lock::FastObjectLockManager;
|
||||
use crate::LockError;
|
||||
use crate::fast_lock::types::{LockConfig, LockMode, LockPriority, LockResult, ObjectKey, ObjectLockRequest};
|
||||
use crate::fast_lock::{DEFAULT_SHARD_COUNT, FastObjectLockManager};
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
use tokio::time::sleep;
|
||||
@@ -31,6 +32,32 @@ mod fast_lock_tests {
|
||||
FastObjectLockManager::with_config(config)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn try_with_config_returns_error_for_invalid_shard_count() {
|
||||
let config = LockConfig {
|
||||
shard_count: 3,
|
||||
..LockConfig::default()
|
||||
};
|
||||
|
||||
let err = FastObjectLockManager::try_with_config(config)
|
||||
.expect_err("non-power-of-two shard counts should return an explicit configuration error");
|
||||
|
||||
assert!(matches!(err, LockError::Configuration { .. }));
|
||||
assert!(err.to_string().contains("shard count must be a non-zero power of 2"));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn with_config_falls_back_to_default_for_invalid_shard_count() {
|
||||
let config = LockConfig {
|
||||
shard_count: 3,
|
||||
..LockConfig::default()
|
||||
};
|
||||
|
||||
let manager = FastObjectLockManager::with_config(config);
|
||||
|
||||
assert_eq!(manager.shards.len(), DEFAULT_SHARD_COUNT);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_basic_write_lock_acquire_release() {
|
||||
let manager = create_test_manager();
|
||||
|
||||
Reference in New Issue
Block a user