Skip to content

Commit 41d17fa

Browse files
authored
Merge pull request #108 from silicon-heaven/serialize-dirtylog-trim
dirtylog: Serialize Trim requests
2 parents 39bd581 + b8aebbe commit 41d17fa

3 files changed

Lines changed: 22 additions & 4 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "historyprovider"
33
description = "historyprovider-rs"
44
license = "MIT"
55
repository = "https://github.com/silicon-heaven/historyprovider-rs"
6-
version = "2.8.3"
6+
version = "2.9.0"
77
edition = "2024"
88

99
[[bin]]

src/dirtylog.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,11 +261,23 @@ pub(crate) async fn dirtylog_task(
261261

262262
let mut request_scheduler = RequestScheduler::new(Path::new(&app_state.config.journal_dir).into());
263263

264+
// Priority-based execution:
265+
// 1. High Priority: Get, ProcessNotification (Optimizes getLog responsiveness)
266+
// 2. Low Priority: Trim (Processed sequentially)
267+
let mut trim_requests = VecDeque::new();
268+
264269
loop {
265-
futures::select! {
270+
futures::select_biased! {
266271
command = cmd_rx.select_next_some() => match command {
267272
DirtyLogCommand::Trim { site } => {
268-
request_scheduler.schedule_new(site, Request::Trim);
273+
if !trim_requests.contains(&site) {
274+
trim_requests.push_back(site);
275+
}
276+
// Schedule Trim only if there is no other request in the scheduler
277+
if request_scheduler.inflight.is_empty()
278+
&& let Some(site) = trim_requests.pop_front() {
279+
request_scheduler.schedule_new(site, Request::Trim);
280+
}
269281
}
270282
DirtyLogCommand::Get { site, response_tx } => {
271283
request_scheduler.schedule_new(site, Request::Get(response_tx));
@@ -290,6 +302,12 @@ pub(crate) async fn dirtylog_task(
290302
},
291303
site = request_scheduler.inflight.select_next_some() => {
292304
request_scheduler.on_finished(site);
305+
// If no other requests have been scheduled, we can process another Trim
306+
if request_scheduler.inflight.is_empty()
307+
&& let Some(site) = trim_requests.pop_front() {
308+
request_scheduler.schedule_new(site, Request::Trim);
309+
}
310+
293311
}
294312
complete => break,
295313
}

0 commit comments

Comments
 (0)