From 3fc39768e9ec716623273f6920d9297ba472649e Mon Sep 17 00:00:00 2001 From: Rusty Bee <145002912+rustybee42@users.noreply.github.com> Date: Wed, 10 Sep 2025 12:24:28 +0200 Subject: [PATCH] fix: include unmapped targets with most queries --- mgmtd/src/db/schema/4.sql | 8 ++++++++ mgmtd/src/grpc/target.rs | 26 +++++++++++++++----------- 2 files changed, 23 insertions(+), 11 deletions(-) create mode 100644 mgmtd/src/db/schema/4.sql diff --git a/mgmtd/src/db/schema/4.sql b/mgmtd/src/db/schema/4.sql new file mode 100644 index 0000000..4b1ba91 --- /dev/null +++ b/mgmtd/src/db/schema/4.sql @@ -0,0 +1,8 @@ +DROP VIEW targets_ext; + +CREATE VIEW targets_ext AS + SELECT e.alias, t.*, n.node_uid + FROM targets AS t + INNER JOIN entities AS e ON e.uid = t.target_uid + LEFT JOIN nodes AS n USING(node_type, node_id) +; diff --git a/mgmtd/src/grpc/target.rs b/mgmtd/src/grpc/target.rs index afce3ee..97e38a4 100644 --- a/mgmtd/src/grpc/target.rs +++ b/mgmtd/src/grpc/target.rs @@ -33,7 +33,7 @@ pub(crate) async fn get( t.free_space, t.free_inodes, t.total_space, t.total_inodes, gp.p_target_id, gs.s_target_id FROM targets_ext AS t - INNER JOIN nodes_ext AS n USING(node_uid) + LEFT JOIN nodes_ext AS n USING(node_uid) LEFT JOIN pools_ext AS p USING(node_type, pool_id) LEFT JOIN buddy_groups AS gp ON gp.p_target_id = t.target_id AND gp.node_type = t.node_type LEFT JOIN buddy_groups AS gs ON gs.s_target_id = t.target_id AND gs.node_type = t.node_type" @@ -45,6 +45,19 @@ pub(crate) async fn get( let is_primary = row.get::<_, Option>(16)?.is_some(); let is_secondary = row.get::<_, Option>(17)?.is_some(); + let node = if let Some(node_id) = row.get::<_, Option>(6)? { + Some(pb::EntityIdSet { + uid: row.get(4)?, + legacy_id: Some(pb::LegacyId { + num_id: node_id, + node_type, + }), + alias: row.get(5)?, + }) + } else { + None + }; + Ok(pm::get_targets_response::Target { id: Some(pb::EntityIdSet { uid: row.get(0)?, @@ -55,14 +68,7 @@ pub(crate) async fn get( alias: row.get(1)?, }), node_type, - node: Some(pb::EntityIdSet { - uid: row.get(4)?, - legacy_id: Some(pb::LegacyId { - num_id: row.get(6)?, - node_type, - }), - alias: row.get(5)?, - }), + node, storage_pool: if let Some(uid) = row.get::<_, Option>(7)? { Some(pb::EntityIdSet { uid: Some(uid), @@ -219,8 +225,6 @@ pub(crate) async fn delete( let target = Some(target.into()); - log::warn!("{target:?}"); - Ok(pm::DeleteTargetResponse { target }) }