fix: reload bucket metadata after lifecycle updates (#2822)

Co-authored-by: houseme <housemecn@gmail.com>
This commit is contained in:
cxymds
2026-05-06 21:01:44 +08:00
committed by GitHub
parent 4b36667ba1
commit 9f07029373
2 changed files with 60 additions and 23 deletions
+39 -23
View File
@@ -485,31 +485,29 @@ impl NotificationSys {
Ok(())
}
pub async fn load_bucket_metadata(&self, bucket: &str) -> Vec<NotificationPeerErr> {
pub async fn load_bucket_metadata(&self, bucket: &str) -> Result<()> {
let operation = format!("load_bucket_metadata({bucket})");
let mut failures = Vec::new();
let mut futures = Vec::with_capacity(self.peer_clients.len());
for client in self.peer_clients.iter() {
let b = bucket.to_string();
futures.push(async move {
if let Some(client) = client {
match client.load_bucket_metadata(&b).await {
Ok(_) => NotificationPeerErr {
host: client.host.to_string(),
err: None,
},
Err(e) => NotificationPeerErr {
host: client.host.to_string(),
err: Some(e),
},
}
} else {
NotificationPeerErr {
host: "".to_string(),
err: Some(Error::other("peer is not reachable")),
}
}
});
for (idx, client) in self.peer_clients.iter().enumerate() {
if let Some(client) = client {
let host = client.host.to_string();
let b = bucket.to_string();
futures.push(async move { client.load_bucket_metadata(&b).await.map_err(|err| (host, err)) });
} else {
failures.push(format!("peer[{idx}] {operation} failed: peer is not reachable"));
}
}
join_all(futures).await
for result in join_all(futures).await {
if let Err((host, err)) = result {
let failure = format!("peer {host} {operation} failed: {err}");
error!("notification {operation} err {failure}");
failures.push(failure);
}
}
aggregate_notification_failures(&operation, failures)
}
pub async fn delete_bucket_metadata(&self, bucket: &str) -> Vec<NotificationPeerErr> {
@@ -904,4 +902,22 @@ mod tests {
assert!(msg.contains("peer-1 failed"));
assert!(msg.contains("local save failed"));
}
#[tokio::test]
async fn load_bucket_metadata_reports_unreachable_peers() {
let sys = NotificationSys {
peer_clients: vec![None],
all_peer_clients: Vec::new(),
};
let err = sys
.load_bucket_metadata("bucket-a")
.await
.expect_err("unreachable peers should fail bucket metadata reload");
let msg = err.to_string();
assert!(msg.contains("load_bucket_metadata(bucket-a)"));
assert!(msg.contains("1 failure(s)"));
assert!(msg.contains("peer[0]"));
}
}