Skip to content

Commit d31ad32

Browse files
committed
fix: include unmapped targets with most queries
1 parent 14b6851 commit d31ad32

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

mgmtd/src/db/schema/4.sql

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
DROP VIEW targets_ext;
2+
3+
CREATE VIEW targets_ext AS
4+
SELECT e.alias, t.*, n.node_uid
5+
FROM targets AS t
6+
INNER JOIN entities AS e ON e.uid = t.target_uid
7+
LEFT JOIN nodes AS n USING(node_type, node_id)
8+
;

mgmtd/src/grpc/target.rs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub(crate) async fn get(
3333
t.free_space, t.free_inodes, t.total_space, t.total_inodes,
3434
gp.p_target_id, gs.s_target_id
3535
FROM targets_ext AS t
36-
INNER JOIN nodes_ext AS n USING(node_uid)
36+
LEFT JOIN nodes_ext AS n USING(node_uid)
3737
LEFT JOIN pools_ext AS p USING(node_type, pool_id)
3838
LEFT JOIN buddy_groups AS gp ON gp.p_target_id = t.target_id AND gp.node_type = t.node_type
3939
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(
4545
let is_primary = row.get::<_, Option<TargetId>>(16)?.is_some();
4646
let is_secondary = row.get::<_, Option<TargetId>>(17)?.is_some();
4747

48+
let node = if let Some(node_id) = row.get::<_, Option<NodeId>>(6)? {
49+
Some(pb::EntityIdSet {
50+
uid: row.get(4)?,
51+
legacy_id: Some(pb::LegacyId {
52+
num_id: node_id,
53+
node_type,
54+
}),
55+
alias: row.get(5)?,
56+
})
57+
} else {
58+
None
59+
};
60+
4861
Ok(pm::get_targets_response::Target {
4962
id: Some(pb::EntityIdSet {
5063
uid: row.get(0)?,
@@ -55,14 +68,7 @@ pub(crate) async fn get(
5568
alias: row.get(1)?,
5669
}),
5770
node_type,
58-
node: Some(pb::EntityIdSet {
59-
uid: row.get(4)?,
60-
legacy_id: Some(pb::LegacyId {
61-
num_id: row.get(6)?,
62-
node_type,
63-
}),
64-
alias: row.get(5)?,
65-
}),
71+
node,
6672
storage_pool: if let Some(uid) = row.get::<_, Option<Uid>>(7)? {
6773
Some(pb::EntityIdSet {
6874
uid: Some(uid),
@@ -219,8 +225,6 @@ pub(crate) async fn delete(
219225

220226
let target = Some(target.into());
221227

222-
log::warn!("{target:?}");
223-
224228
Ok(pm::DeleteTargetResponse { target })
225229
}
226230

0 commit comments

Comments
 (0)