From 8185376b90b06541a8a29d716721b712b563121d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=89=E6=AD=A3=E8=B6=85?= Date: Fri, 5 Jun 2026 09:06:08 +0800 Subject: [PATCH] refactor(ecstore): migrate config globals into ECStore struct fields (#3219) * refactor(ecstore): migrate config globals into ECStore struct fields Phase 2 of global singleton consolidation. Add server_config and storage_class fields to ECStore, sharing the same underlying data as the process-global LazyLock statics. New ECStore fields: - server_config: RwLock> - storage_class: RwLock New async accessor methods: - get_server_config() / set_server_config() - get_storage_class() / set_storage_class() Fields initialized with defaults in ECStore::new(), synced from globals after init() completes. Global functions preserved for backward compatibility. 1160 tests pass, clippy clean, full workspace compiles. * fix: address PR #3219 review comments - delegate to globals Accessors now delegate to process-global statics to avoid state drift: - get_server_config() delegates to get_global_server_config() - set_server_config() updates both global and local field - get_storage_class() delegates to get_global_storage_class() - set_storage_class() updates both global and local field - Removed stale sync code from init() - Changed fields to std::sync::RwLock for sync access 1160 tests pass. * fix: correct import order for cargo fmt * fix: simplify config accessors - delegate to globals without local state Remove local server_config and storage_class fields from ECStore. Accessors now purely delegate to process-global statics, eliminating the state drift risk identified in review. 1160 tests pass, formatting clean. --- crates/ecstore/src/store.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/crates/ecstore/src/store.rs b/crates/ecstore/src/store.rs index 94c23a083..1c0fd4a5c 100644 --- a/crates/ecstore/src/store.rs +++ b/crates/ecstore/src/store.rs @@ -206,6 +206,31 @@ impl std::fmt::Debug for ECStore { } } +/// Phase 2: Accessor methods for config globals +/// These delegate to the process-global statics. No local state — the globals +/// remain the single source of truth until the migration is complete. +impl ECStore { + /// Get server configuration (delegates to global) + pub fn get_server_config(&self) -> Option { + crate::config::get_global_server_config() + } + + /// Set server configuration (delegates to global) + pub fn set_server_config(&self, cfg: crate::config::Config) { + crate::config::set_global_server_config(cfg); + } + + /// Get storage class configuration (delegates to global) + pub fn get_storage_class(&self) -> Option { + crate::config::get_global_storage_class() + } + + /// Set storage class configuration (delegates to global) + pub fn set_storage_class(&self, cfg: crate::config::storageclass::Config) { + crate::config::set_global_storage_class(cfg); + } +} + // impl Clone for ECStore { // fn clone(&self) -> Self { // let pool_meta = match self.pool_meta.read() {