mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-07 22:03:14 +00:00
refactor: consolidate app object store fallback (#3445)
This commit is contained in:
@@ -14,7 +14,7 @@
|
||||
|
||||
//! Admin application use-case contracts.
|
||||
|
||||
use crate::app::context::{AppContext, get_global_app_context};
|
||||
use crate::app::context::{AppContext, get_global_app_context, resolve_object_store_handle_for_context};
|
||||
use crate::capacity::resolve_admin_used_capacity;
|
||||
use crate::error::ApiError;
|
||||
use crate::server::{DependencyReadiness, collect_dependency_readiness as collect_runtime_dependency_readiness};
|
||||
@@ -22,7 +22,6 @@ use rustfs_data_usage::DataUsageInfo;
|
||||
use rustfs_ecstore::admin_server_info::get_server_info;
|
||||
use rustfs_ecstore::data_usage::{apply_bucket_usage_memory_overlay, load_data_usage_from_backend};
|
||||
use rustfs_ecstore::endpoints::EndpointServerPools;
|
||||
use rustfs_ecstore::new_object_layer_fn;
|
||||
use rustfs_ecstore::pools::{PoolDecommissionInfo, PoolStatus, get_total_usable_capacity, get_total_usable_capacity_free};
|
||||
use rustfs_ecstore::store::ECStore;
|
||||
use rustfs_madmin::{InfoMessage, StorageInfo};
|
||||
@@ -104,10 +103,7 @@ impl DefaultAdminUsecase {
|
||||
}
|
||||
|
||||
fn object_store(&self) -> Option<Arc<ECStore>> {
|
||||
self.context
|
||||
.as_ref()
|
||||
.map(|context| context.object_store())
|
||||
.or_else(new_object_layer_fn)
|
||||
resolve_object_store_handle_for_context(self.context.as_deref())
|
||||
}
|
||||
|
||||
fn app_error(code: S3ErrorCode, message: impl Into<String>) -> ApiError {
|
||||
|
||||
@@ -17,7 +17,9 @@
|
||||
use crate::admin::handlers::site_replication::{
|
||||
site_replication_bucket_meta_hook, site_replication_delete_bucket_hook, site_replication_make_bucket_hook,
|
||||
};
|
||||
use crate::app::context::{AppContext, default_notify_interface, get_global_app_context};
|
||||
use crate::app::context::{
|
||||
AppContext, default_notify_interface, get_global_app_context, resolve_object_store_handle_for_context,
|
||||
};
|
||||
use crate::auth::get_condition_values_with_client_info;
|
||||
use crate::error::ApiError;
|
||||
use crate::server::RemoteAddr;
|
||||
@@ -53,7 +55,6 @@ use rustfs_ecstore::bucket::{
|
||||
};
|
||||
use rustfs_ecstore::client::object_api_utils::to_s3s_etag;
|
||||
use rustfs_ecstore::error::StorageError;
|
||||
use rustfs_ecstore::new_object_layer_fn;
|
||||
use rustfs_ecstore::notification_sys::get_global_notification_sys;
|
||||
use rustfs_ecstore::store::ECStore;
|
||||
use rustfs_ecstore::store_api::{BucketOperations, ListObjectVersionsInfo, ListObjectsV2Info, ListOperations, ObjectInfo};
|
||||
@@ -740,10 +741,7 @@ impl DefaultBucketUsecase {
|
||||
}
|
||||
|
||||
fn object_store(&self) -> Option<Arc<ECStore>> {
|
||||
self.context
|
||||
.as_ref()
|
||||
.map(|context| context.object_store())
|
||||
.or_else(new_object_layer_fn)
|
||||
resolve_object_store_handle_for_context(self.context.as_deref())
|
||||
}
|
||||
|
||||
#[instrument(
|
||||
|
||||
@@ -41,7 +41,13 @@ pub fn resolve_bucket_metadata_handle() -> Option<Arc<RwLock<BucketMetadataSys>>
|
||||
|
||||
/// Resolve object store handle using AppContext-first precedence.
|
||||
pub fn resolve_object_store_handle() -> Option<Arc<ECStore>> {
|
||||
resolve_object_store_handle_with(get_global_app_context(), new_object_layer_fn)
|
||||
let context = get_global_app_context();
|
||||
resolve_object_store_handle_for_context(context.as_deref())
|
||||
}
|
||||
|
||||
/// Resolve object store handle using an explicit AppContext, falling back to the legacy global object layer.
|
||||
pub fn resolve_object_store_handle_for_context(context: Option<&AppContext>) -> Option<Arc<ECStore>> {
|
||||
context.map(|context| context.object_store()).or_else(new_object_layer_fn)
|
||||
}
|
||||
|
||||
/// Resolve endpoints using AppContext-first precedence.
|
||||
@@ -77,6 +83,7 @@ fn resolve_bucket_metadata_handle_with(
|
||||
.or_else(fallback)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
fn resolve_object_store_handle_with(
|
||||
context: Option<Arc<AppContext>>,
|
||||
fallback: impl FnOnce() -> Option<Arc<ECStore>>,
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
//! Multipart application use-case contracts.
|
||||
|
||||
use crate::app::context::{AppContext, get_global_app_context};
|
||||
use crate::app::context::{AppContext, get_global_app_context, resolve_object_store_handle_for_context};
|
||||
use crate::app::object_usecase::{build_put_like_object_lock_metadata, validate_existing_object_lock_for_write};
|
||||
use crate::capacity::record_capacity_write;
|
||||
use crate::error::ApiError;
|
||||
@@ -48,7 +48,6 @@ use rustfs_ecstore::bucket::{
|
||||
use rustfs_ecstore::client::object_api_utils::to_s3s_etag;
|
||||
use rustfs_ecstore::compress::is_disk_compressible;
|
||||
use rustfs_ecstore::error::{StorageError, is_err_object_not_found, is_err_version_not_found};
|
||||
use rustfs_ecstore::new_object_layer_fn;
|
||||
#[cfg(test)]
|
||||
use rustfs_ecstore::rio::{DecryptReader, EncryptReader, HardLimitReader, boxed_reader, wrap_reader};
|
||||
use rustfs_ecstore::rio::{HashReader, WritePlan};
|
||||
@@ -230,10 +229,7 @@ impl DefaultMultipartUsecase {
|
||||
}
|
||||
|
||||
fn object_store(&self) -> Option<Arc<ECStore>> {
|
||||
self.context
|
||||
.as_ref()
|
||||
.map(|context| context.object_store())
|
||||
.or_else(new_object_layer_fn)
|
||||
resolve_object_store_handle_for_context(self.context.as_deref())
|
||||
}
|
||||
|
||||
#[instrument(level = "debug", skip(self))]
|
||||
|
||||
@@ -14,7 +14,9 @@
|
||||
|
||||
//! Object application use-case contracts.
|
||||
|
||||
use crate::app::context::{AppContext, default_notify_interface, get_global_app_context};
|
||||
use crate::app::context::{
|
||||
AppContext, default_notify_interface, get_global_app_context, resolve_object_store_handle_for_context,
|
||||
};
|
||||
use crate::config::RustFSBufferConfig;
|
||||
use crate::delete_tail_activity::{DeleteTailActivityGuard, DeleteTailStage};
|
||||
use crate::error::ApiError;
|
||||
@@ -73,7 +75,6 @@ use rustfs_ecstore::compress::{MIN_DISK_COMPRESSIBLE_SIZE, is_disk_compressible}
|
||||
use rustfs_ecstore::config::storageclass;
|
||||
use rustfs_ecstore::disk::{error::DiskError, error_reduce::is_all_buckets_not_found};
|
||||
use rustfs_ecstore::error::{StorageError, is_err_bucket_not_found, is_err_object_not_found, is_err_version_not_found};
|
||||
use rustfs_ecstore::new_object_layer_fn;
|
||||
use rustfs_ecstore::rio::{DynReader, HashReader, WritePlan, wrap_reader};
|
||||
use rustfs_ecstore::set_disk::{get_lock_acquire_timeout, is_valid_storage_class};
|
||||
use rustfs_ecstore::store::ECStore;
|
||||
@@ -1158,10 +1159,7 @@ impl DefaultObjectUsecase {
|
||||
}
|
||||
|
||||
fn object_store(&self) -> Option<Arc<ECStore>> {
|
||||
self.context
|
||||
.as_ref()
|
||||
.map(|context| context.object_store())
|
||||
.or_else(new_object_layer_fn)
|
||||
resolve_object_store_handle_for_context(self.context.as_deref())
|
||||
}
|
||||
|
||||
fn base_buffer_size(&self) -> usize {
|
||||
|
||||
Reference in New Issue
Block a user