Skip to content

Commit 8be8517

Browse files
authored
feat: Add support for returning metadata root mirror node info (#18)
Add support for returning metadata root mirror node info and other refactors - Extended SQL query and added root mirror node support - Refactored variable names and queries - Updated dependencies and formatting ThinkParQ/beegfs-go#27
1 parent 1b9b203 commit 8be8517

File tree

3 files changed

+81
-47
lines changed

3 files changed

+81
-47
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ itertools = "0"
1818
libc = "0"
1919
log = { version = "0", features = ["std"] }
2020
prost = "0"
21-
protobuf = { git = "https://github.com/thinkparq/protobuf", rev = "ecdf4dc4bc70bdf3db47e7d7a4d335f4a325f63e" }
21+
protobuf = { git = "https://github.com/thinkparq/protobuf", rev = "24f942a79ffa8a879b84dc014384c9f06780d2b7" }
2222
regex = "1"
2323
ring = "0"
2424
rusqlite = { version = "0", features = ["bundled", "vtab", "array"] }

mgmtd/src/grpc/node.rs

Lines changed: 79 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,30 @@ use shared::bee_msg::node::RemoveNode;
33

44
/// Delivers a list of nodes
55
pub(crate) async fn get(ctx: Context, req: pm::GetNodesRequest) -> Result<pm::GetNodesResponse> {
6-
let (mut nodes, nics, meta_root_node, fs_uuid) = ctx
6+
let (mut nodes, nics, meta_root_node, meta_root_buddy_group, fs_uuid) = ctx
77
.db
88
.read_tx(move |tx| {
99
// Fetching the nic list is optional as it causes additional load
1010
let nics: Vec<(Uid, pm::get_nodes_response::node::Nic)> = if req.include_nics {
11-
tx.prepare_cached(
12-
sql!(
13-
"SELECT nn.node_uid, nn.addr, n.port, nn.nic_type, nn.name
14-
FROM node_nics AS nn
15-
INNER JOIN nodes AS n USING(node_uid)
16-
ORDER BY nn.node_uid ASC"
17-
))?.query_and_then(
18-
[],
19-
|row| {
20-
let nic_type = NicType::from_row(row, 3)?.into_proto_i32();
21-
22-
Ok((
23-
row.get(0)?,
24-
pm::get_nodes_response::node::Nic {
25-
addr: row.get(1)?,
26-
name: row.get(4)?,
27-
nic_type,
28-
},
29-
))
30-
},
31-
)?.collect::<Result<Vec<_>>>()?
11+
tx.prepare_cached(sql!(
12+
"SELECT nn.node_uid, nn.addr, n.port, nn.nic_type, nn.name
13+
FROM node_nics AS nn
14+
INNER JOIN nodes AS n USING(node_uid)
15+
ORDER BY nn.node_uid ASC"
16+
))?
17+
.query_and_then([], |row| {
18+
let nic_type = NicType::from_row(row, 3)?.into_proto_i32();
19+
20+
Ok((
21+
row.get(0)?,
22+
pm::get_nodes_response::node::Nic {
23+
addr: row.get(1)?,
24+
name: row.get(4)?,
25+
nic_type,
26+
},
27+
))
28+
})?
29+
.collect::<Result<Vec<_>>>()?
3230
} else {
3331
vec![]
3432
};
@@ -58,44 +56,79 @@ pub(crate) async fn get(ctx: Context, req: pm::GetNodesRequest) -> Result<pm::Ge
5856
},
5957
)?;
6058

61-
// Figure out the meta root node
62-
let meta_root_node = if let Some((uid, alias, num_id)) = tx
59+
// Figure out the meta root node and buddy mirror information
60+
let maybe_row = tx
6361
.query_row_cached(
6462
sql!(
6563
"SELECT
66-
COALESCE(mn.node_uid, mn2.node_uid),
67-
COALESCE(e.alias, e2.alias),
68-
COALESCE(mn.node_id, mn2.node_id)
64+
COALESCE(mn.node_uid, mn2.node_uid),
65+
COALESCE(e.alias, e2.alias),
66+
COALESCE(mn.node_id, mn2.node_id),
67+
mg.group_id,
68+
mg.group_uid,
69+
ge.alias
6970
FROM root_inode as ri
7071
LEFT JOIN targets AS mt USING(node_type, target_id)
71-
LEFT JOIN nodes AS mn ON mn.node_id = mt.node_id AND mn.node_type = mt.node_type
72+
LEFT JOIN nodes AS mn ON mn.node_id = mt.node_id
73+
AND mn.node_type = mt.node_type
7274
LEFT JOIN entities AS e ON e.uid = mn.node_uid
7375
LEFT JOIN buddy_groups AS mg USING(node_type, group_id)
74-
LEFT JOIN targets AS mt2 ON mt2.target_id = mg.p_target_id AND mt2.node_type = mg.node_type
75-
LEFT JOIN nodes AS mn2 ON mn2.node_id = mt2.node_id AND mn2.node_type = mg.node_type
76+
LEFT JOIN entities AS ge ON ge.uid = mg.group_uid
77+
LEFT JOIN targets AS mt2 ON mt2.target_id = mg.p_target_id
78+
AND mt2.node_type = mg.node_type
79+
LEFT JOIN nodes AS mn2 ON mn2.node_id = mt2.node_id
80+
AND mn2.node_type = mg.node_type
7681
LEFT JOIN entities AS e2 ON e2.uid = mn2.node_uid"
7782
),
7883
[],
79-
|row| Ok((row.get(0)?, row.get::<_, String>(1)?, row.get(2)?)),
80-
)
81-
.optional()?
82-
{
83-
Some(EntityIdSet {
84-
uid,
85-
alias: alias.try_into()?,
86-
legacy_id: LegacyId {
87-
node_type: NodeType::Meta,
88-
num_id,
84+
|row| {
85+
Ok((
86+
row.get::<_, Uid>(0)?,
87+
row.get::<_, String>(1)?,
88+
row.get::<_, NodeId>(2)?,
89+
row.get::<_, Option<NodeId>>(3)?,
90+
row.get::<_, Option<Uid>>(4)?,
91+
row.get::<_, Option<String>>(5)?,
92+
))
8993
},
90-
})
91-
} else {
92-
None
93-
};
94+
)
95+
.optional()?;
96+
97+
let (meta_root_node, meta_root_buddy_group) =
98+
if let Some((uid, alias, num_id, bg_num_id, bg_uid, bg_alias)) = maybe_row {
99+
let meta_root_node = Some(EntityIdSet {
100+
uid,
101+
alias: alias.try_into()?,
102+
legacy_id: LegacyId {
103+
node_type: NodeType::Meta,
104+
num_id,
105+
},
106+
});
107+
108+
let meta_root_buddy_group = if let (Some(num_id), Some(uid), Some(alias)) =
109+
(bg_num_id, bg_uid, bg_alias)
110+
{
111+
Some(EntityIdSet {
112+
uid,
113+
alias: alias.try_into()?,
114+
legacy_id: LegacyId {
115+
node_type: NodeType::Meta,
116+
num_id,
117+
},
118+
})
119+
} else {
120+
None
121+
};
122+
123+
(meta_root_node, meta_root_buddy_group)
124+
} else {
125+
(None, None)
126+
};
94127

95128
let fs_uuid = db::config::get(tx, db::config::Config::FsUuid)
96129
.context("Could not read file system UUID from database")?;
97130

98-
Ok((nodes, nics, meta_root_node, fs_uuid))
131+
Ok((nodes, nics, meta_root_node, meta_root_buddy_group, fs_uuid))
99132
})
100133
.await?;
101134

@@ -115,6 +148,7 @@ pub(crate) async fn get(ctx: Context, req: pm::GetNodesRequest) -> Result<pm::Ge
115148
Ok(pm::GetNodesResponse {
116149
nodes,
117150
meta_root_node: meta_root_node.map(|e| e.into()),
151+
meta_root_buddy_group: meta_root_buddy_group.map(|e| e.into()),
118152
fs_uuid,
119153
})
120154
}

0 commit comments

Comments
 (0)