refactor(ecstore): migrate background replication pool/stats into InstanceContext (Phase 5 Slice 11) (#4495)

Phase 5 Slice 11 (backlog#939): move the background replication pool and stats —
the last service handles, and the only async ones — out of the process statics
into the per-instance InstanceContext.

- InstanceContext gains `replication_stats: OnceCell<Arc<ReplicationStats>>` and
  `replication_pool: OnceCell<Arc<DynReplicationPool>>` (tokio async OnceCell),
  with sync read accessors (`replication_stats`/`replication_pool`/
  `replication_initialized`) and pub(crate) cell accessors for the async init.
- `init_background_replication` initializes the current instance's cells via the
  same `get_or_init(async {…}).await` (workers still spawned once on first
  init). The lifecycle owner helpers and the runtime-source accessors keep their
  signatures and route through the current instance's context; the two statics
  (and the now-unused lazy_static import) are removed. The replication-boundary
  arch guard still passes.

Single-instance: init materializes one shared pool/stats via the bootstrap
context — byte-for-byte the same as the eager statics.

Tests: replication state is None until set and independent across instances.

Verification: cargo test -p rustfs-ecstore (22 instance-context tests green),
cargo clippy -p rustfs-ecstore --all-targets (clean), make pre-commit (pass).

Refs: backlog#939 (Phase 5, Slice 11). Stacked on Slice 10 (#4494).
This commit is contained in:
Zhengchao An
2026-07-08 23:15:01 +08:00
committed by GitHub
parent db8ba9e2e5
commit ca63a6cced
3 changed files with 80 additions and 17 deletions
+4 -7
View File
@@ -23,10 +23,7 @@ use crate::disk::endpoint::Endpoint;
use crate::{
bucket::lifecycle::bucket_lifecycle_ops::{ExpiryState, TransitionState},
bucket::metadata_sys::{BucketMetadataSys, get_global_bucket_metadata_sys},
bucket::replication::{
DynReplicationPool, ReplicationStats,
replication_pool::{GLOBAL_REPLICATION_POOL, GLOBAL_REPLICATION_STATS},
},
bucket::replication::{DynReplicationPool, ReplicationStats},
config::{get_global_storage_class, set_global_storage_class, storageclass},
disk::{DiskAPI, DiskOption, DiskStore, new_disk},
error::Result,
@@ -271,15 +268,15 @@ pub fn deployment_id() -> Option<String> {
}
pub(crate) fn replication_pool() -> Option<Arc<DynReplicationPool>> {
GLOBAL_REPLICATION_POOL.get().cloned()
crate::runtime::global::current_ctx().replication_pool()
}
pub(crate) fn replication_stats() -> Option<Arc<ReplicationStats>> {
GLOBAL_REPLICATION_STATS.get().cloned()
crate::runtime::global::current_ctx().replication_stats()
}
pub(crate) fn replication_runtime_initialized() -> bool {
GLOBAL_REPLICATION_STATS.get().is_some() && GLOBAL_REPLICATION_POOL.get().is_some()
crate::runtime::global::current_ctx().replication_initialized()
}
pub(crate) fn ensure_deployment_id(deployment_id: Uuid) {