From 1a549d78caf923d3ba0919e77af163ff1dc4c612 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=89=E6=AD=A3=E8=B6=85?= Date: Thu, 26 Feb 2026 09:18:07 +0800 Subject: [PATCH] refactor(storage): converge put-object quota metadata context (#1963) --- rustfs/src/storage/objects/put_object.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/rustfs/src/storage/objects/put_object.rs b/rustfs/src/storage/objects/put_object.rs index 9a4a986fd..101d677ae 100644 --- a/rustfs/src/storage/objects/put_object.rs +++ b/rustfs/src/storage/objects/put_object.rs @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +use crate::app::context::{default_bucket_metadata_interface, get_global_app_context}; use crate::error::ApiError; use crate::storage::concurrency::get_concurrency_manager; use crate::storage::helper::OperationHelper; @@ -45,10 +46,18 @@ use s3s::dto::{ChecksumAlgorithm, ETag, PutObjectInput, PutObjectOutput}; use s3s::{S3Error, S3ErrorCode, S3Request, S3Response, S3Result, s3_error}; use std::collections::HashMap; use std::path::Path; +use std::sync::Arc; use tokio_tar::Archive; +use tokio::sync::RwLock; use tokio_util::io::StreamReader; use tracing::{debug, error, instrument, warn}; +fn bucket_metadata_for_quota() -> Option>> { + get_global_app_context() + .and_then(|context| context.bucket_metadata().handle()) + .or_else(|| default_bucket_metadata_interface().handle()) +} + impl Objects { #[instrument(level = "debug", skip(self, req))] pub async fn put_object(&self, req: S3Request) -> S3Result> { @@ -135,9 +144,9 @@ impl Objects { // check quota for put operation let mut quota_usage_calculated = false; if let Some(size) = content_length - && let Some(metadata_sys) = rustfs_ecstore::bucket::metadata_sys::GLOBAL_BucketMetadataSys.get() + && let Some(metadata_sys) = bucket_metadata_for_quota() { - let quota_checker = QuotaChecker::new(metadata_sys.clone()); + let quota_checker = QuotaChecker::new(metadata_sys); match quota_checker .check_quota(&bucket, QuotaOperation::PutObject, size as u64)