db-snapshot: propagate any node snapshot error through RPC call
All checks were successful
ci/woodpecker/pr/debug Pipeline was successful
ci/woodpecker/push/debug Pipeline was successful

In particular, it means that "garage meta snapshot --all" will get an exit
code of 1 if any node fails to snapshot.

This makes sure that any external tool trying to snapshot nodes (e.g. from
cron) will be aware of the failure.

Fix #920
This commit is contained in:
Baptiste Jonglez 2025-01-24 19:21:08 +01:00
parent 1d5142dcea
commit 8ff2aa729b

View file

@ -495,8 +495,15 @@ impl AdminRpcHandler {
ret.push(format!("{:?}\t{}", to, res_str)); ret.push(format!("{:?}\t{}", to, res_str));
} }
if resps.iter().any(|resp| match resp {
Err(_) => true,
Ok(_) => false,
}) {
Err(Error::BadRequest(format_table_to_string(ret)).into())
} else {
Ok(AdminRpc::Ok(format_table_to_string(ret))) Ok(AdminRpc::Ok(format_table_to_string(ret)))
} }
}
MetaOperation::Snapshot { all: false } => { MetaOperation::Snapshot { all: false } => {
garage_model::snapshot::async_snapshot_metadata(&self.garage).await?; garage_model::snapshot::async_snapshot_metadata(&self.garage).await?;
Ok(AdminRpc::Ok("Snapshot has been saved.".into())) Ok(AdminRpc::Ok("Snapshot has been saved.".into()))