From de19342744d55ba7b2eb036ce5752ad72a7f6b60 Mon Sep 17 00:00:00 2001 From: Zhengchao An Date: Tue, 30 Jun 2026 05:50:58 +0800 Subject: [PATCH] refactor(runtime): finish legacy global naming (#4097) --- crates/ecstore/src/metadata/bucket_sys.rs | 10 +++---- .../ecstore/src/services/notification_sys.rs | 6 ++--- docs/architecture/global-state-inventory.md | 5 ++-- rustfs/src/storage/ecfs_test.rs | 6 ++--- rustfs/src/storage/storage_api.rs | 2 +- scripts/check_architecture_migration_rules.sh | 26 +++++++++++++++++++ 6 files changed, 41 insertions(+), 14 deletions(-) diff --git a/crates/ecstore/src/metadata/bucket_sys.rs b/crates/ecstore/src/metadata/bucket_sys.rs index 9fd0fdd81..4d89a5320 100644 --- a/crates/ecstore/src/metadata/bucket_sys.rs +++ b/crates/ecstore/src/metadata/bucket_sys.rs @@ -42,7 +42,7 @@ use tokio::time::sleep; use tracing::error; lazy_static! { - pub static ref GLOBAL_BucketMetadataSys: OnceLock>> = OnceLock::new(); + pub static ref GLOBAL_BUCKET_METADATA_SYS: OnceLock>> = OnceLock::new(); } pub async fn init_bucket_metadata_sys(api: Arc, buckets: Vec) { @@ -51,19 +51,19 @@ pub async fn init_bucket_metadata_sys(api: Arc, buckets: Vec) { let sys = Arc::new(RwLock::new(sys)); - GLOBAL_BucketMetadataSys.set(sys).unwrap(); + GLOBAL_BUCKET_METADATA_SYS.set(sys).unwrap(); } pub fn get_global_bucket_metadata_sys() -> Option>> { - GLOBAL_BucketMetadataSys.get().cloned() + GLOBAL_BUCKET_METADATA_SYS.get().cloned() } // panic if not init pub(super) fn get_bucket_metadata_sys() -> Result>> { - if let Some(sys) = GLOBAL_BucketMetadataSys.get() { + if let Some(sys) = GLOBAL_BUCKET_METADATA_SYS.get() { Ok(sys.clone()) } else { - Err(Error::other("GLOBAL_BucketMetadataSys not init")) + Err(Error::other("GLOBAL_BUCKET_METADATA_SYS not init")) } } diff --git a/crates/ecstore/src/services/notification_sys.rs b/crates/ecstore/src/services/notification_sys.rs index 9e46709ab..a0e68a75d 100644 --- a/crates/ecstore/src/services/notification_sys.rs +++ b/crates/ecstore/src/services/notification_sys.rs @@ -60,18 +60,18 @@ impl PeerAdminCache { } lazy_static! { - pub static ref GLOBAL_NotificationSys: OnceLock = OnceLock::new(); + pub static ref GLOBAL_NOTIFICATION_SYS: OnceLock = OnceLock::new(); } pub async fn new_global_notification_sys(eps: EndpointServerPools) -> Result<()> { - let _ = GLOBAL_NotificationSys + let _ = GLOBAL_NOTIFICATION_SYS .set(NotificationSys::new(eps).await) .map_err(|_| Error::other("init notification_sys fail")); Ok(()) } pub fn get_global_notification_sys() -> Option<&'static NotificationSys> { - GLOBAL_NotificationSys.get() + GLOBAL_NOTIFICATION_SYS.get() } pub struct NotificationSys { diff --git a/docs/architecture/global-state-inventory.md b/docs/architecture/global-state-inventory.md index 8ab7538f1..375b9dc43 100644 --- a/docs/architecture/global-state-inventory.md +++ b/docs/architecture/global-state-inventory.md @@ -29,7 +29,7 @@ caches separate from runtime migration targets. | Owner-local compatibility | Existing compatibility adapters that are allowed to read globals while callers migrate to AppContext-first or owner-local runtime-source APIs. | `rustfs/src/*/runtime_sources.rs`, `rustfs/src/*/storage_api.rs`, `crates/*/storage_api.rs` | | Test or fixture state | Static setup used by tests to amortize expensive ECStore setup or isolate compatibility harness state. | `rustfs/src/app/*_test.rs`, `crates/scanner/tests/*`, `crates/ecstore/src/**/tests` | | Cache or constant | Regexes, metrics descriptors, defaults, KVS registrations, headers, path constants, and small process caches that are not runtime ownership handles. | `crates/config`, `crates/obs/src/metrics`, `crates/utils`, `rustfs/src/server/readiness.rs` | -| Legacy naming or review-needed | Remaining mixed-case `GLOBAL_*`, old MinIO-port naming, stale comments, or names that need owner confirmation before code movement. | `GLOBAL_NotificationSys`, `GLOBAL_OBJECT_API` | +| Legacy naming or review-needed | Old MinIO-port naming, stale comments, or names that need owner confirmation before code movement. | `GLOBAL_OBJECT_API` | ## Runtime Migration Inventory @@ -45,7 +45,8 @@ migration PR removes or replaces each item. | `GLOBAL_EXPIRY_STATE`, `GLOBAL_TRANSITION_STATE`, `GLOBAL_LIFECYCLE_SYS` | `crates/ecstore/src/bucket/lifecycle/*`, `crates/ecstore/src/runtime/global.rs`, and `crates/ecstore/src/runtime/sources.rs` | Runtime migration target | Lifecycle state globals now stay behind ECStore lifecycle owner helpers and ECStore runtime-source helpers; scanner expiry-state access now uses the ECStore runtime `expiry_state_handle` boundary; `GLOBAL_EXPIRY_STATE` remains the first code-bearing ownership candidate because AppContext already has an `ExpiryStateInterface`, resolver, and tests. | | `GLOBAL_REPLICATION_POOL`, `GLOBAL_REPLICATION_STATS`, `GLOBAL_BUCKET_MONITOR` | `crates/ecstore/src/bucket/replication/*`, `crates/ecstore/src/runtime/global.rs` | Runtime migration target | Replication pool/stat access now stays behind replication owner and ECStore runtime-source helpers; bucket-monitor direct access now stays behind ECStore runtime helpers while AppContext/runtime-source resolvers remain the caller boundary. | | `GLOBAL_TIER_CONFIG_MGR`, `GLOBAL_STORAGE_CLASS`, `GLOBAL_CONFIG_SYS`, `GLOBAL_SERVER_CONFIG` | `crates/ecstore/src/config`, `crates/config`, `rustfs/src/app/context/runtime_sources.rs` | Runtime migration target | Tier config manager reads and reloads now use the ECStore runtime-source helper; move remaining config state through config/runtime-source owners only, without combining storage-class behavior or persistence changes. | -| `GLOBAL_EVENT_NOTIFIER`, `GLOBAL_NotificationSys` | `crates/ecstore/src/runtime/global.rs`, `crates/ecstore/src/runtime/sources.rs`, and `crates/ecstore/src/services/*` | Runtime migration target | `GLOBAL_EVENT_NOTIFIER` access now stays behind ECStore runtime-source helpers; move remaining notification ownership only through notify/runtime-source boundaries. | +| `GLOBAL_EVENT_NOTIFIER`, `GLOBAL_NOTIFICATION_SYS` | `crates/ecstore/src/runtime/global.rs`, `crates/ecstore/src/runtime/sources.rs`, and `crates/ecstore/src/services/*` | Runtime migration target | `GLOBAL_EVENT_NOTIFIER` and `GLOBAL_NOTIFICATION_SYS` access now stay behind ECStore runtime-source and notification owner helpers; move remaining notification ownership only through notify/runtime-source boundaries. | +| `GLOBAL_BUCKET_METADATA_SYS` | `crates/ecstore/src/metadata/bucket_sys.rs`, `crates/ecstore/src/runtime/sources.rs`, and RustFS storage compatibility APIs | Runtime migration target | Bucket metadata system direct access now stays inside the ECStore metadata owner; callers use metadata owner helpers or storage/runtime-source compatibility functions until metadata ownership moves behind an injected runtime context. | | `GLOBAL_BOOT_TIME`, `GLOBAL_BACKGROUND_SERVICES_CANCEL_TOKEN`, `GLOBAL_DEPLOYMENT_ID`, `GLOBAL_REGION`, `GLOBAL_RUSTFS_PORT`, `GLOBAL_LOCAL_NODE_NAME_FALLBACK`, `GLOBAL_LOCAL_NODE_NAME_HEX_FALLBACK` | `crates/ecstore/src/runtime/global.rs`, `crates/ecstore/src/runtime/sources.rs` | Runtime migration target | Boot time, background service cancellation token reads, and ECStore local-node-name fallback reads now stay behind the ECStore runtime-source API; deployment ID, region, and port direct access now stays behind owner helpers until the remaining scalar handles migrate. | | `GLOBAL_LOCAL_LOCK_CLIENT`, `GLOBAL_LOCK_CLIENTS`, `GLOBAL_LOCK_MANAGER` | `crates/ecstore/src/runtime/global.rs`, `crates/lock` | Runtime migration target / process-global split | ECStore lock client direct access now stays behind ECStore runtime helpers; preserve lock quorum and lock client selection while keeping the process-level lock manager separate from endpoint-specific clients. | | `GLOBAL_CONN_MAP`, `GLOBAL_LOCAL_NODE_NAME`, `GLOBAL_RUSTFS_HOST`, `GLOBAL_RUSTFS_ADDR`, `GLOBAL_ROOT_CERT`, `GLOBAL_MTLS_IDENTITY`, `GLOBAL_OUTBOUND_TLS_GENERATION` | `crates/common`, `crates/tls-runtime`, `crates/ecstore/src/runtime/sources.rs` | Runtime migration target / process-global split | Internode connection cache, common local node name, RustFS host/address reads, and outbound TLS material reads are now owned behind `rustfs_common` helpers; migrate the remaining transport and TLS state only after internode transport and outbound TLS ownership are explicit, without changing cached channel reuse or TLS reload semantics. | diff --git a/rustfs/src/storage/ecfs_test.rs b/rustfs/src/storage/ecfs_test.rs index fe784495b..4541a7d02 100644 --- a/rustfs/src/storage/ecfs_test.rs +++ b/rustfs/src/storage/ecfs_test.rs @@ -958,7 +958,7 @@ mod tests { use time::OffsetDateTime; if !bucket_metadata_sys_initialized() { - eprintln!("Skipping test: GLOBAL_BucketMetadataSys not initialized"); + eprintln!("Skipping test: bucket metadata system not initialized"); return; } @@ -1539,7 +1539,7 @@ mod tests { #[tokio::test] async fn test_apply_cors_headers_unmatched_origin_with_cors_config() { if get_global_bucket_metadata_sys().is_none() { - eprintln!("Skipping test: GLOBAL_BucketMetadataSys not initialized"); + eprintln!("Skipping test: bucket metadata system not initialized"); return; } @@ -1577,7 +1577,7 @@ mod tests { #[tokio::test] async fn test_apply_cors_headers_credentialed_request_with_wildcard_origin() { if get_global_bucket_metadata_sys().is_none() { - eprintln!("Skipping test: GLOBAL_BucketMetadataSys not initialized"); + eprintln!("Skipping test: bucket metadata system not initialized"); return; } diff --git a/rustfs/src/storage/storage_api.rs b/rustfs/src/storage/storage_api.rs index d63d0cea8..b45477f3c 100644 --- a/rustfs/src/storage/storage_api.rs +++ b/rustfs/src/storage/storage_api.rs @@ -947,7 +947,7 @@ pub(crate) async fn load_bucket_metadata(api: Arc, bucket: &str) -> Res #[cfg(test)] pub(crate) fn bucket_metadata_sys_initialized() -> bool { - ecstore_bucket::metadata_sys::GLOBAL_BucketMetadataSys.get().is_some() + ecstore_bucket::metadata_sys::get_global_bucket_metadata_sys().is_some() } #[cfg(test)] diff --git a/scripts/check_architecture_migration_rules.sh b/scripts/check_architecture_migration_rules.sh index 362944cbb..625bf9274 100755 --- a/scripts/check_architecture_migration_rules.sh +++ b/scripts/check_architecture_migration_rules.sh @@ -197,6 +197,7 @@ REPLICATION_TAGGING_BOUNDARY_BYPASS_HITS_FILE="${TMP_DIR}/replication_tagging_bo REPLICATION_VERSIONING_BOUNDARY_BYPASS_HITS_FILE="${TMP_DIR}/replication_versioning_boundary_bypass_hits.txt" REPLICATION_RUNTIME_SOURCE_BYPASS_HITS_FILE="${TMP_DIR}/replication_runtime_source_bypass_hits.txt" GLOBAL_REPLICATION_STATE_BYPASS_HITS_FILE="${TMP_DIR}/global_replication_state_bypass_hits.txt" +GLOBAL_BUCKET_METADATA_SYS_BYPASS_HITS_FILE="${TMP_DIR}/global_bucket_metadata_sys_bypass_hits.txt" GLOBAL_BUCKET_TARGET_SYS_BYPASS_HITS_FILE="${TMP_DIR}/global_bucket_target_sys_bypass_hits.txt" GLOBAL_BUCKET_MONITOR_BYPASS_HITS_FILE="${TMP_DIR}/global_bucket_monitor_bypass_hits.txt" GLOBAL_ENDPOINTS_BYPASS_HITS_FILE="${TMP_DIR}/global_endpoints_bypass_hits.txt" @@ -210,6 +211,7 @@ GLOBAL_ROOT_DISK_THRESHOLD_BYPASS_HITS_FILE="${TMP_DIR}/global_root_disk_thresho GLOBAL_LIFECYCLE_STATE_BYPASS_HITS_FILE="${TMP_DIR}/global_lifecycle_state_bypass_hits.txt" GLOBAL_LIFECYCLE_SYS_BYPASS_HITS_FILE="${TMP_DIR}/global_lifecycle_sys_bypass_hits.txt" GLOBAL_EVENT_NOTIFIER_BYPASS_HITS_FILE="${TMP_DIR}/global_event_notifier_bypass_hits.txt" +GLOBAL_NOTIFICATION_SYS_BYPASS_HITS_FILE="${TMP_DIR}/global_notification_sys_bypass_hits.txt" GLOBAL_BOOT_TIME_BYPASS_HITS_FILE="${TMP_DIR}/global_boot_time_bypass_hits.txt" GLOBAL_ECSTORE_LOCAL_NODE_NAME_BYPASS_HITS_FILE="${TMP_DIR}/global_ecstore_local_node_name_bypass_hits.txt" GLOBAL_RUNTIME_SCALAR_BYPASS_HITS_FILE="${TMP_DIR}/global_runtime_scalar_bypass_hits.txt" @@ -2516,6 +2518,18 @@ if [[ -s "$GLOBAL_REPLICATION_STATE_BYPASS_HITS_FILE" ]]; then report_failure "GLOBAL_REPLICATION_POOL/STATS access must stay behind replication owner or ECStore runtime-source helpers: $(paste -sd '; ' "$GLOBAL_REPLICATION_STATE_BYPASS_HITS_FILE")" fi +( + cd "$ROOT_DIR" + rg -n --with-filename '\bGLOBAL_(BucketMetadataSys|BUCKET_METADATA_SYS)\b' \ + crates rustfs fuzz \ + --glob '*.rs' | + rg -v '^crates/ecstore/src/metadata/bucket_sys\.rs:' || true +) >"$GLOBAL_BUCKET_METADATA_SYS_BYPASS_HITS_FILE" + +if [[ -s "$GLOBAL_BUCKET_METADATA_SYS_BYPASS_HITS_FILE" ]]; then + report_failure "GLOBAL_BUCKET_METADATA_SYS access must stay behind ECStore bucket metadata owner helpers: $(paste -sd '; ' "$GLOBAL_BUCKET_METADATA_SYS_BYPASS_HITS_FILE")" +fi + ( cd "$ROOT_DIR" rg -n --with-filename '\bGLOBAL_BUCKET_TARGET_SYS\b' \ @@ -2672,6 +2686,18 @@ if [[ -s "$GLOBAL_EVENT_NOTIFIER_BYPASS_HITS_FILE" ]]; then report_failure "GLOBAL_EVENT_NOTIFIER access must stay behind ECStore runtime-source helpers: $(paste -sd '; ' "$GLOBAL_EVENT_NOTIFIER_BYPASS_HITS_FILE")" fi +( + cd "$ROOT_DIR" + rg -n --with-filename '\bGLOBAL_(NotificationSys|NOTIFICATION_SYS)\b' \ + crates rustfs fuzz \ + --glob '*.rs' | + rg -v '^crates/ecstore/src/services/notification_sys\.rs:' || true +) >"$GLOBAL_NOTIFICATION_SYS_BYPASS_HITS_FILE" + +if [[ -s "$GLOBAL_NOTIFICATION_SYS_BYPASS_HITS_FILE" ]]; then + report_failure "GLOBAL_NOTIFICATION_SYS access must stay behind ECStore notification owner helpers: $(paste -sd '; ' "$GLOBAL_NOTIFICATION_SYS_BYPASS_HITS_FILE")" +fi + ( cd "$ROOT_DIR" rg -n --with-filename '\bGLOBAL_BOOT_TIME\b' \