mirror of
https://github.com/rustfs/rustfs.git
synced 2026-09-04 11:15:39 +00:00
perf(filemeta): phase-1~3 rename_data metadata optimization (#3011)
* chore(perf): harden amd64 profiling benchmark flow * fix(profiling): isolate bench buckets and map protobuf conflict * perf: avoid blocking owned local writes * style: format profile admin handler * docs: clarify observability trace validation * perf: reduce mkdir overhead on local writes * perf: add rename_data meta microbenchmark * perf(filemeta): fast-path data_dir decode in version meta * perf(filemeta): collapse data-dir lookup into one scan * perf(filemeta): reduce scan allocs and refresh meta bench * perf(ecstore): skip mkdir path on read-only open * perf(filemeta): single-pass unshared data-dir scan * perf(filemeta): add two-key inline remove fast path * perf(filemeta): compare remove-two keys by bytes first * bench(ecstore): add remove_two-only micro benchmark * bench(ecstore): stabilize rename_data meta benchmark timing * bench(ecstore): align rename_data path with remove_two * perf(filemeta): avoid uuid string alloc in remove_two * perf(filemeta): add fast-path for empty inline data * perf(filemeta): streamline add_version match branch * perf(filemeta): fast-return remove_key on miss * perf(filemeta): speed up add_version insertion lookup * style(ecstore): normalize formatting in perf-tuning files * refactor(filemeta): unify inline data removal paths
This commit is contained in:
@@ -282,6 +282,11 @@ impl FileMeta {
|
||||
fi.version_id = Some(Uuid::nil());
|
||||
}
|
||||
|
||||
if fi.data.is_none() && self.data.after_version().is_empty() {
|
||||
let version = FileMetaVersion::from(fi);
|
||||
return self.add_version_filemata(version);
|
||||
}
|
||||
|
||||
let version_key = data_key_for_version(fi.version_id);
|
||||
let mut next_data = self.data.clone();
|
||||
|
||||
@@ -317,46 +322,30 @@ impl FileMeta {
|
||||
}
|
||||
|
||||
let vid = version.get_version_id();
|
||||
|
||||
// Match existing version for replace; null version: None and Some(nil) are equivalent
|
||||
let matches = |h: &Option<Uuid>| {
|
||||
let v_null = vid.is_none() || vid == Some(Uuid::nil());
|
||||
let h_null = h.is_none() || *h == Some(Uuid::nil());
|
||||
(v_null && h_null) || (vid == *h)
|
||||
let vid_is_null = vid.is_none() || vid == Some(Uuid::nil());
|
||||
let existing_idx = if vid_is_null {
|
||||
self.versions
|
||||
.iter()
|
||||
.position(|v| v.header.version_id.is_none() || v.header.version_id == Some(Uuid::nil()))
|
||||
} else {
|
||||
self.versions.iter().position(|v| v.header.version_id == vid)
|
||||
};
|
||||
|
||||
if let Some(fidx) = self.versions.iter().position(|v| matches(&v.header.version_id)) {
|
||||
if let Some(fidx) = existing_idx {
|
||||
return self.set_idx(fidx, version);
|
||||
}
|
||||
|
||||
// append placeholder to find insert position
|
||||
let placeholder = FileMetaShallowVersion {
|
||||
header: FileMetaVersionHeader {
|
||||
mod_time: None, // None sorts before any real mod_time
|
||||
..Default::default()
|
||||
},
|
||||
meta: Vec::new(),
|
||||
};
|
||||
self.versions.push(placeholder);
|
||||
|
||||
let mod_time = version.get_mod_time();
|
||||
let new_shallow = FileMetaShallowVersion::try_from(version)?;
|
||||
|
||||
for (idx, exist) in self.versions.iter().enumerate() {
|
||||
let ex_mt = exist.header.mod_time;
|
||||
let insert_here = match (ex_mt, mod_time) {
|
||||
(None, _) => true, // placeholder: always insert before
|
||||
(Some(em), Some(nm)) => em <= nm,
|
||||
(Some(_), None) => false,
|
||||
};
|
||||
if insert_here {
|
||||
self.versions.insert(idx, new_shallow);
|
||||
self.versions.pop(); // remove placeholder
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
self.versions.pop(); // remove placeholder on fallback
|
||||
Err(Error::other("add_version failed"))
|
||||
let insert_pos = match mod_time {
|
||||
Some(nm) => self.versions.partition_point(|exist| match exist.header.mod_time {
|
||||
Some(em) => em > nm,
|
||||
None => false,
|
||||
}),
|
||||
None => self.versions.partition_point(|exist| exist.header.mod_time.is_some()),
|
||||
};
|
||||
self.versions.insert(insert_pos, new_shallow);
|
||||
Ok(())
|
||||
|
||||
// if !ver.valid() {
|
||||
// return Err(Error::other("attempted to add invalid version"));
|
||||
|
||||
Reference in New Issue
Block a user