Skip to content

Commit

Permalink
Merge pull request #243 from superfly/debug-cleared-ts
Browse files Browse the repository at this point in the history
Make wal_threshold configurable
  • Loading branch information
somtochiama authored Aug 21, 2024
2 parents 6608e78 + d0a385f commit 8617910
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
7 changes: 4 additions & 3 deletions crates/corro-agent/src/agent/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -462,15 +462,16 @@ async fn vacuum_db(pool: &SplitPool, lim: u64) -> eyre::Result<()> {
/// See `db_cleanup` and `vacuum_db`
pub fn spawn_handle_db_maintenance(agent: &Agent) {
let mut wal_path = agent.config().db.path.clone();
let wal_threshold = agent.config().perf.wal_threshold_gb as u64;
wal_path.set_extension(format!("{}-wal", wal_path.extension().unwrap_or_default()));

let pool = agent.pool().clone();

tokio::spawn(async move {
const TRUNCATE_WAL_THRESHOLD: u64 = 5 * 1024 * 1024 * 1024;
let truncate_wal_threshold: u64 = wal_threshold * 1024 * 1024 * 1024;

// try to initially truncate the WAL
match wal_checkpoint_over_threshold(wal_path.as_path(), &pool, TRUNCATE_WAL_THRESHOLD).await
match wal_checkpoint_over_threshold(wal_path.as_path(), &pool, truncate_wal_threshold).await
{
Ok(truncated) if truncated => {
info!("initially truncated WAL");
Expand All @@ -495,7 +496,7 @@ pub fn spawn_handle_db_maintenance(agent: &Agent) {
}

if let Err(e) =
wal_checkpoint_over_threshold(wal_path.as_path(), &pool, TRUNCATE_WAL_THRESHOLD)
wal_checkpoint_over_threshold(wal_path.as_path(), &pool, truncate_wal_threshold)
.await
{
error!("could not wal_checkpoint truncate: {e}");
Expand Down
7 changes: 7 additions & 0 deletions crates/corro-types/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ const fn default_apply_queue() -> usize {
100
}

const fn default_wal_threshold() -> usize {
10
}

/// Used for the apply channel
const fn default_huge_channel() -> usize {
2048
Expand Down Expand Up @@ -181,6 +185,8 @@ pub struct PerfConfig {
pub apply_queue_timeout: usize,
#[serde(default = "default_apply_queue")]
pub apply_queue_len: usize,
#[serde(default = "default_wal_threshold")]
pub wal_threshold_gb: usize,
}

impl Default for PerfConfig {
Expand All @@ -197,6 +203,7 @@ impl Default for PerfConfig {
foca_channel_len: default_small_channel(),
apply_queue_timeout: default_apply_timeout(),
apply_queue_len: default_apply_queue(),
wal_threshold_gb: default_wal_threshold(),
}
}
}
Expand Down

0 comments on commit 8617910

Please sign in to comment.