refactor(storage): converge put-object quota metadata context (#1963)

This commit is contained in:
安正超
2026-02-26 09:18:07 +08:00
committed by GitHub
parent 7909a57634
commit 1a549d78ca
+11 -2
View File
@@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
use crate::app::context::{default_bucket_metadata_interface, get_global_app_context};
use crate::error::ApiError; use crate::error::ApiError;
use crate::storage::concurrency::get_concurrency_manager; use crate::storage::concurrency::get_concurrency_manager;
use crate::storage::helper::OperationHelper; 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 s3s::{S3Error, S3ErrorCode, S3Request, S3Response, S3Result, s3_error};
use std::collections::HashMap; use std::collections::HashMap;
use std::path::Path; use std::path::Path;
use std::sync::Arc;
use tokio_tar::Archive; use tokio_tar::Archive;
use tokio::sync::RwLock;
use tokio_util::io::StreamReader; use tokio_util::io::StreamReader;
use tracing::{debug, error, instrument, warn}; use tracing::{debug, error, instrument, warn};
fn bucket_metadata_for_quota() -> Option<Arc<RwLock<metadata_sys::BucketMetadataSys>>> {
get_global_app_context()
.and_then(|context| context.bucket_metadata().handle())
.or_else(|| default_bucket_metadata_interface().handle())
}
impl Objects { impl Objects {
#[instrument(level = "debug", skip(self, req))] #[instrument(level = "debug", skip(self, req))]
pub async fn put_object(&self, req: S3Request<PutObjectInput>) -> S3Result<S3Response<PutObjectOutput>> { pub async fn put_object(&self, req: S3Request<PutObjectInput>) -> S3Result<S3Response<PutObjectOutput>> {
@@ -135,9 +144,9 @@ impl Objects {
// check quota for put operation // check quota for put operation
let mut quota_usage_calculated = false; let mut quota_usage_calculated = false;
if let Some(size) = content_length 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 match quota_checker
.check_quota(&bucket, QuotaOperation::PutObject, size as u64) .check_quota(&bucket, QuotaOperation::PutObject, size as u64)