fix(storage): address pending metadata and health gaps (#4380)

This commit is contained in:
Zhengchao An
2026-07-08 00:15:07 +08:00
committed by GitHub
parent d3660f9ded
commit 62a31e4ec4
8 changed files with 841 additions and 79 deletions
@@ -21,7 +21,7 @@ use crate::data_usage::load_data_usage_cache;
use crate::storage_api_contracts::admin::StorageAdminApi;
use rustfs_common::heal_channel::DriveState;
use rustfs_madmin::{
BackendDisks, Disk, ErasureSetInfo, ITEM_INITIALIZING, ITEM_OFFLINE, ITEM_ONLINE, InfoMessage, ServerProperties,
BackendDisks, Disk, ErasureSetInfo, ITEM_INITIALIZING, ITEM_OFFLINE, ITEM_ONLINE, InfoMessage, MemStats, ServerProperties,
};
use rustfs_protos::{
models::{PingBody, PingBodyBuilder},
@@ -128,10 +128,22 @@ pub async fn get_local_server_property() -> ServerProperties {
let addr = runtime_sources::local_node_name().await;
let mut pool_numbers = HashSet::new();
let mut network = HashMap::new();
let (mem_stats, max_procs, num_cpu) = collect_runtime_server_stats();
let endpoints = match runtime_sources::endpoint_pools() {
Some(eps) => eps,
None => return ServerProperties::default(),
None => {
return ServerProperties {
state: ITEM_INITIALIZING.to_string(),
endpoint: addr,
uptime: runtime_sources::boot_uptime_secs(),
version: get_commit_id(),
mem_stats,
max_procs,
num_cpu,
..Default::default()
};
}
};
for ep in endpoints.as_ref().iter() {
for endpoint in ep.endpoints.as_ref().iter() {
@@ -154,14 +166,14 @@ pub async fn get_local_server_property() -> ServerProperties {
}
}
// todo: mem collect
// let mem_stats =
let mut props = ServerProperties {
endpoint: addr,
uptime: runtime_sources::boot_uptime_secs(),
network,
version: get_commit_id(),
mem_stats,
max_procs,
num_cpu,
..Default::default()
};
@@ -189,6 +201,15 @@ pub async fn get_local_server_property() -> ServerProperties {
props
}
fn collect_runtime_server_stats() -> (MemStats, u64, u64) {
let num_cpu = u64::try_from(num_cpus::get()).unwrap_or(u64::MAX);
let max_procs = std::thread::available_parallelism()
.map(|parallelism| u64::try_from(parallelism.get()).unwrap_or(u64::MAX))
.unwrap_or(num_cpu.max(1));
(rustfs_madmin::health::collect_mem_stats(), max_procs, num_cpu)
}
pub async fn get_server_info(get_pools: bool) -> InfoMessage {
let nowt: OffsetDateTime = OffsetDateTime::now_utc();
@@ -393,7 +414,7 @@ mod tests {
use crate::runtime::sources as runtime_sources;
use super::get_server_info;
use super::{get_local_server_property, get_server_info};
#[serial]
#[tokio::test]
@@ -403,4 +424,17 @@ mod tests {
assert_eq!(info.deployment_id, expected_deployment_id);
}
#[serial]
#[tokio::test]
async fn local_server_property_includes_runtime_stats_without_endpoint_pools() {
let props = get_local_server_property().await;
assert!(props.num_cpu > 0);
assert!(props.max_procs > 0);
assert!(
props.mem_stats.alloc > 0 || props.mem_stats.total_alloc > 0 || props.mem_stats.heap_alloc > 0,
"memory stats should not remain fixed placeholders"
);
}
}