Skip to content

Commit d460eaf

Browse files
committed
Fix db-refresh lock issue, add --no-refresh flag, improve logging
Bug Fixes: - Fixed 'database is locked' error in 'monocle config db-refresh' (Issue #90) by removing redundant database connections in do_refresh function New Features: - Added global --no-refresh flag to disable automatic data refresh - Added [monocle] prefix to all auto-refresh log messages for better visibility - RPKI ASPA command now ensures ASInfo data is available for AS name enrichment Improvements: - Added comprehensive tests for database initialization with mock data
1 parent 99cb5df commit d460eaf

File tree

11 files changed

+412
-223
lines changed

11 files changed

+412
-223
lines changed

CHANGELOG.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,36 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
## Unreleased
6+
7+
### Bug Fixes
8+
9+
* Fixed "database is locked" error in `monocle config db-refresh` command (Issue #90)
10+
* The `do_refresh` function was opening redundant database connections for ASInfo and AS2Rel data sources
11+
* Now correctly uses the already-passed database connection parameter
12+
13+
### New Features
14+
15+
* Added global `--no-refresh` flag to disable automatic data refresh
16+
* Use `monocle --no-refresh <command>` to skip all automatic data loading/refresh
17+
* Useful when you want to use existing cached data only
18+
* Shows warnings when data is missing or stale instead of auto-refreshing
19+
20+
* Added `[monocle]` prefix to all auto-refresh log messages
21+
* Makes it easier to distinguish monocle's internal logging from main output
22+
* Especially useful when refresh operations run automatically during commands
23+
24+
* RPKI ASPA command now ensures ASInfo data is available for AS name enrichment
25+
* Automatically loads ASInfo data before showing ASPA output
26+
* AS names and countries are displayed in ASPA results
27+
28+
### Improvements
29+
30+
* Added comprehensive tests for database initialization with mock data
31+
* Tests for all repositories being accessible after initialization
32+
* Tests for schema version verification
33+
* Tests for RPKI and Pfx2as mock data storage/retrieval
34+
535
## v1.0.1 - 2025-12-18
636

737
### Bug Fixes

Cargo.lock

Lines changed: 12 additions & 89 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ lens-bgpkit = [
116116
"dep:itertools",
117117
"dep:radar-rs",
118118
"dep:rayon",
119-
"dep:ureq",
120119
]
121120

122121
# Full lens layer - all lenses including InspectLens
@@ -170,7 +169,7 @@ tracing = "0.1"
170169
# Database dependencies (optional but commonly needed)
171170
# =============================================================================
172171
ipnet = { version = "2.10", features = ["json"], optional = true }
173-
oneio = { version = "0.20.0", default-features = false, features = ["https", "gz", "bz", "json"], optional = true }
172+
oneio = { version = "0.20.1", default-features = false, features = ["https", "gz", "bz", "json"], optional = true }
174173

175174
# =============================================================================
176175
# Lens-core dependencies (optional)
@@ -188,7 +187,6 @@ bgpkit-commons = { version = "0.10.1", features = ["asinfo", "rpki", "countries"
188187
itertools = { version = "0.14", optional = true }
189188
radar-rs = { version = "0.1.0", optional = true }
190189
rayon = { version = "1.8", optional = true }
191-
ureq = { version = "3.1", features = ["json"], optional = true }
192190

193191
# =============================================================================
194192
# Display dependencies (optional)

src/bin/commands/as2rel.rs

Lines changed: 64 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,12 @@ pub struct As2relArgs {
4040
pub show_full_name: bool,
4141
}
4242

43-
pub fn run(config: &MonocleConfig, args: As2relArgs, output_format: OutputFormat) {
43+
pub fn run(
44+
config: &MonocleConfig,
45+
args: As2relArgs,
46+
output_format: OutputFormat,
47+
no_refresh: bool,
48+
) {
4449
let As2relArgs {
4550
asns,
4651
update,
@@ -64,43 +69,50 @@ pub fn run(config: &MonocleConfig, args: As2relArgs, output_format: OutputFormat
6469

6570
// Handle explicit updates
6671
if update || update_with.is_some() {
67-
eprintln!("Updating AS2rel data...");
72+
if no_refresh {
73+
eprintln!("[monocle] Warning: --update ignored because --no-refresh is set");
74+
} else {
75+
eprintln!("[monocle] Updating AS2rel data...");
6876

69-
let db = match MonocleDatabase::open(&sqlite_path) {
70-
Ok(db) => db,
71-
Err(e) => {
72-
eprintln!("Failed to open database: {}", e);
73-
std::process::exit(1);
77+
let db = match MonocleDatabase::open(&sqlite_path) {
78+
Ok(db) => db,
79+
Err(e) => {
80+
eprintln!("Failed to open database: {}", e);
81+
std::process::exit(1);
82+
}
83+
};
84+
85+
let lens = As2relLens::new(&db);
86+
let result = match &update_with {
87+
Some(path) => lens.update_from(path),
88+
None => lens.update(),
89+
};
90+
91+
match result {
92+
Ok(count) => {
93+
eprintln!(
94+
"[monocle] AS2rel data updated: {} relationships loaded",
95+
count
96+
);
97+
}
98+
Err(e) => {
99+
eprintln!("[monocle] Failed to update AS2rel data: {}", e);
100+
std::process::exit(1);
101+
}
74102
}
75-
};
76-
77-
let lens = As2relLens::new(&db);
78-
let result = match &update_with {
79-
Some(path) => lens.update_from(path),
80-
None => lens.update(),
81-
};
82103

83-
match result {
84-
Ok(count) => {
85-
eprintln!("AS2rel data updated: {} relationships loaded", count);
86-
}
87-
Err(e) => {
88-
eprintln!("Failed to update AS2rel data: {}", e);
89-
std::process::exit(1);
90-
}
104+
// Continue with query using the same connection
105+
run_query(
106+
&db,
107+
&asns,
108+
sort_by_asn,
109+
show_name,
110+
show_full_name,
111+
no_explain,
112+
output_format,
113+
);
114+
return;
91115
}
92-
93-
// Continue with query using the same connection
94-
run_query(
95-
&db,
96-
&asns,
97-
sort_by_asn,
98-
show_name,
99-
show_full_name,
100-
no_explain,
101-
output_format,
102-
);
103-
return;
104116
}
105117

106118
// Open the database
@@ -116,15 +128,25 @@ pub fn run(config: &MonocleConfig, args: As2relArgs, output_format: OutputFormat
116128

117129
// Check if data needs to be initialized or updated automatically
118130
if lens.needs_update() {
119-
eprintln!("AS2rel data is empty or outdated, updating now...");
131+
if no_refresh {
132+
eprintln!(
133+
"[monocle] Warning: AS2rel data is empty or outdated. Results may be incomplete."
134+
);
135+
eprintln!("[monocle] Run without --no-refresh or use 'monocle config db-refresh --as2rel' to load data.");
136+
} else {
137+
eprintln!("[monocle] AS2rel data is empty or outdated, updating now...");
120138

121-
match lens.update() {
122-
Ok(count) => {
123-
eprintln!("AS2rel data updated: {} relationships loaded", count);
124-
}
125-
Err(e) => {
126-
eprintln!("Failed to update AS2rel data: {}", e);
127-
std::process::exit(1);
139+
match lens.update() {
140+
Ok(count) => {
141+
eprintln!(
142+
"[monocle] AS2rel data updated: {} relationships loaded",
143+
count
144+
);
145+
}
146+
Err(e) => {
147+
eprintln!("[monocle] Failed to update AS2rel data: {}", e);
148+
std::process::exit(1);
149+
}
128150
}
129151
}
130152
}

0 commit comments

Comments
 (0)