Skip to content

Commit bf3db35

Browse files
helper function
1 parent 7903933 commit bf3db35

File tree

1 file changed

+36
-27
lines changed

1 file changed

+36
-27
lines changed

src/handlers/http/modal/mod.rs

Lines changed: 36 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -306,12 +306,22 @@ impl NodeMetadata {
306306
node_type_str: &str,
307307
options: &Options,
308308
) -> Option<Self> {
309-
let entries = staging_path
310-
.read_dir()
311-
.expect("Couldn't read from staging directory");
309+
let entries = match staging_path.read_dir() {
310+
Ok(entries) => entries,
311+
Err(e) => {
312+
error!("Couldn't read from staging directory: {}", e);
313+
return None;
314+
}
315+
};
312316

313317
for entry in entries {
314-
let path = entry.expect("Should be a directory entry").path();
318+
let path = match entry {
319+
Ok(entry) => entry.path(),
320+
Err(e) => {
321+
error!("Error reading directory entry: {}", e);
322+
continue;
323+
}
324+
};
315325
if !Self::is_valid_metadata_file(&path, node_type_str) {
316326
continue;
317327
}
@@ -417,32 +427,31 @@ impl NodeMetadata {
417427
let version = json.get("version").and_then(|version| version.as_str());
418428

419429
if version == Some("v3") {
420-
if json.contains_key("ingestor_id") {
421-
// Migration: get ingestor_id value, remove it, and add as node_id
422-
if let Some(id) = json.remove("ingestor_id") {
423-
json.insert("node_id".to_string(), id);
430+
fn migrate_legacy_id(
431+
json: &mut Map<String, Value>,
432+
legacy_id_key: &str,
433+
node_type_str: &str,
434+
) -> bool {
435+
if json.contains_key(legacy_id_key) {
436+
if let Some(id) = json.remove(legacy_id_key) {
437+
json.insert("node_id".to_string(), id);
438+
json.insert(
439+
"version".to_string(),
440+
Value::String(DEFAULT_VERSION.to_string()),
441+
);
442+
}
424443
json.insert(
425-
"version".to_string(),
426-
Value::String(DEFAULT_VERSION.to_string()),
444+
"node_type".to_string(),
445+
Value::String(node_type_str.to_string()),
427446
);
447+
true
448+
} else {
449+
false
428450
}
429-
json.insert(
430-
"node_type".to_string(),
431-
Value::String("ingestor".to_string()),
432-
);
433-
} else if json.contains_key("indexer_id") {
434-
// Migration: get indexer_id value, remove it, and add as node_id
435-
if let Some(id) = json.remove("indexer_id") {
436-
json.insert("node_id".to_string(), id);
437-
json.insert(
438-
"version".to_string(),
439-
Value::String(DEFAULT_VERSION.to_string()),
440-
);
441-
}
442-
json.insert(
443-
"node_type".to_string(),
444-
Value::String("indexer".to_string()),
445-
);
451+
}
452+
453+
if !migrate_legacy_id(&mut json, "ingestor_id", "ingestor") {
454+
migrate_legacy_id(&mut json, "indexer_id", "indexer");
446455
}
447456
}
448457
// Determine node type and perform migration if needed

0 commit comments

Comments
 (0)