aboutsummaryrefslogtreecommitdiff
path: root/src/garage
diff options
context:
space:
mode:
authorMendes <mendes.oulamara@pm.me>2022-10-11 17:17:13 +0200
committerMendes <mendes.oulamara@pm.me>2022-10-11 17:17:13 +0200
commite5664c9822c6ed1ecb30cac41b6a4125da3f88e7 (patch)
treed63136ec90d644d934f390f398e88248aef6b12d /src/garage
parent4abab246f1113a9a1988fdfca81c1dd8ffa323c8 (diff)
downloadgarage-e5664c9822c6ed1ecb30cac41b6a4125da3f88e7.tar.gz
garage-e5664c9822c6ed1ecb30cac41b6a4125da3f88e7.zip
Improved the statistics displayed in layout show
corrected a few bugs
Diffstat (limited to 'src/garage')
-rw-r--r--src/garage/cli/layout.rs69
1 files changed, 45 insertions, 24 deletions
diff --git a/src/garage/cli/layout.rs b/src/garage/cli/layout.rs
index f747fbe4..5056e57d 100644
--- a/src/garage/cli/layout.rs
+++ b/src/garage/cli/layout.rs
@@ -169,7 +169,7 @@ pub async fn cmd_show_layout(
rpc_cli: &Endpoint<SystemRpc, ()>,
rpc_host: NodeID,
) -> Result<(), Error> {
- let mut layout = fetch_layout(rpc_cli, rpc_host).await?;
+ let layout = fetch_layout(rpc_cli, rpc_host).await?;
println!("==== CURRENT CLUSTER LAYOUT ====");
if !print_cluster_layout(&layout) {
@@ -179,41 +179,40 @@ pub async fn cmd_show_layout(
println!();
println!("Current cluster layout version: {}", layout.version);
- if print_staging_role_changes(&layout) {
- layout.roles.merge(&layout.staging);
-
- println!();
- println!("==== NEW CLUSTER LAYOUT AFTER APPLYING CHANGES ====");
- if !print_cluster_layout(&layout) {
- println!("No nodes have a role in the new layout.");
- }
- println!();
-
- println!("==== PARAMETERS OF THE LAYOUT COMPUTATION ====");
- println!(
- "Zone redundancy: {}",
- layout.staged_parameters.get().zone_redundancy
- );
- println!();
+ let has_role_changes = print_staging_role_changes(&layout);
+ let has_param_changes = print_staging_parameters_changes(&layout);
+ if has_role_changes || has_param_changes {
+ let v = layout.version;
+ let res_apply = layout.apply_staged_changes(Some(v + 1));
// this will print the stats of what partitions
// will move around when we apply
- match layout.calculate_partition_assignation() {
- Ok(msg) => {
+ match res_apply {
+ Ok((layout, msg)) => {
+ println!();
+ println!("==== NEW CLUSTER LAYOUT AFTER APPLYING CHANGES ====");
+ if !print_cluster_layout(&layout) {
+ println!("No nodes have a role in the new layout.");
+ }
+ println!();
+
for line in msg.iter() {
println!("{}", line);
}
println!("To enact the staged role changes, type:");
println!();
- println!(" garage layout apply --version {}", layout.version + 1);
+ println!(" garage layout apply --version {}", v + 1);
println!();
println!(
"You can also revert all proposed changes with: garage layout revert --version {}",
- layout.version + 1)
+ v + 1)
}
Err(Error::Message(s)) => {
println!("Error while trying to compute the assignation: {}", s);
println!("This new layout cannot yet be applied.");
+ println!(
+ "You can also revert all proposed changes with: garage layout revert --version {}",
+ v + 1)
}
_ => {
println!("Unknown Error");
@@ -321,21 +320,29 @@ pub async fn send_layout(
}
pub fn print_cluster_layout(layout: &ClusterLayout) -> bool {
- let mut table = vec!["ID\tTags\tZone\tCapacity".to_string()];
+ let mut table = vec!["ID\tTags\tZone\tCapacity\tUsable".to_string()];
for (id, _, role) in layout.roles.items().iter() {
let role = match &role.0 {
Some(r) => r,
_ => continue,
};
let tags = role.tags.join(",");
+ let usage = layout.get_node_usage(id).unwrap_or(0);
+ let capacity = layout.get_node_capacity(id).unwrap_or(1);
table.push(format!(
- "{:?}\t{}\t{}\t{}",
+ "{:?}\t{}\t{}\t{}\t{} ({:.1}%)",
id,
tags,
role.zone,
- role.capacity_string()
+ role.capacity_string(),
+ usage as u32 * layout.partition_size,
+ (100.0 * usage as f32 * layout.partition_size as f32) / (capacity as f32)
));
}
+ println!();
+ println!("Parameters of the layout computation:");
+ println!("Zone redundancy: {}", layout.parameters.zone_redundancy);
+ println!();
if table.len() == 1 {
false
} else {
@@ -344,6 +351,20 @@ pub fn print_cluster_layout(layout: &ClusterLayout) -> bool {
}
}
+pub fn print_staging_parameters_changes(layout: &ClusterLayout) -> bool {
+ let has_changes = layout.staged_parameters.get().clone() != layout.parameters;
+ if has_changes {
+ println!();
+ println!("==== NEW LAYOUT PARAMETERS ====");
+ println!(
+ "Zone redundancy: {}",
+ layout.staged_parameters.get().zone_redundancy
+ );
+ println!();
+ }
+ has_changes
+}
+
pub fn print_staging_role_changes(layout: &ClusterLayout) -> bool {
let has_changes = layout
.staging