From c036fec06576d73a2a1dfc2579cee1dc33afee90 Mon Sep 17 00:00:00 2001 From: Erik Grinaker Date: Thu, 13 Mar 2025 15:28:42 +0100 Subject: [PATCH] pageserver: enable `compaction_l0_first` by default (#11212) ## Problem `compaction_l0_first` has already been enabled in production for a couple of weeks. ## Summary of changes Enable `compaction_l0_first` by default. Also set `CompactFlags::NoYield` in `timeline_checkpoint_handler`, to ensure explicitly requested compaction runs to completion. This endpoint is mainly used in tests, and caused some flakiness where tests expected compaction to complete. --- libs/pageserver_api/src/config.rs | 9 ++++++--- pageserver/src/http/routes.rs | 1 + 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/libs/pageserver_api/src/config.rs b/libs/pageserver_api/src/config.rs index ce7de1e0c7..6e457823dd 100644 --- a/libs/pageserver_api/src/config.rs +++ b/libs/pageserver_api/src/config.rs @@ -272,10 +272,11 @@ pub struct TenantConfigToml { /// size exceeds `compaction_upper_limit * checkpoint_distance`. pub compaction_upper_limit: usize, pub compaction_algorithm: crate::models::CompactionAlgorithmSettings, - /// If true, compact down L0 across all tenant timelines before doing regular compaction. + /// If true, compact down L0 across all tenant timelines before doing regular compaction. L0 + /// compaction must be responsive to avoid read amp during heavy ingestion. Defaults to true. pub compaction_l0_first: bool, /// If true, use a separate semaphore (i.e. concurrency limit) for the L0 compaction pass. Only - /// has an effect if `compaction_l0_first` is `true`. + /// has an effect if `compaction_l0_first` is true. Defaults to true. pub compaction_l0_semaphore: bool, /// Level0 delta layer threshold at which to delay layer flushes for compaction backpressure, /// such that they take 2x as long, and start waiting for layer flushes during ephemeral layer @@ -567,7 +568,9 @@ pub mod tenant_conf_defaults { // be reduced later by optimizing L0 hole calculation to avoid loading all keys into memory). So // with this config, we can get a maximum peak compaction usage of 9 GB. pub const DEFAULT_COMPACTION_UPPER_LIMIT: usize = 20; - pub const DEFAULT_COMPACTION_L0_FIRST: bool = false; + // Enable L0 compaction pass and semaphore by default. L0 compaction must be responsive to avoid + // read amp. + pub const DEFAULT_COMPACTION_L0_FIRST: bool = true; pub const DEFAULT_COMPACTION_L0_SEMAPHORE: bool = true; pub const DEFAULT_COMPACTION_ALGORITHM: crate::models::CompactionAlgorithm = diff --git a/pageserver/src/http/routes.rs b/pageserver/src/http/routes.rs index 44159aee0a..70c3cc8522 100644 --- a/pageserver/src/http/routes.rs +++ b/pageserver/src/http/routes.rs @@ -2392,6 +2392,7 @@ async fn timeline_checkpoint_handler( let state = get_state(&request); let mut flags = EnumSet::empty(); + flags |= CompactFlags::NoYield; // run compaction to completion if Some(true) == parse_query_param::<_, bool>(&request, "force_l0_compaction")? { flags |= CompactFlags::ForceL0Compaction; }