refactor(config): move global config accessors (#3360)

This commit is contained in:
安正超
2026-06-11 19:16:02 +08:00
committed by GitHub
parent ed3851782c
commit b4524033e3
15 changed files with 131 additions and 65 deletions
@@ -30,6 +30,12 @@ for later deletion.
- Why: old `StorageAPI::new_ns_lock` callers must keep compiling while namespace-lock-only consumers migrate to NamespaceLocking.
- Removal condition: remove after all namespace-lock-only consumers depend on NamespaceLocking and StorageAPI no longer owns namespace lock capability.
- Status: planned cleanup.
- `RUSTFS_COMPAT_TODO(CFG-008)`
- Task: `CFG-008`
- File: `crates/ecstore/src/config/mod.rs`
- Why: old `rustfs_ecstore::config` global server-config accessor paths must keep compiling while runtime consumers migrate.
- Removal condition: remove after all consumers import global server-config accessors from `rustfs_config::server_config`.
- Status: planned cleanup.
## Review Checklist
+24 -5
View File
@@ -34,6 +34,12 @@ That re-export included `RUSTFS_COMPAT_TODO(CFG-004)` and a matching entry in
consumers were migrated. The CFG-004 cleanup removed this old model path after
code scans showed consumers import the model directly from `rustfs-config`.
Follow-up `CFG-008` moved the process-global server-config snapshot accessors
to `rustfs_config::server_config` after the model path stabilized. ECStore keeps
only a temporary `rustfs_ecstore::config::{get_global_server_config,
set_global_server_config}` compatibility re-export while in-repo runtime
consumers migrate.
## Why `rustfs-config`
`rustfs-config` is already the lowest RustFS crate for configuration constants
@@ -51,7 +57,8 @@ removing any storage or runtime dependency by itself.
The server-config model module may use only:
- `std::collections::HashMap`
- `std::sync::{LazyLock, OnceLock}` for the default `KVS` registration surface
- `std::sync::{LazyLock, OnceLock, RwLock}` for the default `KVS` registration
surface and process-global server-config snapshot
- `serde` for `KV` and `KVS` serialization compatibility
- `serde_json` for `Config::marshal` and `Config::unmarshal`
- existing `rustfs-config` constants and subsystem modules
@@ -71,7 +78,8 @@ The model module must not depend on:
- notify, audit, targets, IAM, scanner, KMS, or admin handler crates
- async runtimes, HTTP/router crates, object-store crates, or runtime lifecycle
state
- global server-config snapshot state such as `GLOBAL_SERVER_CONFIG`
- unrelated runtime global state outside the process-global server-config
snapshot
- `ConfigSys`, `read_config_without_migrate`, `save_server_config`, or any
`com.rs` persistence helper
@@ -94,9 +102,6 @@ Move in the first extraction:
Keep in `ecstore`:
- `ConfigSys`
- `GLOBAL_SERVER_CONFIG`
- `get_global_server_config`
- `set_global_server_config`
- `init_global_config_sys`
- `try_migrate_server_config`
- `read_config_without_migrate`
@@ -109,6 +114,15 @@ extracts a dedicated default-registration contract. The values may be registered
through the moved `rustfs_config::server_config::register_default_kvs`, but the
startup order and caller remain unchanged.
Move in `CFG-008`:
- `GLOBAL_SERVER_CONFIG`
- `get_global_server_config`
- `set_global_server_config`
Keep a temporary ECStore compatibility re-export for these accessors until all
consumers use `rustfs_config::server_config` directly.
## Required Shape Preservation
The extraction PR must preserve:
@@ -138,6 +152,11 @@ all in-repo consumers migrated.
`CFG-005` should migrate external consumers one group at a time after the model
and compatibility path are stable.
`CFG-008` moves only the global server-config snapshot accessors to
`rustfs-config` and migrates in-repo direct consumers. It must not move
`ConfigSys`, storage-class global state, persistence helpers, default
registration wiring, startup order, or storage behavior.
## Verification Gate
Before pushing an extraction PR, run:
+55 -31
View File
@@ -5,17 +5,17 @@ Status values: `[ ]` not started, `[~]` in progress, `[x]` complete, `[!]` block
## Current Context
- Issue: [`rustfs/backlog#660`](https://github.com/rustfs/backlog/issues/660)
- Branch: `overtrue/arch-config-compat-cleanup`
- Baseline: `origin/main` at `69549634ea9524724dafd6bd90c8639880a2dbc6`
- Branch: `overtrue/arch-config-global-state`
- Baseline: `origin/main` at `ed3851782c48131e6102735d44d80fb6014a0699`
- PR type for this branch: `api-extraction`
- Runtime behavior changes: none.
- Rust code changes: remove the temporary CFG-004
`rustfs_ecstore::config` server-config model compatibility re-export and its
smoke test after all in-repo consumers migrated to
`rustfs_config::server_config`.
- Runtime behavior changes: none intended.
- Rust code changes: move the process-global server-config snapshot accessors
to `rustfs_config::server_config`, migrate in-repo direct consumers to the
new owner, and keep a temporary ECStore compatibility re-export for the old
accessor path.
- CI/script changes: none.
- Docs changes: record CFG-004 cleanup context, update the compatibility
cleanup register, and mark the model-boundary ADR cleanup status.
- Docs changes: record CFG-008 global accessor ownership, update the
compatibility cleanup register, and mark the model-boundary ADR follow-up.
## Phase 0 Tasks
@@ -116,6 +116,19 @@ Status values: `[ ]` not started, `[~]` in progress, `[x]` complete, `[!]` block
env overrides, persisted-config validation, cycle scheduling, bitrot-cycle
compatibility, cache timeout, and alert threshold semantics remain
unchanged.
- [x] `CFG-008` Move global server-config accessors.
- Current branch: move `GLOBAL_SERVER_CONFIG`,
`get_global_server_config`, and `set_global_server_config` to
`rustfs_config::server_config`; migrate in-repo runtime consumers to the
new owner.
- Compatibility: keep
`rustfs_ecstore::config::{get_global_server_config,
set_global_server_config}` as a temporary re-export with
`RUSTFS_COMPAT_TODO(CFG-008)`.
- Acceptance: ECStore still owns `ConfigSys`, config persistence helpers,
storage-class global state, default registration wiring, and startup
initialization; global server-config reads and writes keep the same
`std::sync::RwLock<Option<Config>>` clone semantics.
## Phase 1 Security Governance Tasks
@@ -349,25 +362,31 @@ Status values: `[ ]` not started, `[~]` in progress, `[x]` complete, `[!]` block
| Expert | Status | Notes |
|---|---|---|
| Quality/architecture | pass | Confirmed the diff only removes the temporary model re-export and smoke test; ECStore persistence helpers, global state, startup wiring, and default registration remain unchanged. |
| Migration preservation | pass | Confirmed `ConfigSys`, `GLOBAL_SERVER_CONFIG`, storage-class globals/accessors, read/save/serde paths, scanner/admin consumers, and in-repo model imports remain correct after old-path removal. |
| Testing/verification | pass | Confirmed ECStore config tests, rustfs-config/ECStore/server compile check, migration guards, old-path scan, and added-line risk scan are sufficient; full pre-commit is skipped under the current larger-granularity instruction. |
| Quality/architecture | pass | Confirmed the diff only moves the process-global server-config snapshot accessors to `rustfs-config`, keeps ECStore persistence and storage-class ownership unchanged, and keeps the old accessor path as a temporary compatibility re-export. |
| Migration preservation | pass | Confirmed scanner, IAM, admin, app context, and ECStore store consumers read and write the same global server-config snapshot through the new owner without changing startup, persistence, or storage behavior. |
| Testing/verification | pass | Confirmed focused compile/tests, migration guards, old-path scan, dependency check, and Rust risk scan cover the changed accessor ownership; full pre-commit is skipped under the current larger-granularity instruction. |
## Verification Notes
Passed:
- `cargo check -p rustfs-config -p rustfs-ecstore -p rustfs-iam -p rustfs-scanner -p rustfs --lib`.
- `cargo test -p rustfs-config --lib`; 26 passed.
- `cargo test -p rustfs-ecstore config --lib`; 59 passed.
- `cargo check -p rustfs-config -p rustfs-ecstore -p rustfs --lib`.
- `cargo test -p rustfs-scanner runtime_config --lib`; 16 passed.
- `cargo test -p rustfs admin::handlers::config_admin --lib`; 29 passed.
- `cargo test -p rustfs admin::handlers::oidc --lib`; 20 passed.
- `cargo test -p rustfs-iam oidc --lib`; 53 passed.
- `cargo fmt --all --check`.
- `./scripts/check_architecture_migration_rules.sh`.
- `./scripts/check_layer_dependencies.sh`.
- `./scripts/check_metrics_migration_refs.sh`.
- `./scripts/check_unsafe_code_allowances.sh`.
- `git diff --check`.
- CFG-004 old model code-path scan found no
`rustfs_ecstore::config::{Config, KV, KVS, DEFAULT_KVS,
register_default_kvs}` imports and no `RUSTFS_COMPAT_TODO(CFG-004)` markers
in `crates/**/*.rs` or `rustfs/src`.
- `cargo tree -p rustfs-config --edges normal` found no dependency on
`rustfs-ecstore`, `rustfs-scanner`, `rustfs-iam`, or `rustfs`.
- CFG-008 old accessor code-path scan found no direct in-repo runtime imports
from `rustfs_ecstore::config::{get_global_server_config,
set_global_server_config}` or `crate::config::{get_global_server_config,
set_global_server_config}` in `crates/**/*.rs` or `rustfs/src`.
- Added-line risk scan found no production `unwrap`/`expect`, lossy numeric
casts, stringly public errors, boxed dynamic errors, stdout/stderr printing,
or relaxed atomic ordering.
@@ -375,20 +394,25 @@ Passed:
Notes:
- Full pre-commit may be skipped if focused tests, compile checks, and guards
pass, per the current instruction to increase PR granularity.
- This slice removes only the old pure model compatibility path. ECStore
retains persistence helpers, ConfigSys, global server-config state,
storage-class global state, startup wiring, and all storage/config persistence
logic.
- The old `rustfs_ecstore::config` model path is no longer available after this
cleanup. Consumers must use `rustfs_config::server_config`.
- `./scripts/check_unsafe_code_allowances.sh` is not counted for this PR; it
currently reports unrelated existing unsafe allowance locations whose nearby
`SAFETY:` comments are present.
- This slice moves only `GLOBAL_SERVER_CONFIG`, `get_global_server_config`, and
`set_global_server_config` to `rustfs_config::server_config`.
- ECStore retains `ConfigSys`, config persistence helpers, storage-class global
state, default registration wiring, startup initialization, and storage
behavior.
- The old `rustfs_ecstore::config` accessor path remains available through a
temporary `RUSTFS_COMPAT_TODO(CFG-008)` re-export for downstream callers.
## Handoff Notes
- Keep this CFG-004 cleanup slice as an `api-extraction` PR that only removes
the temporary model compatibility re-export and its cleanup-register entry.
- Do not move `ConfigSys`, `GLOBAL_SERVER_CONFIG`, storage-class global state,
- Keep this CFG-008 slice as an `api-extraction` PR that only moves the global
server-config snapshot accessors and migrates direct in-repo runtime
consumers to `rustfs_config::server_config`.
- Do not move `ConfigSys`, storage-class global state,
`read_config_without_migrate`, `save_server_config`, config-object helpers,
startup wiring, storage-class helpers, ECStore persistence helpers, or storage
persistence logic in this PR.
- Do not add temporary compatibility code unless a matching
`RUSTFS_COMPAT_TODO(<task-id>)` marker and cleanup-register entry are added.
default registration wiring, startup wiring, storage-class helpers, ECStore
persistence helpers, or storage persistence logic in this PR.
- Remove the CFG-008 compatibility re-export only after downstream and in-repo
consumers no longer need `rustfs_ecstore::config` accessor imports.