From d37e90f43043032a0705472f1eda88c4ebb01147 Mon Sep 17 00:00:00 2001 From: "Alex Chi Z." <4198311+skyzh@users.noreply.github.com> Date: Mon, 7 Apr 2025 12:01:21 -0400 Subject: [PATCH] fix(pageserver): allow shard ancestor compaction to be cancelled (#11452) ## Problem https://github.com/neondatabase/neon/issues/11330 https://github.com/neondatabase/neon/issues/11358 ## Summary of changes Looking at the staging log, a few tenants right after shard split are stuck on shutdown because they are running shard ancestor compaction. The compaction does not respect the cancellation token. Signed-off-by: Alex Chi Z --- pageserver/src/tenant/timeline/compaction.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pageserver/src/tenant/timeline/compaction.rs b/pageserver/src/tenant/timeline/compaction.rs index 5aaef8db0c..73f6691f14 100644 --- a/pageserver/src/tenant/timeline/compaction.rs +++ b/pageserver/src/tenant/timeline/compaction.rs @@ -1244,6 +1244,10 @@ impl Timeline { let mut replace_image_layers = Vec::new(); for layer in layers_to_rewrite { + if self.cancel.is_cancelled() { + return Err(CompactionError::ShuttingDown); + } + tracing::info!(layer=%layer, "Rewriting layer after shard split..."); let mut image_layer_writer = ImageLayerWriter::new( self.conf,