mirror of
https://github.com/rustfs/rustfs.git
synced 2026-12-01 13:44:49 +00:00
Distinguish replication buckets sharing the same remote endpoint
This commit is contained in:
@@ -925,29 +925,24 @@ impl BucketTargetSys {
|
||||
target: &BucketTarget,
|
||||
update: bool,
|
||||
) -> Result<(), BucketTargetError> {
|
||||
let mut found = false;
|
||||
|
||||
for (idx, existing_target) in bucket_targets.iter().enumerate() {
|
||||
if existing_target.target_type.to_string() == target.target_type.to_string() {
|
||||
if existing_target.arn == target.arn {
|
||||
if !update {
|
||||
return Err(BucketTargetError::BucketRemoteAlreadyExists {
|
||||
bucket: existing_target.target_bucket.clone(),
|
||||
});
|
||||
}
|
||||
bucket_targets[idx] = target.clone();
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
if existing_target.endpoint == target.endpoint {
|
||||
return Err(BucketTargetError::BucketRemoteAlreadyExists {
|
||||
bucket: existing_target.target_bucket.clone(),
|
||||
});
|
||||
}
|
||||
let mut replace_index = None;
|
||||
for (index, existing) in bucket_targets.iter().enumerate() {
|
||||
if existing.target_type != target.target_type {
|
||||
continue;
|
||||
}
|
||||
if update && existing.arn == target.arn {
|
||||
replace_index.get_or_insert(index);
|
||||
} else if existing.arn == target.arn
|
||||
|| (existing.endpoint == target.endpoint && existing.target_bucket == target.target_bucket)
|
||||
{
|
||||
return Err(BucketTargetError::BucketRemoteAlreadyExists {
|
||||
bucket: existing.target_bucket.clone(),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if !found && !update {
|
||||
if let Some(index) = replace_index {
|
||||
bucket_targets[index] = target.clone();
|
||||
} else if !update {
|
||||
bucket_targets.push(target.clone());
|
||||
}
|
||||
|
||||
@@ -5567,6 +5562,59 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn site_and_bucket_replication_can_register_distinct_destinations_on_one_peer() {
|
||||
let site = BucketTarget {
|
||||
target_bucket: "source".into(),
|
||||
..repair_target("source", "site")
|
||||
};
|
||||
let operator = repair_target("source", "archive");
|
||||
for (first, second) in [(&site, &operator), (&operator, &site)] {
|
||||
let mut targets = vec![first.clone()];
|
||||
BucketTargetSys::upsert_target_entry(&mut targets, second, false).expect("register the other destination");
|
||||
let mut edited = second.clone();
|
||||
edited.bandwidth_limit = 4096;
|
||||
BucketTargetSys::upsert_target_entry(&mut targets, &edited, true).expect("update only the selected ARN");
|
||||
assert_eq!(targets.len(), 2);
|
||||
assert_eq!(targets[0].arn, first.arn);
|
||||
assert_eq!(targets[0].bandwidth_limit, first.bandwidth_limit);
|
||||
assert_eq!(targets[1].arn, second.arn);
|
||||
assert_eq!(targets[1].target_bucket, second.target_bucket);
|
||||
assert_eq!(targets[1].bandwidth_limit, 4096);
|
||||
let duplicate = BucketTarget {
|
||||
arn: "another-arn".into(),
|
||||
..second.clone()
|
||||
};
|
||||
assert!(matches!(
|
||||
BucketTargetSys::upsert_target_entry(&mut targets, &duplicate, false),
|
||||
Err(BucketTargetError::BucketRemoteAlreadyExists { .. })
|
||||
));
|
||||
assert!(BucketTargetSys::upsert_target_entry(&mut targets, first, false).is_err());
|
||||
assert_eq!(targets.len(), 2);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn retargeting_to_an_existing_destination_preserves_both_entries_in_either_order() {
|
||||
let first = repair_target("source", "first");
|
||||
let old = BucketTarget {
|
||||
endpoint: "second.example.com".into(),
|
||||
..repair_target("source", "second")
|
||||
};
|
||||
let edit = BucketTarget {
|
||||
endpoint: first.endpoint.clone(),
|
||||
..old.clone()
|
||||
};
|
||||
for mut targets in [vec![first.clone(), old.clone()], vec![old.clone(), first.clone()]] {
|
||||
let before = serde_json::to_vec(&targets).unwrap();
|
||||
assert!(matches!(
|
||||
BucketTargetSys::upsert_target_entry(&mut targets, &edit, true),
|
||||
Err(BucketTargetError::BucketRemoteAlreadyExists { .. })
|
||||
));
|
||||
assert_eq!(serde_json::to_vec(&targets).unwrap(), before);
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn an_unreadable_target_set_refuses_cached_writes() {
|
||||
let sys = BucketTargetSys::default();
|
||||
|
||||
Reference in New Issue
Block a user