Skip to content

Commit 90dc8ad

Browse files
authored
Ignore missing zpools instead of bailing (#7965)
In omdb, if a zpool is not part of the latest inventory, ignore this and continue displaying rows for other zpools and datasets. Several columns had to change to Option to support this. Fixes #7963
1 parent 2fd10bb commit 90dc8ad

File tree

1 file changed

+46
-26
lines changed
  • dev-tools/omdb/src/bin/omdb

1 file changed

+46
-26
lines changed

dev-tools/omdb/src/bin/omdb/db.rs

Lines changed: 46 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1636,11 +1636,21 @@ struct CrucibleDatasetRow {
16361636
no_provision: bool,
16371637

16381638
// zpool fields
1639-
control_plane_storage_buffer: i64,
1640-
pool_total_size: i64,
1639+
#[tabled(display_with = "option_impl_display")]
1640+
control_plane_storage_buffer: Option<i64>,
1641+
#[tabled(display_with = "option_impl_display")]
1642+
pool_total_size: Option<i64>,
16411643

16421644
// computed fields
1643-
size_left: i128,
1645+
#[tabled(display_with = "option_impl_display")]
1646+
size_left: Option<i128>,
1647+
}
1648+
1649+
fn option_impl_display<T: std::fmt::Display>(t: &Option<T>) -> String {
1650+
match t {
1651+
Some(v) => format!("{v}"),
1652+
None => String::from("n/a"),
1653+
}
16441654
}
16451655

16461656
async fn get_crucible_dataset_rows(
@@ -1676,16 +1686,14 @@ async fn get_crucible_dataset_rows(
16761686
Vec::with_capacity(crucible_datasets.len());
16771687

16781688
for d in crucible_datasets {
1679-
let control_plane_storage_buffer: i64 = zpools
1689+
let control_plane_storage_buffer: Option<i64> = match zpools
16801690
.get(&d.pool_id)
1681-
.ok_or_else(|| anyhow::anyhow!("zpool {} not found!", d.pool_id))?
1682-
.control_plane_storage_buffer()
1683-
.into();
1691+
{
1692+
Some(zpool) => Some(zpool.control_plane_storage_buffer().into()),
1693+
None => None,
1694+
};
16841695

1685-
let pool_total_size =
1686-
*zpool_total_size.get(&d.pool_id).ok_or_else(|| {
1687-
anyhow::anyhow!("zpool {} not part of inventory!", d.pool_id)
1688-
})?;
1696+
let pool_total_size = zpool_total_size.get(&d.pool_id);
16891697

16901698
result.push(CrucibleDatasetRow {
16911699
// dataset fields
@@ -1701,12 +1709,18 @@ async fn get_crucible_dataset_rows(
17011709

17021710
// zpool fields
17031711
control_plane_storage_buffer,
1704-
pool_total_size,
1712+
pool_total_size: pool_total_size.cloned(),
17051713

17061714
// computed fields
1707-
size_left: i128::from(pool_total_size)
1708-
- i128::from(control_plane_storage_buffer)
1709-
- i128::from(d.size_used),
1715+
size_left: match (pool_total_size, control_plane_storage_buffer) {
1716+
(Some(total_size), Some(control_plane_storage_buffer)) => Some(
1717+
i128::from(*total_size)
1718+
- i128::from(control_plane_storage_buffer)
1719+
- i128::from(d.size_used),
1720+
),
1721+
1722+
_ => None,
1723+
},
17101724
});
17111725
}
17121726

@@ -1742,9 +1756,20 @@ async fn cmd_crucible_dataset_show_overprovisioned(
17421756
let rows: Vec<_> = rows
17431757
.into_iter()
17441758
.filter(|row| {
1745-
(i128::from(row.size_used)
1746-
+ i128::from(row.control_plane_storage_buffer))
1747-
>= i128::from(row.pool_total_size)
1759+
match (row.pool_total_size, row.control_plane_storage_buffer) {
1760+
(Some(pool_total_size), Some(control_plane_storage_buffer)) => {
1761+
(i128::from(row.size_used)
1762+
+ i128::from(control_plane_storage_buffer))
1763+
>= i128::from(pool_total_size)
1764+
}
1765+
1766+
_ => {
1767+
// Without the total size or control plane storage buffer, we
1768+
// can't determine if the dataset is overprovisioned or not.
1769+
// Filter it out.
1770+
false
1771+
}
1772+
}
17481773
})
17491774
.collect();
17501775

@@ -7858,7 +7883,8 @@ async fn cmd_db_zpool_list(
78587883
time_deleted: String,
78597884
sled_id: Uuid,
78607885
physical_disk_id: Uuid,
7861-
total_size: i64,
7886+
#[tabled(display_with = "option_impl_display")]
7887+
total_size: Option<i64>,
78627888
control_plane_storage_buffer: i64,
78637889
}
78647890

@@ -7874,13 +7900,7 @@ async fn cmd_db_zpool_list(
78747900
},
78757901
sled_id: p.sled_id,
78767902
physical_disk_id: p.physical_disk_id.into_untyped_uuid(),
7877-
total_size: *zpool_total_size.get(&zpool_id).ok_or_else(
7878-
|| {
7879-
anyhow::anyhow!(
7880-
"zpool {zpool_id} not found in inventory!"
7881-
)
7882-
},
7883-
)?,
7903+
total_size: zpool_total_size.get(&zpool_id).cloned(),
78847904
control_plane_storage_buffer: p
78857905
.control_plane_storage_buffer()
78867906
.into(),

0 commit comments

Comments
 (0)