From 95bb6ce2e4de68baf5178cc1ad49090634fe4e79 Mon Sep 17 00:00:00 2001 From: Vlad Lazar Date: Thu, 26 Jun 2025 11:11:05 +0200 Subject: [PATCH] another fix --- pageserver/src/tenant/timeline.rs | 36 +++++++++---------------------- 1 file changed, 10 insertions(+), 26 deletions(-) diff --git a/pageserver/src/tenant/timeline.rs b/pageserver/src/tenant/timeline.rs index 0d05bfd406..db0db442c3 100644 --- a/pageserver/src/tenant/timeline.rs +++ b/pageserver/src/tenant/timeline.rs @@ -4674,6 +4674,7 @@ impl Timeline { }; info!("started flush loop"); + loop { tokio::select! { _ = self.cancel.cancelled() => { @@ -4688,13 +4689,12 @@ impl Timeline { // The highest LSN to which we flushed in the loop over frozen layers let mut flushed_to_lsn = Lsn(0); - let result = loop { + // Force not bailing early by wrapping the code into a closure. + #[allow(clippy::redundant_closure_call)] + let result = (async || { loop { if self.cancel.is_cancelled() { info!("dropping out of flush loop for timeline shutdown"); - // Note: we do not bother transmitting into [`layer_flush_done_tx`], because - // anyone waiting on that will respect self.cancel as well: they will stop - // waiting at the same time we as drop out of this loop. - return; + break Err(FlushLayerError::Cancelled); } // Break to notify potential waiters as soon as we've flushed the requested LSN. If @@ -4707,16 +4707,8 @@ impl Timeline { let (layer, l0_count, frozen_count, frozen_size) = { let layers = self.layers.read(LayerManagerLockHolder::FlushLoop).await; let Ok(lm) = layers.layer_map() else { - if self.cancel.is_cancelled() { - info!("dropping out of flush loop for timeline shutdown"); - } else { - info!("dropping out of flush loop for layer map shutdown"); - let _ = self - .layer_flush_done_tx - .send_replace((flush_counter, Err(FlushLayerError::Cancelled))); - } - - return; + info!("dropping out of flush loop for layer map shutdown"); + break Err(FlushLayerError::Cancelled); }; let l0_count = lm.level0_deltas().len(); let frozen_count = lm.frozen_layers.len(); @@ -4764,16 +4756,8 @@ impl Timeline { match self.flush_frozen_layer(layer, ctx).await { Ok(layer_lsn) => flushed_to_lsn = max(flushed_to_lsn, layer_lsn), Err(FlushLayerError::Cancelled) => { - if self.cancel.is_cancelled() { - info!("dropping out of flush loop for timeline shutdown"); - } else { - info!("dropping out of flush loop for remote client shutdown"); - let _ = self - .layer_flush_done_tx - .send_replace((flush_counter, Err(FlushLayerError::Cancelled))); - } - - return; + info!("dropping out of flush loop for remote client shutdown"); + break Err(FlushLayerError::Cancelled); } err @ Err( FlushLayerError::NotRunning(_) @@ -4814,7 +4798,7 @@ impl Timeline { } } } - }; + }})().await; // Unsharded tenants should never advance their LSN beyond the end of the // highest layer they write: such gaps between layer data and the frozen LSN