Skip to content

Commit

Permalink
Make a single call to run_pending_tasks to evict as many entries as
Browse files Browse the repository at this point in the history
possible from the cache

Ensure the loop in the `do_run_pending_tasks` method is eventually stopped.
  • Loading branch information
tatsuya6502 committed Apr 16, 2024
1 parent 91c8497 commit c6a4d4b
Show file tree
Hide file tree
Showing 8 changed files with 208 additions and 111 deletions.
13 changes: 7 additions & 6 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ pub(crate) struct HousekeeperConfig {
pub(crate) maintenance_task_timeout: Duration,
/// The maximum repeat count for receiving operation logs from the read and write
/// log channels. Default: `MAX_LOG_SYNC_REPEATS`.
pub(crate) max_log_sync_repeats: usize,
pub(crate) max_log_sync_repeats: u32,
/// The batch size of entries to be processed by each internal eviction method.
/// Default: `EVICTION_BATCH_SIZE`.
pub(crate) eviction_batch_size: usize,
pub(crate) eviction_batch_size: u32,
}

impl Default for HousekeeperConfig {
Expand All @@ -88,7 +88,7 @@ impl Default for HousekeeperConfig {
maintenance_task_timeout: Duration::from_millis(
DEFAULT_MAINTENANCE_TASK_TIMEOUT_MILLIS,
),
max_log_sync_repeats: DEFAULT_MAX_LOG_SYNC_REPEATS,
max_log_sync_repeats: DEFAULT_MAX_LOG_SYNC_REPEATS as u32,
eviction_batch_size: DEFAULT_EVICTION_BATCH_SIZE,
}
}
Expand All @@ -98,14 +98,15 @@ impl HousekeeperConfig {
#[cfg(test)]
pub(crate) fn new(
maintenance_task_timeout: Option<Duration>,
max_log_sync_repeats: Option<usize>,
eviction_batch_size: Option<usize>,
max_log_sync_repeats: Option<u32>,
eviction_batch_size: Option<u32>,
) -> Self {
Self {
maintenance_task_timeout: maintenance_task_timeout.unwrap_or(Duration::from_millis(
DEFAULT_MAINTENANCE_TASK_TIMEOUT_MILLIS,
)),
max_log_sync_repeats: max_log_sync_repeats.unwrap_or(DEFAULT_MAX_LOG_SYNC_REPEATS),
max_log_sync_repeats: max_log_sync_repeats
.unwrap_or(DEFAULT_MAX_LOG_SYNC_REPEATS as u32),
eviction_batch_size: eviction_batch_size.unwrap_or(DEFAULT_EVICTION_BATCH_SIZE),
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/common/concurrent/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub(crate) const WRITE_LOG_CH_SIZE: usize =

// TODO: Calculate the batch size based on the number of entries in the cache (or an
// estimated number of entries to evict)
pub(crate) const DEFAULT_EVICTION_BATCH_SIZE: usize = WRITE_LOG_CH_SIZE;
pub(crate) const DEFAULT_EVICTION_BATCH_SIZE: u32 = WRITE_LOG_CH_SIZE as u32;

/// The default timeout duration for the `run_pending_tasks` method.
pub(crate) const DEFAULT_MAINTENANCE_TASK_TIMEOUT_MILLIS: u64 = 100;
Expand Down
11 changes: 6 additions & 5 deletions src/common/concurrent/housekeeper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ use std::{
};

pub(crate) trait InnerSync {
/// Runs the pending tasks. Returns `true` if there are more entries to evict.
/// Runs the pending tasks. Returns `true` if there are more entries to evict in
/// next run.
fn run_pending_tasks(
&self,
timeout: Option<Duration>,
max_log_sync_repeats: usize,
eviction_batch_size: usize,
max_log_sync_repeats: u32,
eviction_batch_size: u32,
) -> bool;

fn now(&self) -> Instant;
Expand All @@ -43,10 +44,10 @@ pub(crate) struct Housekeeper {
maintenance_task_timeout: Option<Duration>,
/// The maximum repeat count for receiving operation logs from the read and write
/// log channels. Default: `MAX_LOG_SYNC_REPEATS`.
max_log_sync_repeats: usize,
max_log_sync_repeats: u32,
/// The batch size of entries to be processed by each internal eviction method.
/// Default: `EVICTION_BATCH_SIZE`.
eviction_batch_size: usize,
eviction_batch_size: u32,
auto_run_enabled: AtomicBool,
}

Expand Down
Loading

0 comments on commit c6a4d4b

Please sign in to comment.