mirror of
https://github.com/rustfs/rustfs.git
synced 2026-07-26 16:28:15 +00:00
refactor(app): route buffer config through AppContext (#1964)
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
//! for storage, IAM, and KMS handles.
|
||||
#![allow(dead_code)]
|
||||
|
||||
use crate::config::workload_profiles::{RustFSBufferConfig, get_global_buffer_config};
|
||||
use async_trait::async_trait;
|
||||
use rustfs_ecstore::GLOBAL_Endpoints;
|
||||
use rustfs_ecstore::bucket::metadata_sys::{BucketMetadataSys, GLOBAL_BucketMetadataSys};
|
||||
@@ -83,6 +84,11 @@ pub trait ServerConfigInterface: Send + Sync {
|
||||
fn get(&self) -> Option<Config>;
|
||||
}
|
||||
|
||||
/// Buffer profile config interface for application-layer use-cases.
|
||||
pub trait BufferConfigInterface: Send + Sync {
|
||||
fn get(&self) -> RustFSBufferConfig;
|
||||
}
|
||||
|
||||
/// Default IAM interface adapter.
|
||||
pub struct IamHandle {
|
||||
iam: Arc<IamSys<ObjectStore>>,
|
||||
@@ -195,6 +201,16 @@ impl ServerConfigInterface for ServerConfigHandle {
|
||||
}
|
||||
}
|
||||
|
||||
/// Default buffer profile config interface adapter.
|
||||
#[derive(Default)]
|
||||
pub struct BufferConfigHandle;
|
||||
|
||||
impl BufferConfigInterface for BufferConfigHandle {
|
||||
fn get(&self) -> RustFSBufferConfig {
|
||||
get_global_buffer_config().clone()
|
||||
}
|
||||
}
|
||||
|
||||
/// Application-layer context with explicit dependencies.
|
||||
#[derive(Clone)]
|
||||
pub struct AppContext {
|
||||
@@ -207,6 +223,7 @@ pub struct AppContext {
|
||||
region: Arc<dyn RegionInterface>,
|
||||
tier_config: Arc<dyn TierConfigInterface>,
|
||||
server_config: Arc<dyn ServerConfigInterface>,
|
||||
buffer_config: Arc<dyn BufferConfigInterface>,
|
||||
}
|
||||
|
||||
impl AppContext {
|
||||
@@ -221,6 +238,7 @@ impl AppContext {
|
||||
region: default_region_interface(),
|
||||
tier_config: default_tier_config_interface(),
|
||||
server_config: default_server_config_interface(),
|
||||
buffer_config: default_buffer_config_interface(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -267,6 +285,10 @@ impl AppContext {
|
||||
pub fn server_config(&self) -> Arc<dyn ServerConfigInterface> {
|
||||
self.server_config.clone()
|
||||
}
|
||||
|
||||
pub fn buffer_config(&self) -> Arc<dyn BufferConfigInterface> {
|
||||
self.buffer_config.clone()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn default_notify_interface() -> Arc<dyn NotifyInterface> {
|
||||
@@ -293,6 +315,10 @@ pub fn default_server_config_interface() -> Arc<dyn ServerConfigInterface> {
|
||||
Arc::new(ServerConfigHandle)
|
||||
}
|
||||
|
||||
pub fn default_buffer_config_interface() -> Arc<dyn BufferConfigInterface> {
|
||||
Arc::new(BufferConfigHandle)
|
||||
}
|
||||
|
||||
static GLOBAL_APP_CONTEXT: OnceLock<Arc<AppContext>> = OnceLock::new();
|
||||
|
||||
/// Initialize global application context once and return the canonical instance.
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
#![allow(dead_code)]
|
||||
|
||||
use crate::app::context::{AppContext, default_notify_interface, get_global_app_context};
|
||||
use crate::config::workload_profiles::get_global_buffer_config;
|
||||
use crate::config::workload_profiles::RustFSBufferConfig;
|
||||
use crate::error::ApiError;
|
||||
use crate::storage::access::{ReqInfo, authorize_request, has_bypass_governance_header};
|
||||
use crate::storage::concurrency::{
|
||||
@@ -204,6 +204,14 @@ impl DefaultObjectUsecase {
|
||||
self.context.as_ref().and_then(|context| context.bucket_metadata().handle())
|
||||
}
|
||||
|
||||
fn base_buffer_size(&self) -> usize {
|
||||
self.context
|
||||
.clone()
|
||||
.or_else(get_global_app_context)
|
||||
.map(|context| context.buffer_config().get().base_config.default_unknown)
|
||||
.unwrap_or_else(|| RustFSBufferConfig::default().base_config.default_unknown)
|
||||
}
|
||||
|
||||
#[instrument(level = "debug", skip(self, fs, req))]
|
||||
pub async fn execute_put_object(&self, fs: &FS, req: S3Request<PutObjectInput>) -> S3Result<S3Response<PutObjectOutput>> {
|
||||
if let Some(context) = &self.context {
|
||||
@@ -1194,7 +1202,7 @@ impl DefaultObjectUsecase {
|
||||
// Calculate adaptive I/O strategy from permit wait time
|
||||
// This adjusts buffer sizes, read-ahead, and caching behavior based on load
|
||||
// Use 256KB as the base buffer size for strategy calculation
|
||||
let base_buffer_size = get_global_buffer_config().base_config.default_unknown;
|
||||
let base_buffer_size = self.base_buffer_size();
|
||||
let io_strategy = manager.calculate_io_strategy(permit_wait_duration, base_buffer_size);
|
||||
|
||||
// Record detailed I/O metrics for monitoring
|
||||
|
||||
Reference in New Issue
Block a user