fix(ecstore): fence restore final commit by operation id (#5062)

Refs rustfs/backlog#1356

Co-authored-by: heihutu <heihutu@gmail.com>
This commit is contained in:
houseme
2026-07-20 20:08:55 +08:00
committed by GitHub
parent b44e82fef1
commit 35f3599992
4 changed files with 481 additions and 17 deletions
+34
View File
@@ -210,6 +210,40 @@ pub(super) fn require_restore_operation_id(metadata: &HashMap<String, String>, e
}
}
pub(super) fn restore_commit_operation_id_from_metadata(metadata: &HashMap<String, String>) -> Result<Option<Uuid>> {
if !metadata.contains_key(X_AMZ_RESTORE.as_str()) {
return Ok(None);
}
restore_operation_id_from_metadata(metadata)
}
impl SetDisks {
pub(super) async fn require_current_restore_operation_id(
&self,
bucket: &str,
object: &str,
opts: &ObjectOptions,
expected: Option<Uuid>,
mode: &str,
) -> Result<()> {
let Some(expected) = expected else {
return Ok(());
};
let read_opts = ObjectOptions {
version_id: opts.version_id.clone(),
versioned: opts.versioned,
version_suspended: opts.version_suspended,
no_lock: true,
..Default::default()
};
let (current, _, _) = self.get_object_fileinfo(bucket, object, &read_opts, true, false).await?;
restore_operation_id_from_metadata(&current.metadata)?
.filter(|actual| *actual == expected)
.ok_or_else(|| Error::other(format!("restore operation id changed before {mode}: expected {expected}")))?;
Ok(())
}
}
type ListObjectsV2Info = StorageListObjectsV2Info<ObjectInfo>;
type ListObjectVersionsInfo = StorageListObjectVersionsInfo<ObjectInfo>;
type ObjectInfoOrErr = StorageObjectInfoOrErr<ObjectInfo, Error>;