@@ -3,32 +3,30 @@ use shared::bee_msg::node::RemoveNode;
3
3
4
4
/// Delivers a list of nodes
5
5
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
7
7
. db
8
8
. read_tx ( move |tx| {
9
9
// Fetching the nic list is optional as it causes additional load
10
10
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 < _ > > > ( ) ?
32
30
} else {
33
31
vec ! [ ]
34
32
} ;
@@ -58,44 +56,79 @@ pub(crate) async fn get(ctx: Context, req: pm::GetNodesRequest) -> Result<pm::Ge
58
56
} ,
59
57
) ?;
60
58
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
63
61
. query_row_cached (
64
62
sql ! (
65
63
"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
69
70
FROM root_inode as ri
70
71
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
72
74
LEFT JOIN entities AS e ON e.uid = mn.node_uid
73
75
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
76
81
LEFT JOIN entities AS e2 ON e2.uid = mn2.node_uid"
77
82
) ,
78
83
[ ] ,
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
+ ) )
89
93
} ,
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
+ } ;
94
127
95
128
let fs_uuid = db:: config:: get ( tx, db:: config:: Config :: FsUuid )
96
129
. context ( "Could not read file system UUID from database" ) ?;
97
130
98
- Ok ( ( nodes, nics, meta_root_node, fs_uuid) )
131
+ Ok ( ( nodes, nics, meta_root_node, meta_root_buddy_group , fs_uuid) )
99
132
} )
100
133
. await ?;
101
134
@@ -115,6 +148,7 @@ pub(crate) async fn get(ctx: Context, req: pm::GetNodesRequest) -> Result<pm::Ge
115
148
Ok ( pm:: GetNodesResponse {
116
149
nodes,
117
150
meta_root_node : meta_root_node. map ( |e| e. into ( ) ) ,
151
+ meta_root_buddy_group : meta_root_buddy_group. map ( |e| e. into ( ) ) ,
118
152
fs_uuid,
119
153
} )
120
154
}
0 commit comments