review: remove save_buf_for_read

Signed-off-by: Yuchen Liang <yuchen@neon.tech>
This commit is contained in:
Yuchen Liang
2024-11-25 04:42:02 +00:00
parent 28718bfadc
commit 76f0e4fd1d
2 changed files with 6 additions and 22 deletions

View File

@@ -101,7 +101,7 @@ where
mut self,
ctx: &RequestContext,
) -> std::io::Result<(u64, Arc<W>)> {
self.flush(true, ctx).await?;
self.flush(ctx).await?;
let Self {
mutable: buf,
@@ -156,28 +156,21 @@ where
if let Some(control) = control.take() {
control.release().await;
}
control = self.flush(true, ctx).await?;
control = self.flush(ctx).await?;
}
}
Ok((chunk_len, control))
}
#[must_use = "caller must explcitly check the flush control"]
async fn flush(
&mut self,
save_buf_for_read: bool,
_ctx: &RequestContext,
) -> std::io::Result<Option<FlushControl>> {
async fn flush(&mut self, _ctx: &RequestContext) -> std::io::Result<Option<FlushControl>> {
let buf = self.mutable.take().expect("must not use after an error");
let buf_len = buf.pending();
if buf_len == 0 {
self.mutable = Some(buf);
return Ok(None);
}
let (recycled, flush_control) = self
.flush_handle
.flush(buf, self.bytes_submitted, save_buf_for_read)
.await?;
let (recycled, flush_control) = self.flush_handle.flush(buf, self.bytes_submitted).await?;
self.bytes_submitted += u64::try_from(buf_len).unwrap();
self.mutable = Some(recycled);
Ok(Some(flush_control))

View File

@@ -141,23 +141,14 @@ where
/// Returns a buffer that completed flushing for re-use, length reset to 0, capacity unchanged.
/// If `save_buf_for_read` is true, then we save the buffer in `Self::maybe_flushed`, otherwise
/// clear `maybe_flushed`.
pub async fn flush<B>(
&mut self,
buf: B,
offset: u64,
save_buf_for_read: bool,
) -> std::io::Result<(B, FlushControl)>
pub async fn flush<B>(&mut self, buf: B, offset: u64) -> std::io::Result<(B, FlushControl)>
where
B: Buffer<IoBuf = Buf> + Send + 'static,
{
let slice = buf.flush();
// Saves a buffer for read while flushing. This also removes reference to the old buffer.
self.maybe_flushed = if save_buf_for_read {
Some(slice.clone())
} else {
None
};
self.maybe_flushed = Some(slice.clone());
let (request, flush_control) = new_flush_op(slice, offset);