mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-08 14:23:13 +00:00
refactor: remove scalar runtime fallbacks (#3957)
This commit is contained in:
+17
-22
@@ -62,9 +62,8 @@ pub async fn resolve_encryption_service() -> Option<Arc<ObjectEncryptionService>
|
||||
}
|
||||
|
||||
/// Resolve outbound TLS generation using AppContext-first precedence.
|
||||
pub fn resolve_outbound_tls_generation() -> TlsGeneration {
|
||||
pub fn resolve_outbound_tls_generation() -> Option<TlsGeneration> {
|
||||
resolve_outbound_tls_generation_with(get_global_app_context())
|
||||
.unwrap_or_else(|| default_outbound_tls_runtime_interface().generation())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -176,8 +175,8 @@ pub fn resolve_boot_time() -> Option<SystemTime> {
|
||||
}
|
||||
|
||||
/// Resolve daily tier transition statistics using AppContext-first precedence.
|
||||
pub fn resolve_daily_tier_stats() -> DailyAllTierStats {
|
||||
resolve_daily_tier_stats_with(get_global_app_context()).unwrap_or_else(|| default_tier_stats_interface().daily_all())
|
||||
pub fn resolve_daily_tier_stats() -> Option<DailyAllTierStats> {
|
||||
resolve_daily_tier_stats_with(get_global_app_context())
|
||||
}
|
||||
|
||||
/// Resolve scanner metrics report using AppContext-first precedence.
|
||||
@@ -195,8 +194,8 @@ pub fn resolve_deployment_id() -> Option<String> {
|
||||
}
|
||||
|
||||
/// Resolve runtime port using AppContext-first precedence.
|
||||
pub fn resolve_runtime_port() -> u16 {
|
||||
resolve_runtime_port_with(get_global_app_context()).unwrap_or_else(|| default_runtime_port_interface().get())
|
||||
pub fn resolve_runtime_port() -> Option<u16> {
|
||||
resolve_runtime_port_with(get_global_app_context())
|
||||
}
|
||||
|
||||
/// Resolve lock client using AppContext-first precedence.
|
||||
@@ -210,13 +209,13 @@ pub fn resolve_lock_clients_handle() -> Option<HashMap<String, Arc<dyn LockClien
|
||||
}
|
||||
|
||||
/// Resolve performance metrics using AppContext-first precedence.
|
||||
pub fn resolve_performance_metrics() -> Arc<PerformanceMetrics> {
|
||||
resolve_performance_metrics_with(get_global_app_context()).unwrap_or_else(|| default_performance_metrics_interface().handle())
|
||||
pub fn resolve_performance_metrics() -> Option<Arc<PerformanceMetrics>> {
|
||||
resolve_performance_metrics_with(get_global_app_context())
|
||||
}
|
||||
|
||||
/// Resolve internode metrics using AppContext-first precedence.
|
||||
pub fn resolve_internode_metrics() -> Arc<InternodeMetrics> {
|
||||
resolve_internode_metrics_with(get_global_app_context()).unwrap_or_else(|| default_internode_metrics_interface().handle())
|
||||
pub fn resolve_internode_metrics() -> Option<Arc<InternodeMetrics>> {
|
||||
resolve_internode_metrics_with(get_global_app_context())
|
||||
}
|
||||
|
||||
/// Resolve S3 Select database using AppContext-first precedence.
|
||||
@@ -232,12 +231,8 @@ pub async fn resolve_s3select_db(
|
||||
}
|
||||
|
||||
/// Resolve local node name using AppContext-first precedence.
|
||||
pub async fn resolve_local_node_name() -> String {
|
||||
if let Some(node_name) = resolve_local_node_name_with(get_global_app_context()).await {
|
||||
return node_name;
|
||||
}
|
||||
|
||||
runtime_sources::local_node_name().await
|
||||
pub async fn resolve_local_node_name() -> Option<String> {
|
||||
resolve_local_node_name_with(get_global_app_context()).await
|
||||
}
|
||||
|
||||
/// Resolve action credentials using AppContext-first precedence.
|
||||
@@ -251,13 +246,13 @@ pub fn resolve_region() -> Option<s3s::region::Region> {
|
||||
}
|
||||
|
||||
/// Resolve tier config handle using AppContext-first precedence.
|
||||
pub fn resolve_tier_config_handle() -> Arc<RwLock<TierConfigMgr>> {
|
||||
resolve_tier_config_handle_with(get_global_app_context()).unwrap_or_else(|| default_tier_config_interface().handle())
|
||||
pub fn resolve_tier_config_handle() -> Option<Arc<RwLock<TierConfigMgr>>> {
|
||||
resolve_tier_config_handle_with(get_global_app_context())
|
||||
}
|
||||
|
||||
/// Resolve lifecycle expiry state using AppContext-first precedence.
|
||||
pub fn resolve_expiry_state_handle() -> Arc<RwLock<ExpiryState>> {
|
||||
resolve_expiry_state_handle_with(get_global_app_context()).unwrap_or_else(|| default_expiry_state_interface().handle())
|
||||
pub fn resolve_expiry_state_handle() -> Option<Arc<RwLock<ExpiryState>>> {
|
||||
resolve_expiry_state_handle_with(get_global_app_context())
|
||||
}
|
||||
|
||||
/// Resolve server config using AppContext-first precedence.
|
||||
@@ -283,8 +278,8 @@ pub fn publish_storage_class_config(config: StorageClassConfig) {
|
||||
}
|
||||
|
||||
/// Resolve buffer profile config using AppContext-first precedence.
|
||||
pub fn resolve_buffer_config() -> RustFSBufferConfig {
|
||||
resolve_buffer_config_with(get_global_app_context()).unwrap_or_else(|| default_buffer_config_interface().get())
|
||||
pub fn resolve_buffer_config() -> Option<RustFSBufferConfig> {
|
||||
resolve_buffer_config_with(get_global_app_context())
|
||||
}
|
||||
|
||||
fn resolve_kms_runtime_service_manager_with(context: Option<Arc<AppContext>>) -> Option<Arc<KmsServiceManager>> {
|
||||
|
||||
@@ -13,19 +13,23 @@
|
||||
// limitations under the License.
|
||||
|
||||
use crate::app::context;
|
||||
use crate::config::RustFSBufferConfig;
|
||||
use crate::storage_api::server::runtime_sources::{DailyAllTierStats, ExpiryState, TierConfigMgr};
|
||||
use rustfs_io_metrics::{PerformanceMetrics, internode_metrics::InternodeMetrics};
|
||||
use rustfs_tls_runtime::TlsGeneration;
|
||||
use std::sync::Arc;
|
||||
#[cfg(test)]
|
||||
use std::sync::atomic::{AtomicU64, Ordering};
|
||||
use tokio::sync::RwLock;
|
||||
|
||||
pub(crate) use context::{
|
||||
AppContext, NotifyInterface, publish_oidc_handle, publish_server_config, publish_storage_class_config,
|
||||
resolve_action_credentials as current_action_credentials, resolve_boot_time as current_boot_time,
|
||||
resolve_bucket_metadata_handle as current_bucket_metadata_handle,
|
||||
resolve_bucket_monitor_handle as current_bucket_monitor_handle, resolve_buffer_config as current_buffer_config,
|
||||
resolve_daily_tier_stats as current_daily_tier_stats, resolve_deployment_id as current_deployment_id,
|
||||
resolve_bucket_monitor_handle as current_bucket_monitor_handle, resolve_deployment_id as current_deployment_id,
|
||||
resolve_encryption_service as current_encryption_service, resolve_endpoints_handle as current_endpoints_handle,
|
||||
resolve_expiry_state_handle as current_expiry_state_handle, resolve_iam_handle as current_iam_handle,
|
||||
resolve_iam_ready as current_iam_ready, resolve_internode_metrics as current_internode_metrics,
|
||||
resolve_kms_runtime_service_manager as current_kms_runtime_service_manager,
|
||||
resolve_local_node_name as current_local_node_name, resolve_lock_client as current_lock_client,
|
||||
resolve_iam_handle as current_iam_handle, resolve_iam_ready as current_iam_ready,
|
||||
resolve_kms_runtime_service_manager as current_kms_runtime_service_manager, resolve_lock_client as current_lock_client,
|
||||
resolve_lock_clients_handle as current_lock_clients_handle, resolve_notification_system as current_notification_system,
|
||||
resolve_notification_system_for_context as current_notification_system_for_context,
|
||||
resolve_notify_interface as current_notify_interface,
|
||||
@@ -34,18 +38,69 @@ pub(crate) use context::{
|
||||
resolve_object_store_handle_for_context as current_object_store_handle_for_context,
|
||||
resolve_oidc_handle as current_oidc_handle,
|
||||
resolve_or_init_kms_runtime_service_manager as current_or_init_kms_runtime_service_manager,
|
||||
resolve_outbound_tls_generation as current_outbound_tls_generation, resolve_outbound_tls_state as current_outbound_tls_state,
|
||||
resolve_performance_metrics as current_performance_metrics, resolve_ready_iam_handle as current_ready_iam_handle,
|
||||
resolve_outbound_tls_state as current_outbound_tls_state, resolve_ready_iam_handle as current_ready_iam_handle,
|
||||
resolve_region as current_region, resolve_replication_pool_handle as current_replication_pool_handle,
|
||||
resolve_replication_stats_handle as current_replication_stats_handle, resolve_runtime_port as current_runtime_port,
|
||||
resolve_s3select_db as current_s3select_db, resolve_scanner_metrics_report as current_scanner_metrics_report,
|
||||
resolve_server_config as current_server_config, resolve_server_config_for_context as current_server_config_for_context,
|
||||
resolve_tier_config_handle as current_tier_config_handle, resolve_token_signing_key as current_token_signing_key,
|
||||
resolve_replication_stats_handle as current_replication_stats_handle, resolve_s3select_db as current_s3select_db,
|
||||
resolve_scanner_metrics_report as current_scanner_metrics_report, resolve_server_config as current_server_config,
|
||||
resolve_server_config_for_context as current_server_config_for_context,
|
||||
resolve_token_signing_key as current_token_signing_key,
|
||||
};
|
||||
|
||||
#[cfg(test)]
|
||||
pub(crate) use context::set_test_outbound_tls_generation;
|
||||
static TEST_OUTBOUND_TLS_GENERATION: AtomicU64 = AtomicU64::new(0);
|
||||
|
||||
#[cfg(test)]
|
||||
pub(crate) fn set_test_outbound_tls_generation(generation: u64) {
|
||||
context::set_test_outbound_tls_generation(generation);
|
||||
TEST_OUTBOUND_TLS_GENERATION.store(generation, Ordering::Relaxed);
|
||||
}
|
||||
|
||||
pub(crate) fn current_app_context() -> Option<Arc<AppContext>> {
|
||||
context::get_global_app_context()
|
||||
}
|
||||
|
||||
pub(crate) fn current_outbound_tls_generation() -> TlsGeneration {
|
||||
context::resolve_outbound_tls_generation().unwrap_or_else(empty_outbound_tls_generation)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
fn empty_outbound_tls_generation() -> TlsGeneration {
|
||||
TlsGeneration(TEST_OUTBOUND_TLS_GENERATION.load(Ordering::Relaxed))
|
||||
}
|
||||
|
||||
#[cfg(not(test))]
|
||||
fn empty_outbound_tls_generation() -> TlsGeneration {
|
||||
TlsGeneration(0)
|
||||
}
|
||||
|
||||
pub(crate) fn current_daily_tier_stats() -> DailyAllTierStats {
|
||||
context::resolve_daily_tier_stats().unwrap_or_default()
|
||||
}
|
||||
|
||||
pub(crate) fn current_runtime_port() -> u16 {
|
||||
context::resolve_runtime_port().unwrap_or(rustfs_config::DEFAULT_PORT)
|
||||
}
|
||||
|
||||
pub(crate) fn current_performance_metrics() -> Arc<PerformanceMetrics> {
|
||||
context::resolve_performance_metrics().unwrap_or_else(|| Arc::new(PerformanceMetrics::new()))
|
||||
}
|
||||
|
||||
pub(crate) fn current_internode_metrics() -> Arc<InternodeMetrics> {
|
||||
context::resolve_internode_metrics().unwrap_or_else(|| Arc::new(InternodeMetrics::default()))
|
||||
}
|
||||
|
||||
pub(crate) async fn current_local_node_name() -> String {
|
||||
context::resolve_local_node_name().await.unwrap_or_default()
|
||||
}
|
||||
|
||||
pub(crate) fn current_tier_config_handle() -> Arc<RwLock<TierConfigMgr>> {
|
||||
context::resolve_tier_config_handle().unwrap_or_else(TierConfigMgr::new)
|
||||
}
|
||||
|
||||
pub(crate) fn current_expiry_state_handle() -> Arc<RwLock<ExpiryState>> {
|
||||
context::resolve_expiry_state_handle().unwrap_or_else(ExpiryState::new)
|
||||
}
|
||||
|
||||
pub(crate) fn current_buffer_config() -> RustFSBufferConfig {
|
||||
context::resolve_buffer_config().unwrap_or_default()
|
||||
}
|
||||
|
||||
@@ -142,7 +142,9 @@ pub(crate) mod server {
|
||||
}
|
||||
|
||||
pub(crate) mod runtime_sources {
|
||||
pub(crate) use crate::storage::storage_api::{ECStore, EndpointServerPools};
|
||||
pub(crate) use crate::storage::storage_api::{
|
||||
DailyAllTierStats, ECStore, EndpointServerPools, ExpiryState, TierConfigMgr,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user