refactor(replication): centralize object replication state parsing (#4158)

* refactor(replication): centralize object replication state parsing

* fix(replication): gate test-only msgpack import
This commit is contained in:
Zhengchao An
2026-07-02 04:41:54 +08:00
committed by GitHub
parent 2de38d3e5c
commit e05c281176
2 changed files with 34 additions and 49 deletions
+26
View File
@@ -747,6 +747,13 @@ impl ObjectInfo {
}
}
pub fn target_replication_status(&self, arn: &str) -> ReplicationStatusType {
replication_statuses_map(self.replication_status_internal.as_deref().unwrap_or_default())
.get(arn)
.cloned()
.unwrap_or_default()
}
pub fn decrypt_checksums(&self, part: usize, _headers: &HeaderMap) -> Result<(HashMap<String, String>, bool)> {
if part > 0
&& let Some(checksums) = self.parts.iter().find(|p| p.number == part).and_then(|p| p.checksums.clone())
@@ -823,6 +830,25 @@ mod tests {
assert_eq!(state.composite_replication_status(), ReplicationStatusType::Replica);
}
#[test]
fn object_info_replication_helpers_parse_target_status_and_reset_headers() {
let reset_key = rustfs_utils::http::internal_key_rustfs("replication-reset-arn:target-a");
let object = ObjectInfo {
replication_status_internal: Some("arn:target-a=COMPLETED;arn:target-b=FAILED;".to_string()),
version_purge_status_internal: Some("arn:target-a=PENDING;".to_string()),
user_defined: Arc::new(HashMap::from([(reset_key, "reset-id".to_string())])),
..Default::default()
};
let state = object.replication_state();
assert_eq!(object.target_replication_status("arn:target-a"), ReplicationStatusType::Completed);
assert_eq!(object.target_replication_status("arn:missing"), ReplicationStatusType::Empty);
assert_eq!(state.targets.get("arn:target-b"), Some(&ReplicationStatusType::Failed));
assert_eq!(state.purge_targets.get("arn:target-a"), Some(&VersionPurgeStatusType::Pending));
assert_eq!(state.reset_statuses_map.get("arn:target-a"), Some(&"reset-id".to_string()));
}
#[test]
fn versions_after_marker_handles_uuid_version_marker() {
let first_version = Uuid::parse_str("11111111-2222-3333-4444-555555555555").unwrap();