Skip to content

Commit 8e919ad

Browse files
Istrate Andrei-EduardIstrate Andrei-Eduard
authored andcommitted
Improve error handling and logging for removing old snapshots
1 parent ec893d4 commit 8e919ad

2 files changed

Lines changed: 8 additions & 6 deletions

File tree

src/main.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ fn merge_global_store(
6262
#[actix_web::main]
6363
async fn main() -> std::io::Result<()> {
6464
dotenvy::dotenv().unwrap();
65-
// Usage: <program> <current_node_address> [join_node_address]
6665
let args: Vec<String> = env::args().collect();
6766
if args.len() < 2 {
6867
eprintln!("Usage: {} <current_node_address> [join_node_address]", args[0]);
@@ -86,7 +85,6 @@ async fn main() -> std::io::Result<()> {
8685
});
8786
let _ = APP_STATE.set(state.clone());
8887

89-
// Load cold storage (snapshot + WAL replay) from disk.
9088
match load_all_tables(&state).await {
9189
Ok(_) => println!("Cold storage loaded"),
9290
Err(e) => eprintln!("Error loading cold storage: {}", e),
@@ -115,7 +113,7 @@ async fn main() -> std::io::Result<()> {
115113

116114
// Send join request.
117115
let client = reqwest::Client::new();
118-
let join_url = format!("http://{}/join", join_node);
116+
let join_url = format!("{}/join", join_node);
119117
match client
120118
.post(&join_url)
121119
.json(&json!({
@@ -143,7 +141,7 @@ async fn main() -> std::io::Result<()> {
143141

144142

145143
// Pull the remote state for all tables.
146-
let store_url = format!("http://{}/store", join_node);
144+
let store_url = format!("{}/store", join_node);
147145
match client.get(&store_url).header("x-api-key", std::env::var("CLUSTER_SECRET").unwrap_or_default()).send().await {
148146
Ok(resp) => {
149147
if resp.status().is_success() {

src/storage/snapshoting.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use actix_web::web::Data;
2+
use log::warn;
23
use serde_json;
34
use std::{env, io, path::PathBuf, time::SystemTime};
45
use tokio::{fs, time::{self, Duration}};
@@ -35,7 +36,10 @@ async fn clean_old_snapshots(dir: &PathBuf, max_snapshots: usize)
3536
.into_iter()
3637
.take(snaps_cloned.len() - max_snapshots)
3738
{
38-
let _ = fs::remove_file(old).await;
39+
match fs::remove_file(&old).await {
40+
Ok(_) => { println!("Removed old snapshot from path: {}", old.to_str().unwrap())},
41+
Err(error) => {warn!("{:}", error)}
42+
};
3943
}
4044
}
4145
Ok(())
@@ -62,7 +66,7 @@ pub fn start_snapshot_task(states: &Data<AppState>) {
6266
return;
6367
}
6468

65-
let mut ticker = time::interval(Duration::from_secs(60 * 60));
69+
let mut ticker = time::interval(Duration::from_secs(3600));
6670
loop {
6771
ticker.tick().await;
6872
let ts = current_timestamp();

0 commit comments

Comments
 (0)