From df49a9b7aa9900b5c7d785d4300a955cb9030d76 Mon Sep 17 00:00:00 2001 From: John Spray Date: Wed, 2 Aug 2023 19:31:09 +0100 Subject: [PATCH] pagekeeper: suppress error logs in shutdown/detach (#4876) ## Problem Error messages like this coming up during normal operations: ``` Compaction failed, retrying in 2s: timeline is Stopping Compaction failed, retrying in 2s: Cannot run compaction iteration on inactive tenant ``` ## Summary of changes Add explicit handling for the shutdown case in these locations, to suppress error logs. --- pageserver/src/tenant/tasks.rs | 5 +++++ pageserver/src/tenant/timeline.rs | 8 +++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/pageserver/src/tenant/tasks.rs b/pageserver/src/tenant/tasks.rs index a758d4da23ec..6400eb7cbe78 100644 --- a/pageserver/src/tenant/tasks.rs +++ b/pageserver/src/tenant/tasks.rs @@ -103,6 +103,11 @@ async fn compaction_loop(tenant: Arc, cancel: CancellationToken) { } } + if cancel.is_cancelled() { + info!("received cancellation request"); + break; + } + let started_at = Instant::now(); let sleep_duration = if period == Duration::ZERO { diff --git a/pageserver/src/tenant/timeline.rs b/pageserver/src/tenant/timeline.rs index 647c9b7b0ec5..e2f10bb4f88a 100644 --- a/pageserver/src/tenant/timeline.rs +++ b/pageserver/src/tenant/timeline.rs @@ -697,6 +697,9 @@ impl Timeline { Err(CompactionError::DownloadRequired(rls)) => { anyhow::bail!("Compaction requires downloading multiple times (last was {} layers), possibly battling against eviction", rls.len()) } + Err(CompactionError::ShuttingDown) => { + return Ok(()); + } Err(CompactionError::Other(e)) => { return Err(e); } @@ -778,7 +781,8 @@ impl Timeline { let layer_removal_cs = Arc::new(self.layer_removal_cs.clone().lock_owned().await); // Is the timeline being deleted? if self.is_stopping() { - return Err(anyhow::anyhow!("timeline is Stopping").into()); + trace!("Dropping out of compaction on timeline shutdown"); + return Err(CompactionError::ShuttingDown); } let target_file_size = self.get_checkpoint_distance(); @@ -3235,6 +3239,8 @@ enum CompactionError { /// This should not happen repeatedly, but will be retried once by top-level /// `Timeline::compact`. DownloadRequired(Vec>), + /// The timeline or pageserver is shutting down + ShuttingDown, /// Compaction cannot be done right now; page reconstruction and so on. Other(anyhow::Error), }