From b2286f5bcb1491227665d4fb6f35b229b8052e81 Mon Sep 17 00:00:00 2001 From: "Alex Chi Z." <4198311+skyzh@users.noreply.github.com> Date: Thu, 13 Mar 2025 10:38:45 -0400 Subject: [PATCH] fix(pageserver): don't panic if gc-compaction find no keys (#11200) ## Problem There was a panic on staging that compaction didn't find any keys. This is possible if all layers selected for compaction does not contain any keys within the current shard. ## Summary of changes Make panic an error. In the future, we can try creating an empty image layer so that GC can clean up those layers. Otherwise, for now, we can only rely on shard ancestor compaction to remove these data. Signed-off-by: Alex Chi Z --- pageserver/src/tenant/timeline/compaction.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pageserver/src/tenant/timeline/compaction.rs b/pageserver/src/tenant/timeline/compaction.rs index e6f2104e90..300daec9bf 100644 --- a/pageserver/src/tenant/timeline/compaction.rs +++ b/pageserver/src/tenant/timeline/compaction.rs @@ -3189,7 +3189,11 @@ impl Timeline { } // TODO: move the below part to the loop body - let last_key = last_key.expect("no keys produced during compaction"); + let Some(last_key) = last_key else { + return Err(CompactionError::Other(anyhow!( + "no keys produced during compaction" + ))); + }; stat.on_unique_key_visited(); let retention = self