Skip to content

Commit 102d604

Browse files
authored
fix: read in nics when importing a v7 management (ThinkParQ/beegfs-rs#182)
While they are replaced anyway on first contact with a node, this avoids error messages on first startup where nodes are already imported into the db but they have no nics.
1 parent ef5abe9 commit 102d604

File tree

3 files changed

+48
-11
lines changed

3 files changed

+48
-11
lines changed

mgmtd/src/bee_msg.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,6 @@ pub async fn notify_nodes<M: Msg + Serializable>(
212212
}
213213
.await
214214
{
215-
log::error!("Notification could not be send to all nodes: {err:#}");
215+
log::error!("Notification could not be sent to all nodes: {err:#}");
216216
}
217217
}

mgmtd/src/db/import_v7.rs

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ use crate::db::*;
22
use anyhow::{Context, Result, anyhow, bail};
33
use rusqlite::Transaction;
44
use shared::bee_msg::buddy_group::CombinedTargetState;
5+
use shared::bee_msg::node::Nic;
56
use shared::bee_msg::quota::QuotaEntry;
67
use shared::bee_msg::storage_pool::StoragePool;
7-
use shared::bee_serde::{Deserializable, Deserializer};
8+
use shared::bee_serde::{BeeSerdeConversion, Deserializable, Deserializer};
89
use shared::types::*;
910
use sqlite_check::sql;
1011
use std::io::Write;
@@ -112,6 +113,23 @@ fn check_target_states(f: &Path) -> Result<()> {
112113
Ok(())
113114
}
114115

116+
fn node_nics(tx: &Transaction, node_uid: Uid, nics: Vec<Nic>) -> Result<()> {
117+
let mut stmt = tx.prepare_cached(sql!(
118+
"INSERT INTO node_nics (node_uid, nic_type, addr, name) VALUES (?1, ?2, ?3, ?4)"
119+
))?;
120+
121+
for nic in nics {
122+
stmt.execute(params![
123+
node_uid,
124+
nic.nic_type.sql_variant(),
125+
nic.addr.to_string(),
126+
String::from_utf8_lossy(&nic.name)
127+
])?;
128+
}
129+
130+
Ok(())
131+
}
132+
115133
/// Imports meta nodes / targets. Intentionally ignores nics as they are refreshed on first contact
116134
/// anyway.
117135
fn meta_nodes(tx: &Transaction, f: &Path) -> Result<(NodeId, bool)> {
@@ -121,8 +139,9 @@ fn meta_nodes(tx: &Transaction, f: &Path) -> Result<(NodeId, bool)> {
121139
nodes,
122140
} = read_nodes(f)?;
123141

124-
for (num_id, port) in nodes {
125-
node::insert(tx, num_id, None, NodeType::Meta, port)?;
142+
for (num_id, port, nics) in nodes {
143+
let node = node::insert(tx, num_id, None, NodeType::Meta, port)?;
144+
node_nics(tx, node.uid, nics)?;
126145

127146
// A meta target has to be explicitly created with the same ID as the node.
128147
let Ok(target_id) = TargetId::try_from(num_id) else {
@@ -151,8 +170,9 @@ fn meta_nodes(tx: &Transaction, f: &Path) -> Result<(NodeId, bool)> {
151170
fn storage_nodes(tx: &Transaction, f: &Path) -> Result<()> {
152171
let ReadNodesResult { nodes, .. } = read_nodes(f)?;
153172

154-
for (num_id, port) in nodes {
155-
node::insert(tx, num_id, None, NodeType::Storage, port)?;
173+
for (num_id, port, nics) in nodes {
174+
let node = node::insert(tx, num_id, None, NodeType::Storage, port)?;
175+
node_nics(tx, node.uid, nics)?;
156176
}
157177

158178
Ok(())
@@ -161,7 +181,7 @@ fn storage_nodes(tx: &Transaction, f: &Path) -> Result<()> {
161181
struct ReadNodesResult {
162182
root_id: NodeId,
163183
root_mirrored: bool,
164-
nodes: Vec<(NodeId, Port)>,
184+
nodes: Vec<(NodeId, Port, Vec<Nic>)>,
165185
}
166186

167187
// Deserialize nodes from file
@@ -175,17 +195,34 @@ fn read_nodes(f: &Path) -> Result<ReadNodesResult> {
175195

176196
// Define the node data deserialization manually because the `Nic` type used by `Node` had
177197
// changes for v8 (the ipv6 changes). The v7 on-disk-data is of course still in the old format.
178-
// We only need the num id and the port, everything else is ignored.
179198
let nodes = des.seq(false, |des| {
180199
des.cstr(0)?;
181200
// The v7 on-disk-data does NOT contain the total size field, so putting `false` here is
182201
// correct. It only got introduced with the ipv6 changes.
183-
des.seq(false, |des| des.skip(24))?;
202+
let nics = des.seq(false, |des| {
203+
// The v7 on-disk-data uses the old format without a protocol field, thus we deserialize
204+
// it manually here.
205+
let addr = des.u32()?.to_le_bytes().into();
206+
let mut name = des.bytes(15)?;
207+
des.u8()?;
208+
let nic_type = NicType::try_from_bee_serde(des.u8()?)?;
209+
des.skip(3)?;
210+
211+
// Remove null bytes from name
212+
name.retain(|b| b != &0);
213+
214+
Ok(Nic {
215+
addr,
216+
name,
217+
nic_type,
218+
})
219+
})?;
220+
184221
let num_id = NodeId::deserialize(des)?;
185222
let port = Port::deserialize(des)?;
186223
Port::deserialize(des)?;
187224
des.u8()?;
188-
Ok((num_id, port))
225+
Ok((num_id, port, nics))
189226
})?;
190227
des.finish()?;
191228

shared/src/conn/outgoing.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ impl Pool {
195195

196196
for node_uid in peers {
197197
let Some(addrs) = self.store.get_node_addrs(node_uid) else {
198-
bail!("No known addresses of {node_uid:?}");
198+
bail!("No network address found for node with uid {node_uid:?}");
199199
};
200200

201201
for addr in addrs.iter() {

0 commit comments

Comments
 (0)