Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions mgmtd/src/db/schema/4.sql
Original file line number Diff line number Diff line change
@@ -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)
;
26 changes: 15 additions & 11 deletions mgmtd/src/grpc/target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -45,6 +45,19 @@ pub(crate) async fn get(
let is_primary = row.get::<_, Option<TargetId>>(16)?.is_some();
let is_secondary = row.get::<_, Option<TargetId>>(17)?.is_some();

let node = if let Some(node_id) = row.get::<_, Option<NodeId>>(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)?,
Expand All @@ -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<Uid>>(7)? {
Some(pb::EntityIdSet {
uid: Some(uid),
Expand Down Expand Up @@ -219,8 +225,6 @@ pub(crate) async fn delete(

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

log::warn!("{target:?}");

Ok(pm::DeleteTargetResponse { target })
}

Expand Down
Loading