mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-07 22:03:14 +00:00
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:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user