mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-13 08:36:54 +00:00
perf(get): reduce request entry allocations (#6029)
Co-authored-by: heihutu <heihutu@gmail.com>
This commit is contained in:
@@ -1585,7 +1585,7 @@ impl ECStore {
|
||||
) -> Result<GetObjectReader> {
|
||||
check_get_obj_args(bucket, object)?;
|
||||
|
||||
let object = encode_dir_object(object);
|
||||
let object = rustfs_utils::path::encode_dir_object_ref(object);
|
||||
let mut opts = opts.clone();
|
||||
let read_lock_guard = self
|
||||
.acquire_object_read_lock_if_needed("get_object", bucket, &object, &mut opts)
|
||||
@@ -1593,14 +1593,14 @@ impl ECStore {
|
||||
|
||||
let reader = if self.single_pool() {
|
||||
self.pools[0]
|
||||
.get_object_reader(bucket, object.as_str(), range, h, &opts)
|
||||
.get_object_reader(bucket, object.as_ref(), range, h, &opts)
|
||||
.await?
|
||||
} else {
|
||||
let (_, idx) = self
|
||||
.get_latest_accessible_object_info_with_idx(bucket, &object, &opts)
|
||||
.await?;
|
||||
self.pools[idx]
|
||||
.get_object_reader(bucket, object.as_str(), range, h, &opts)
|
||||
.get_object_reader(bucket, object.as_ref(), range, h, &opts)
|
||||
.await?
|
||||
};
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use std::borrow::Cow;
|
||||
use std::path::Component;
|
||||
use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
@@ -44,14 +45,19 @@ pub fn has_suffix(s: &str, suffix: &str) -> bool {
|
||||
/// If the object name ends with a slash, it is considered a directory object.
|
||||
/// The trailing slash is removed and `GLOBAL_DIR_SUFFIX` is appended.
|
||||
/// If it does not end with a slash, the name is returned as is.
|
||||
pub fn encode_dir_object(object: &str) -> String {
|
||||
pub fn encode_dir_object_ref(object: &str) -> Cow<'_, str> {
|
||||
if has_suffix(object, SLASH_SEPARATOR) {
|
||||
format!("{}{}", object.trim_end_matches(SLASH_SEPARATOR), GLOBAL_DIR_SUFFIX)
|
||||
Cow::Owned(format!("{}{}", object.trim_end_matches(SLASH_SEPARATOR), GLOBAL_DIR_SUFFIX))
|
||||
} else {
|
||||
object.to_string()
|
||||
Cow::Borrowed(object)
|
||||
}
|
||||
}
|
||||
|
||||
/// Owned compatibility wrapper for callers that retain or mutate the encoded name.
|
||||
pub fn encode_dir_object(object: &str) -> String {
|
||||
encode_dir_object_ref(object).into_owned()
|
||||
}
|
||||
|
||||
/// Checks if the given object name represents a directory object.
|
||||
///
|
||||
/// Returns true if the object name ends with `GLOBAL_DIR_SUFFIX`.
|
||||
@@ -602,6 +608,17 @@ mod tests {
|
||||
use super::*;
|
||||
use proptest::prelude::*;
|
||||
|
||||
#[test]
|
||||
fn encode_dir_object_ref_borrows_objects_and_encodes_directories() {
|
||||
let object = "prefix/object";
|
||||
let encoded = encode_dir_object_ref(object);
|
||||
assert!(matches!(encoded, Cow::Borrowed(value) if value == object));
|
||||
|
||||
let encoded = encode_dir_object_ref("prefix/directory/");
|
||||
assert!(matches!(encoded, Cow::Owned(ref value) if value == "prefix/directory__XLDIR__"));
|
||||
assert_eq!(encode_dir_object("prefix/directory/"), encoded);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_trim_etag() {
|
||||
// Test with quoted ETag
|
||||
|
||||
Reference in New Issue
Block a user