From 0f63c957a683f8771c8fc5bc30d2db9b29e4a58e Mon Sep 17 00:00:00 2001 From: Yuchen Liang Date: Wed, 20 Nov 2024 16:18:21 +0000 Subject: [PATCH] document and reorder flush background task invokation sequence Signed-off-by: Yuchen Liang --- .../src/virtual_file/owned_buffers_io/write/flush.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/pageserver/src/virtual_file/owned_buffers_io/write/flush.rs b/pageserver/src/virtual_file/owned_buffers_io/write/flush.rs index 4c2019076e..bd45ed33a4 100644 --- a/pageserver/src/virtual_file/owned_buffers_io/write/flush.rs +++ b/pageserver/src/virtual_file/owned_buffers_io/write/flush.rs @@ -127,14 +127,19 @@ where W: OwnedAsyncWriter + Send + Sync + 'static + std::fmt::Debug, { /// Spawns a new background flush task and obtains a handle. + /// + /// Note: The background task so we do not need to explicitly maintain a queue of buffers. pub fn spawn_new(file: Arc, buf: B, ctx: RequestContext) -> Self where B: Buffer + Send + 'static, { - let (front, back) = duplex::mpsc::channel(1); + let (front, back) = duplex::mpsc::channel(2); - let bg = FlushBackgroundTask::new(back, file, ctx); - let join_handle = tokio::spawn(async move { bg.run(buf.flush()).await }); + let join_handle = tokio::spawn(async move { + FlushBackgroundTask::new(back, file, ctx) + .run(buf.flush()) + .await + }); FlushHandle { inner: Some(FlushHandleInner { @@ -239,6 +244,7 @@ where } /// Runs the background flush task. + /// The passed in slice is immediately sent back to the flush handle through the duplex channel. async fn run(mut self, slice: FullSlice) -> std::io::Result> { // Sends the extra buffer back to the handle. self.channel.send(slice).await.map_err(|_| {