refactor(ecstore): wrap background cancel token access (#4078)

This commit is contained in:
Zhengchao An
2026-06-30 02:09:39 +08:00
committed by GitHub
parent d3a84395dc
commit 35d7d6bf23
5 changed files with 32 additions and 8 deletions
@@ -623,7 +623,7 @@ impl ExpiryState {
}
async fn worker(rx: &mut Receiver<Option<ExpiryOpType>>, api: Arc<ECStore>, stats: Arc<ExpiryStats>) {
let cancel_token = crate::runtime::global::get_background_services_cancel_token().unwrap_or_else(|| {
let cancel_token = runtime_sources::background_services_cancel_token().unwrap_or_else(|| {
static FALLBACK: std::sync::OnceLock<tokio_util::sync::CancellationToken> = std::sync::OnceLock::new();
FALLBACK.get_or_init(tokio_util::sync::CancellationToken::new)
});
@@ -1359,7 +1359,7 @@ fn spawn_tier_free_version_recovery_once(api: Arc<ECStore>) {
}
tokio::spawn(async move {
let cancel_token = crate::runtime::global::get_background_services_cancel_token()
let cancel_token = runtime_sources::background_services_cancel_token()
.cloned()
.unwrap_or_else(CancellationToken::new);
let mut interval = tokio::time::interval(StdDuration::from_secs(60));
@@ -1434,7 +1434,7 @@ fn spawn_tier_delete_journal_recovery_once(api: Arc<ECStore>) {
}
tokio::spawn(async move {
let cancel_token = crate::runtime::global::get_background_services_cancel_token()
let cancel_token = runtime_sources::background_services_cancel_token()
.cloned()
.unwrap_or_else(CancellationToken::new);
run_tier_delete_journal_recovery_loop(api, cancel_token).await;
@@ -16,6 +16,7 @@ use std::sync::Arc;
use s3s::dto::BucketLifecycleConfiguration;
use tokio::sync::RwLock;
use tokio_util::sync::CancellationToken;
use crate::bucket::lifecycle::bucket_lifecycle_ops::{ExpiryState, TransitionState};
use crate::runtime::sources;
@@ -34,6 +35,10 @@ pub(crate) fn tier_config_mgr_handle() -> Arc<RwLock<TierConfigMgr>> {
sources::tier_config_mgr_handle()
}
pub(crate) fn background_services_cancel_token() -> Option<&'static CancellationToken> {
sources::background_services_cancel_token()
}
pub(crate) fn object_store_handle() -> Option<Arc<ECStore>> {
sources::object_store_handle()
}