From 25a502e4031a0c5d6d38fb37ce429774db1cca13 Mon Sep 17 00:00:00 2001 From: Sunder Kodi <54266689+sundereshwar@users.noreply.github.com> Date: Fri, 4 Jul 2025 08:23:38 +0000 Subject: [PATCH] feat: 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 https://github.com/ThinkParQ/beegfs-go/issues/27 --- Cargo.lock | 2 +- Cargo.toml | 2 +- mgmtd/src/grpc/node.rs | 124 ++++++++++++++++++++++++++--------------- 3 files changed, 81 insertions(+), 47 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bb4ff74..d2712e9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -852,7 +852,7 @@ dependencies = [ [[package]] name = "protobuf" version = "0.0.0" -source = "git+https://github.com/thinkparq/protobuf?rev=ecdf4dc4bc70bdf3db47e7d7a4d335f4a325f63e#ecdf4dc4bc70bdf3db47e7d7a4d335f4a325f63e" +source = "git+https://github.com/thinkparq/protobuf?rev=24f942a79ffa8a879b84dc014384c9f06780d2b7#24f942a79ffa8a879b84dc014384c9f06780d2b7" dependencies = [ "prost", "prost-types", diff --git a/Cargo.toml b/Cargo.toml index 887fb22..b405115 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,7 +18,7 @@ itertools = "0" libc = "0" log = { version = "0", features = ["std"] } prost = "0" -protobuf = { git = "https://github.com/thinkparq/protobuf", rev = "ecdf4dc4bc70bdf3db47e7d7a4d335f4a325f63e" } +protobuf = { git = "https://github.com/thinkparq/protobuf", rev = "24f942a79ffa8a879b84dc014384c9f06780d2b7" } regex = "1" ring = "0" rusqlite = { version = "0", features = ["bundled", "vtab", "array"] } diff --git a/mgmtd/src/grpc/node.rs b/mgmtd/src/grpc/node.rs index ad60512..9391d82 100644 --- a/mgmtd/src/grpc/node.rs +++ b/mgmtd/src/grpc/node.rs @@ -3,32 +3,30 @@ use shared::bee_msg::node::RemoveNode; /// Delivers a list of nodes pub(crate) async fn get(ctx: Context, req: pm::GetNodesRequest) -> Result { - let (mut nodes, nics, meta_root_node, fs_uuid) = ctx + let (mut nodes, nics, meta_root_node, meta_root_buddy_group, fs_uuid) = ctx .db .read_tx(move |tx| { // Fetching the nic list is optional as it causes additional load let nics: Vec<(Uid, pm::get_nodes_response::node::Nic)> = if req.include_nics { - tx.prepare_cached( - sql!( - "SELECT nn.node_uid, nn.addr, n.port, nn.nic_type, nn.name - FROM node_nics AS nn - INNER JOIN nodes AS n USING(node_uid) - ORDER BY nn.node_uid ASC" - ))?.query_and_then( - [], - |row| { - let nic_type = NicType::from_row(row, 3)?.into_proto_i32(); - - Ok(( - row.get(0)?, - pm::get_nodes_response::node::Nic { - addr: row.get(1)?, - name: row.get(4)?, - nic_type, - }, - )) - }, - )?.collect::>>()? + tx.prepare_cached(sql!( + "SELECT nn.node_uid, nn.addr, n.port, nn.nic_type, nn.name + FROM node_nics AS nn + INNER JOIN nodes AS n USING(node_uid) + ORDER BY nn.node_uid ASC" + ))? + .query_and_then([], |row| { + let nic_type = NicType::from_row(row, 3)?.into_proto_i32(); + + Ok(( + row.get(0)?, + pm::get_nodes_response::node::Nic { + addr: row.get(1)?, + name: row.get(4)?, + nic_type, + }, + )) + })? + .collect::>>()? } else { vec![] }; @@ -58,44 +56,79 @@ pub(crate) async fn get(ctx: Context, req: pm::GetNodesRequest) -> Result(1)?, row.get(2)?)), - ) - .optional()? - { - Some(EntityIdSet { - uid, - alias: alias.try_into()?, - legacy_id: LegacyId { - node_type: NodeType::Meta, - num_id, + |row| { + Ok(( + row.get::<_, Uid>(0)?, + row.get::<_, String>(1)?, + row.get::<_, NodeId>(2)?, + row.get::<_, Option>(3)?, + row.get::<_, Option>(4)?, + row.get::<_, Option>(5)?, + )) }, - }) - } else { - None - }; + ) + .optional()?; + + let (meta_root_node, meta_root_buddy_group) = + if let Some((uid, alias, num_id, bg_num_id, bg_uid, bg_alias)) = maybe_row { + let meta_root_node = Some(EntityIdSet { + uid, + alias: alias.try_into()?, + legacy_id: LegacyId { + node_type: NodeType::Meta, + num_id, + }, + }); + + let meta_root_buddy_group = if let (Some(num_id), Some(uid), Some(alias)) = + (bg_num_id, bg_uid, bg_alias) + { + Some(EntityIdSet { + uid, + alias: alias.try_into()?, + legacy_id: LegacyId { + node_type: NodeType::Meta, + num_id, + }, + }) + } else { + None + }; + + (meta_root_node, meta_root_buddy_group) + } else { + (None, None) + }; let fs_uuid = db::config::get(tx, db::config::Config::FsUuid) .context("Could not read file system UUID from database")?; - Ok((nodes, nics, meta_root_node, fs_uuid)) + Ok((nodes, nics, meta_root_node, meta_root_buddy_group, fs_uuid)) }) .await?; @@ -115,6 +148,7 @@ pub(crate) async fn get(ctx: Context, req: pm::GetNodesRequest) -> Result