refactor: move runtime fallback defaults to owners (#3961)

This commit is contained in:
Zhengchao An
2026-06-27 22:21:09 +08:00
committed by GitHub
parent 20f56af09c
commit c7dc3d7974
12 changed files with 217 additions and 164 deletions
+80 -9
View File
@@ -12,25 +12,28 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use crate::admin::storage_api::runtime::{ECStore, NotificationSys};
use crate::admin::storage_api::runtime_sources::{
DailyAllTierStats, ECStore, NotificationSys, ScannerMetricsReport, StorageClassConfig, TierConfigMgr,
};
pub(crate) use crate::app::admin_usecase::{
AdminPoolStatus, DefaultAdminUsecase, QueryPoolStatusRequest, QueryServerInfoRequest,
};
use crate::app::object_usecase::DefaultObjectUsecase;
use crate::runtime_sources as root_runtime_sources;
pub(crate) use crate::runtime_sources::{
AppContext, current_action_credentials, current_boot_time, current_bucket_metadata_handle, current_bucket_monitor_handle,
current_daily_tier_stats, current_deployment_id, current_endpoints_handle, current_iam_handle,
current_kms_runtime_service_manager, current_notification_system_for_context, current_object_store_handle_for_context,
current_oidc_handle, current_or_init_kms_runtime_service_manager, current_outbound_tls_generation,
current_outbound_tls_state, current_ready_iam_handle, current_region, current_replication_pool_handle,
current_replication_stats_handle, current_runtime_port, current_scanner_metrics_report, current_server_config_for_context,
current_tier_config_handle, current_token_signing_key, publish_server_config, publish_storage_class_config,
current_deployment_id, current_endpoints_handle, current_iam_handle, current_kms_runtime_service_manager,
current_notification_system_for_context, current_object_store_handle_for_context, current_oidc_handle,
current_ready_iam_handle, current_region, current_replication_pool_handle, current_replication_stats_handle,
current_server_config_for_context, current_token_signing_key,
};
use rustfs_config::server_config::Config;
use rustfs_kms::KmsServiceManager;
use rustfs_tls_runtime::{GlobalPublishedOutboundTlsState, TlsGeneration};
use std::sync::Arc;
#[cfg(test)]
pub(crate) use crate::runtime_sources::set_test_outbound_tls_generation;
use std::sync::atomic::{AtomicU64, Ordering};
use tokio::sync::RwLock;
pub(crate) fn default_admin_usecase() -> DefaultAdminUsecase {
DefaultAdminUsecase::from_global()
@@ -58,3 +61,71 @@ pub(crate) fn current_server_config() -> Option<Config> {
let context = current_app_context();
current_server_config_for_context(context.as_deref())
}
pub(crate) fn current_or_init_kms_runtime_service_manager() -> Arc<KmsServiceManager> {
root_runtime_sources::current_or_init_kms_runtime_service_manager()
.unwrap_or_else(rustfs_kms::init_global_kms_service_manager)
}
#[cfg(test)]
static TEST_OUTBOUND_TLS_GENERATION: AtomicU64 = AtomicU64::new(0);
#[cfg(test)]
pub(crate) fn set_test_outbound_tls_generation(generation: u64) {
root_runtime_sources::set_test_outbound_tls_generation(generation);
TEST_OUTBOUND_TLS_GENERATION.store(generation, Ordering::Relaxed);
}
pub(crate) fn current_outbound_tls_generation() -> TlsGeneration {
root_runtime_sources::current_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) async fn current_outbound_tls_state() -> GlobalPublishedOutboundTlsState {
if let Some(state) = root_runtime_sources::current_outbound_tls_state().await {
return state;
}
root_runtime_sources::fallback_outbound_tls_runtime_interface().state().await
}
pub(crate) fn current_daily_tier_stats() -> DailyAllTierStats {
root_runtime_sources::current_daily_tier_stats().unwrap_or_default()
}
pub(crate) fn current_runtime_port() -> u16 {
root_runtime_sources::current_runtime_port().unwrap_or(rustfs_config::DEFAULT_PORT)
}
pub(crate) async fn current_scanner_metrics_report() -> ScannerMetricsReport {
if let Some(report) = root_runtime_sources::current_scanner_metrics_report().await {
return report;
}
root_runtime_sources::fallback_scanner_metrics_interface().report().await
}
pub(crate) fn current_tier_config_handle() -> Arc<RwLock<TierConfigMgr>> {
root_runtime_sources::current_tier_config_handle().unwrap_or_else(TierConfigMgr::new)
}
pub(crate) fn publish_server_config(config: Config) {
if !root_runtime_sources::publish_server_config(config.clone()) {
root_runtime_sources::fallback_server_config_interface().set(config);
}
}
pub(crate) fn publish_storage_class_config(config: StorageClassConfig) {
if !root_runtime_sources::publish_storage_class_config(config.clone()) {
root_runtime_sources::fallback_storage_class_interface().set(config);
}
}
+9
View File
@@ -110,6 +110,15 @@ pub(crate) type TierConfig = ecstore_tier::tier_config::TierConfig;
pub(crate) type TierCreds = ecstore_tier::tier_admin::TierCreds;
pub(crate) type TierType = ecstore_tier::tier_config::TierType;
pub(crate) mod runtime_sources {
pub(crate) type DailyAllTierStats = super::DailyAllTierStats;
pub(crate) type ECStore = super::ECStore;
pub(crate) type NotificationSys = super::NotificationSys;
pub(crate) type ScannerMetricsReport = rustfs_common::metrics::ScannerMetricsReport;
pub(crate) type StorageClassConfig = crate::storage::storage_api::ecstore_config::storageclass::Config;
pub(crate) type TierConfigMgr = crate::storage::storage_api::TierConfigMgr;
}
#[cfg(test)]
pub(crate) type Endpoint = ecstore_disk::endpoint::Endpoint;
#[cfg(test)]
+40 -7
View File
@@ -12,15 +12,48 @@
// See the License for the specific language governing permissions and
// limitations under the License.
pub(crate) use crate::runtime_sources::{
AppContext, current_encryption_service, current_endpoints_handle, current_expiry_state_handle, current_notification_system,
current_notify_interface_for_context, current_object_store_handle_for_context, current_s3select_db,
};
use std::sync::Arc;
use crate::app::storage_api::runtime_sources::ExpiryState;
#[cfg(test)]
pub(crate) use crate::runtime_sources::current_tier_config_handle;
use crate::app::storage_api::runtime_sources::TierConfigMgr;
use crate::runtime_sources as root_runtime_sources;
pub(crate) use crate::runtime_sources::{
AppContext, current_encryption_service, current_endpoints_handle, current_notification_system,
current_object_store_handle_for_context,
};
use rustfs_s3select_api::{QueryResult, server::dbms::DatabaseManagerSystem};
use s3s::dto::SelectObjectContentInput;
use std::sync::Arc;
use tokio::sync::RwLock;
pub(crate) fn current_app_context() -> Option<Arc<AppContext>> {
crate::runtime_sources::current_app_context()
}
pub(crate) fn current_notify_interface_for_context(
app_context: Option<&AppContext>,
) -> Arc<dyn root_runtime_sources::NotifyInterface> {
root_runtime_sources::current_notify_interface_for_context(app_context)
.unwrap_or_else(root_runtime_sources::fallback_notify_interface)
}
pub(crate) async fn current_s3select_db(
input: SelectObjectContentInput,
enable_debug: bool,
) -> QueryResult<Arc<dyn DatabaseManagerSystem + Send + Sync>> {
if let Some(result) = root_runtime_sources::current_s3select_db(input.clone(), enable_debug).await {
return result;
}
root_runtime_sources::fallback_s3select_db_interface()
.get(input, enable_debug)
.await
}
pub(crate) fn current_expiry_state_handle() -> Arc<RwLock<ExpiryState>> {
root_runtime_sources::current_expiry_state_handle().unwrap_or_else(ExpiryState::new)
}
#[cfg(test)]
pub(crate) fn current_tier_config_handle() -> Arc<RwLock<TierConfigMgr>> {
root_runtime_sources::current_tier_config_handle().unwrap_or_else(TierConfigMgr::new)
}
+6
View File
@@ -211,6 +211,12 @@ pub(crate) mod runtime {
}
}
pub(crate) mod runtime_sources {
pub(crate) type ExpiryState = super::runtime::ExpiryState;
#[cfg(test)]
pub(crate) type TierConfigMgr = super::runtime::TierConfigMgr;
}
pub(crate) mod access {
pub(crate) use crate::storage::storage_api::access_consumer::{
PostObjectRequestMarker, ReqInfo, authorize_request, has_bypass_governance_header, req_info_mut, req_info_ref,
+2 -2
View File
@@ -546,7 +546,7 @@ fn collect_config_info_json() -> ConfigInfoJson {
let workload_profile = {
use super::workload_profiles::is_buffer_profile_enabled;
if is_buffer_profile_enabled() {
let config = current_buffer_config();
let config = current_buffer_config().unwrap_or_default();
let profile = config.workload_profile();
let buffer_config = profile.config();
Some(WorkloadProfileJson {
@@ -870,7 +870,7 @@ fn get_workload_profile_info() -> String {
return "| Workload Profile | (disabled) |".to_string();
}
let config = current_buffer_config();
let config = current_buffer_config().unwrap_or_default();
let profile = config.workload_profile();
let name = config.workload_name();
let buffer_config = profile.config();
+2 -1
View File
@@ -12,8 +12,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use crate::runtime_sources::{current_notify_interface, current_region};
use crate::runtime_sources::current_region;
use crate::server::ShutdownHandle;
use crate::server::runtime_sources::current_notify_interface;
use crate::storage_api::startup::init::{
get_bucket_notification_config, process_lambda_configurations, process_queue_configurations, process_topic_configurations,
};
+23 -121
View File
@@ -13,144 +13,46 @@
// limitations under the License.
use crate::app::context;
use crate::app::storage_api::runtime::{ScannerMetricsReport, StorageClassConfig};
use crate::config::RustFSBufferConfig;
use crate::storage_api::server::runtime_sources::{DailyAllTierStats, ExpiryState, TierConfigMgr};
use rustfs_config::server_config::Config;
use rustfs_io_metrics::{PerformanceMetrics, internode_metrics::InternodeMetrics};
use rustfs_kms::KmsServiceManager;
use rustfs_s3select_api::{QueryResult, server::dbms::DatabaseManagerSystem};
use rustfs_tls_runtime::TlsGeneration;
use s3s::dto::SelectObjectContentInput;
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, resolve_action_credentials as current_action_credentials,
AppContext, NotifyInterface, default_notify_interface as fallback_notify_interface,
default_outbound_tls_runtime_interface as fallback_outbound_tls_runtime_interface,
default_s3select_db_interface as fallback_s3select_db_interface,
default_scanner_metrics_interface as fallback_scanner_metrics_interface,
default_server_config_interface as fallback_server_config_interface,
default_storage_class_interface as fallback_storage_class_interface, 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_deployment_id as current_deployment_id,
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_encryption_service as current_encryption_service, resolve_endpoints_handle as current_endpoints_handle,
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_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_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,
resolve_notify_interface_for_context as current_notify_interface_for_context,
resolve_object_store_handle as current_object_store_handle,
resolve_object_store_handle_for_context as current_object_store_handle_for_context,
resolve_oidc_handle as current_oidc_handle, resolve_ready_iam_handle as current_ready_iam_handle,
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_region as current_region, resolve_replication_pool_handle as current_replication_pool_handle,
resolve_replication_stats_handle as current_replication_stats_handle, 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,
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,
};
#[cfg(test)]
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_or_init_kms_runtime_service_manager() -> Arc<KmsServiceManager> {
context::resolve_or_init_kms_runtime_service_manager().unwrap_or_else(rustfs_kms::init_global_kms_service_manager)
}
pub(crate) fn current_notify_interface() -> Arc<dyn NotifyInterface> {
context::resolve_notify_interface().unwrap_or_else(context::default_notify_interface)
}
pub(crate) fn current_notify_interface_for_context(context: Option<&AppContext>) -> Arc<dyn NotifyInterface> {
context::resolve_notify_interface_for_context(context).unwrap_or_else(context::default_notify_interface)
}
pub(crate) fn current_outbound_tls_generation() -> TlsGeneration {
context::resolve_outbound_tls_generation().unwrap_or_else(empty_outbound_tls_generation)
}
pub(crate) async fn current_outbound_tls_state() -> rustfs_tls_runtime::GlobalPublishedOutboundTlsState {
if let Some(state) = context::resolve_outbound_tls_state().await {
return state;
}
context::default_outbound_tls_runtime_interface().state().await
}
#[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_scanner_metrics_report() -> ScannerMetricsReport {
if let Some(report) = context::resolve_scanner_metrics_report().await {
return report;
}
context::default_scanner_metrics_interface().report().await
}
pub(crate) async fn current_s3select_db(
input: SelectObjectContentInput,
enable_debug: bool,
) -> QueryResult<Arc<dyn DatabaseManagerSystem + Send + Sync>> {
if let Some(result) = context::resolve_s3select_db(input.clone(), enable_debug).await {
return result;
}
context::default_s3select_db_interface().get(input, enable_debug).await
}
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()
}
pub(crate) fn publish_server_config(config: Config) {
if !context::publish_server_config(config.clone()) {
context::default_server_config_interface().set(config);
}
}
pub(crate) fn publish_storage_class_config(config: StorageClassConfig) {
if !context::publish_storage_class_config(config.clone()) {
context::default_storage_class_interface().set(config);
}
}
+1 -1
View File
@@ -28,7 +28,7 @@ pub(crate) fn current_server_config() -> Option<rustfs_config::server_config::Co
}
pub(crate) fn current_notify_interface() -> Arc<dyn NotifyInterface> {
crate::runtime_sources::current_notify_interface()
crate::runtime_sources::current_notify_interface().unwrap_or_else(crate::runtime_sources::fallback_notify_interface)
}
pub(crate) fn current_object_store_handle() -> Option<Arc<ECStore>> {
+3 -1
View File
@@ -91,7 +91,9 @@ pub(crate) fn init_tls_metrics() {
}
pub(crate) fn current_outbound_tls_generation() -> u64 {
runtime_current_outbound_tls_generation().0
runtime_current_outbound_tls_generation()
.map(|generation| generation.0)
.unwrap_or_default()
}
pub(crate) async fn publish_outbound_tls_state(generation: TlsGeneration, outbound: &OutboundTlsMaterial) {
+5 -5
View File
@@ -37,15 +37,15 @@ pub(crate) fn current_object_store_handle_for_context(context: Option<&AppContex
}
pub(crate) fn current_buffer_config() -> RustFSBufferConfig {
root_runtime_sources::current_buffer_config()
root_runtime_sources::current_buffer_config().unwrap_or_default()
}
pub(crate) fn current_internode_metrics() -> Arc<InternodeMetrics> {
root_runtime_sources::current_internode_metrics()
root_runtime_sources::current_internode_metrics().unwrap_or_else(|| Arc::new(InternodeMetrics::default()))
}
pub(crate) async fn current_local_node_name() -> String {
root_runtime_sources::current_local_node_name().await
root_runtime_sources::current_local_node_name().await.unwrap_or_default()
}
pub(crate) fn current_action_credentials() -> Option<Credentials> {
@@ -53,11 +53,11 @@ pub(crate) fn current_action_credentials() -> Option<Credentials> {
}
pub(crate) fn current_notify_interface() -> Arc<dyn root_runtime_sources::NotifyInterface> {
root_runtime_sources::current_notify_interface()
root_runtime_sources::current_notify_interface().unwrap_or_else(root_runtime_sources::fallback_notify_interface)
}
pub(crate) fn current_performance_metrics() -> Arc<PerformanceMetrics> {
root_runtime_sources::current_performance_metrics()
root_runtime_sources::current_performance_metrics().unwrap_or_else(|| Arc::new(PerformanceMetrics::new()))
}
pub(crate) async fn current_encryption_service() -> Option<Arc<ObjectEncryptionService>> {
+1 -3
View File
@@ -142,9 +142,7 @@ pub(crate) mod server {
}
pub(crate) mod runtime_sources {
pub(crate) use crate::storage::storage_api::{
DailyAllTierStats, ECStore, EndpointServerPools, ExpiryState, TierConfigMgr,
};
pub(crate) use crate::storage::storage_api::{ECStore, EndpointServerPools};
}
}