mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-09 14:49:25 +00:00
refactor(ecstore): wrap background cancel token access (#4078)
This commit is contained in:
@@ -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()
|
||||
}
|
||||
|
||||
@@ -31,10 +31,11 @@ use crate::{
|
||||
runtime::global::{
|
||||
GLOBAL_BOOT_TIME, GLOBAL_EventNotifier, GLOBAL_IsErasureSD, GLOBAL_LOCAL_DISK_ID_MAP, GLOBAL_LOCAL_DISK_MAP,
|
||||
GLOBAL_LOCAL_DISK_SET_DRIVES, GLOBAL_LifecycleSys, GLOBAL_LocalNodeName, GLOBAL_RootDiskThreshold, GLOBAL_TierConfigMgr,
|
||||
TypeLocalDiskSetDrives, get_global_bucket_monitor, get_global_deployment_id, get_global_endpoints,
|
||||
get_global_endpoints_opt, get_global_lock_clients, get_global_region, get_global_tier_config_mgr, global_rustfs_port,
|
||||
init_global_bucket_monitor, is_dist_erasure, is_erasure, is_first_cluster_node_local, resolve_object_store_handle,
|
||||
set_global_deployment_id, set_global_lock_client, set_global_lock_clients, set_object_layer, update_erasure_type,
|
||||
TypeLocalDiskSetDrives, get_background_services_cancel_token, get_global_bucket_monitor, get_global_deployment_id,
|
||||
get_global_endpoints, get_global_endpoints_opt, get_global_lock_clients, get_global_region, get_global_tier_config_mgr,
|
||||
global_rustfs_port, init_global_bucket_monitor, is_dist_erasure, is_erasure, is_first_cluster_node_local,
|
||||
resolve_object_store_handle, set_global_deployment_id, set_global_lock_client, set_global_lock_clients, set_object_layer,
|
||||
update_erasure_type,
|
||||
},
|
||||
services::batch_processor::{GlobalBatchProcessors, get_global_processors},
|
||||
services::event_notification::EventNotifier,
|
||||
@@ -50,6 +51,7 @@ use rustfs_lock::client::LockClient;
|
||||
use s3s::dto::BucketLifecycleConfiguration;
|
||||
use s3s::region::Region;
|
||||
use tokio::sync::{RwLock, RwLockReadGuard};
|
||||
use tokio_util::sync::CancellationToken;
|
||||
use tonic::transport::Channel;
|
||||
use uuid::Uuid;
|
||||
|
||||
@@ -178,6 +180,10 @@ pub(crate) fn rustfs_port() -> u16 {
|
||||
global_rustfs_port()
|
||||
}
|
||||
|
||||
pub(crate) fn background_services_cancel_token() -> Option<&'static CancellationToken> {
|
||||
get_background_services_cancel_token()
|
||||
}
|
||||
|
||||
pub(crate) async fn rustfs_host() -> String {
|
||||
rustfs_common::get_global_rustfs_host().await
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user