fix: resolve test conflicts and improve data scanner functionality

- Fix multi-threaded test conflicts in AHM heal integration tests
- Remove global environment sharing to prevent test state pollution
- Fix test_all_disk_method by clearing global disk map before test
- Improve data scanner and cache value implementations
- Update dependencies and resolve clippy warnings

Signed-off-by: junxiang Mu <1948535941@qq.com>
This commit is contained in:
junxiang Mu
2025-07-16 16:32:33 +08:00
parent 8e766b90cd
commit c49414f6ac
8 changed files with 36 additions and 68 deletions
+5 -7
View File
@@ -103,7 +103,7 @@ impl HealChannelProcessor {
let response = HealChannelResponse {
request_id: request.id,
success: true,
data: Some(format!("Task ID: {}", task_id).into_bytes()),
data: Some(format!("Task ID: {task_id}").into_bytes()),
error: None,
};
@@ -140,7 +140,7 @@ impl HealChannelProcessor {
let response = HealChannelResponse {
request_id: client_token,
success: true,
data: Some(format!("Query result for path: {}", heal_path).into_bytes()),
data: Some(format!("Query result for path: {heal_path}").into_bytes()),
error: None,
};
@@ -160,7 +160,7 @@ impl HealChannelProcessor {
let response = HealChannelResponse {
request_id: heal_path.clone(),
success: true,
data: Some(format!("Cancel request for path: {}", heal_path).into_bytes()),
data: Some(format!("Cancel request for path: {heal_path}").into_bytes()),
error: None,
};
@@ -196,9 +196,7 @@ impl HealChannelProcessor {
Some(rustfs_common::heal_channel::HealChannelScanMode::Normal) => {
rustfs_ecstore::heal::heal_commands::HEAL_NORMAL_SCAN
}
Some(rustfs_common::heal_channel::HealChannelScanMode::Deep) => {
rustfs_ecstore::heal::heal_commands::HEAL_DEEP_SCAN
}
Some(rustfs_common::heal_channel::HealChannelScanMode::Deep) => rustfs_ecstore::heal::heal_commands::HEAL_DEEP_SCAN,
None => rustfs_ecstore::heal::heal_commands::HEAL_NORMAL_SCAN,
};
@@ -210,7 +208,7 @@ impl HealChannelProcessor {
update_parity: request.update_parity.unwrap_or(true),
recursive: request.recursive.unwrap_or(false),
dry_run: request.dry_run.unwrap_or(false),
timeout: request.timeout_seconds.map(|secs| std::time::Duration::from_secs(secs)),
timeout: request.timeout_seconds.map(std::time::Duration::from_secs),
pool_index: request.pool_index,
set_index: request.set_index,
};
-2
View File
@@ -278,7 +278,6 @@ impl HealManager {
_ = interval.tick() => {
// Build list of endpoints that need healing
let mut endpoints = Vec::new();
println!("GLOBAL_LOCAL_DISK_MAP length: {:?}", GLOBAL_LOCAL_DISK_MAP.read().await.len());
for (_, disk_opt) in GLOBAL_LOCAL_DISK_MAP.read().await.iter() {
if let Some(disk) = disk_opt {
// detect unformatted disk via get_disk_id()
@@ -300,7 +299,6 @@ impl HealManager {
if endpoints.is_empty() {
continue;
}
println!("endpoints length: {:?}", endpoints.len());
for ep in endpoints {
// skip if already queued or healing
+12
View File
@@ -1159,8 +1159,17 @@ mod tests {
use serial_test::serial;
use std::fs;
use std::net::SocketAddr;
use std::sync::OnceLock;
// Global test environment cache to avoid repeated initialization
static GLOBAL_TEST_ENV: OnceLock<(Vec<std::path::PathBuf>, Arc<ECStore>)> = OnceLock::new();
async fn prepare_test_env(test_dir: Option<&str>, port: Option<u16>) -> (Vec<std::path::PathBuf>, Arc<ECStore>) {
// Check if global environment is already initialized
if let Some((disk_paths, ecstore)) = GLOBAL_TEST_ENV.get() {
return (disk_paths.clone(), ecstore.clone());
}
// create temp dir as 4 disks
let test_base_dir = test_dir.unwrap_or("/tmp/rustfs_ahm_test");
let temp_dir = std::path::PathBuf::from(test_base_dir);
@@ -1222,6 +1231,9 @@ mod tests {
let buckets = buckets_list.into_iter().map(|v| v.name).collect();
rustfs_ecstore::bucket::metadata_sys::init_bucket_metadata_sys(ecstore.clone(), buckets).await;
// Store in global cache
let _ = GLOBAL_TEST_ENV.set((disk_paths.clone(), ecstore.clone()));
(disk_paths, ecstore)
}