Skip to content

Commit

Permalink
Implement garbage collection
Browse files Browse the repository at this point in the history
  • Loading branch information
Virv12 committed Dec 10, 2023
1 parent d8e9dc3 commit 31df7a4
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
21 changes: 21 additions & 0 deletions pixie-server/src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,26 @@ async fn image(
Ok(format!("{updated} computer(s) affected\n").customize())
}

#[get("/admin/gc")]
async fn gc(state: Data<State>) -> Result<impl Responder, Box<dyn Error>> {
let mut image_stats = state.image_stats.lock().await;
let mut chunk_stats = state.chunk_stats.lock().await;
let mut cnt = 0;
chunk_stats.retain(|k, v| {
if v.ref_cnt == 0 {
let path = state.storage_dir.join("chunks").join(hex::encode(k));
fs::remove_file(path).unwrap();
image_stats.total_csize -= v.csize;
image_stats.reclaimable -= v.csize;
cnt += 1;
false
} else {
true
}
});
Ok(format!("Removed {} chunks\n", cnt))
}

#[get("/admin/config")]
async fn get_config(state: Data<State>) -> Result<impl Responder, actix_web::Error> {
Ok(serde_json::to_string(&state.config))
Expand Down Expand Up @@ -188,6 +208,7 @@ pub async fn main(state: Arc<State>) -> Result<()> {
.app_data(data.clone())
.service(action)
.service(image)
.service(gc)
.service(get_config)
.service(get_units)
.service(get_hostmap)
Expand Down
4 changes: 2 additions & 2 deletions pixie-uefi/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ async fn server_discover(os: UefiOS) -> Result<Address> {
let msg = postcard::to_allocvec(&UdpRequest::Discover).unwrap();
loop {
socket.send([255; 4], ACTION_PORT, &msg).await?;
os.sleep_us(10_000_000).await;
os.sleep_us(1_000_000).await;
}
};

Expand Down Expand Up @@ -91,7 +91,7 @@ async fn run(os: UefiOS) -> Result<!> {
let udp_socket = os.udp_bind(None).await.unwrap();
loop {
udp_socket.send(server.ip, 4043, b"pixie").await.unwrap();
os.sleep_us(1_000_000).await;
os.sleep_us(10_000_000).await;
}
});

Expand Down
6 changes: 6 additions & 0 deletions pixie-web/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,12 @@ fn Images<'a, 'b, G: Html>(cx: Scope<'a>, images: &'a ReadSignal<ImageStat>) ->
tr {
td { "Reclaimable" }
td { (Bytes(images.get().reclaimable)) }
td { }
td {
button(id="reclaime", on:click=move |_| send_req("/admin/gc".into()) ) {
"Reclaim disk space"
}
}
}
}
}
Expand Down

0 comments on commit 31df7a4

Please sign in to comment.