Revert "try a closure approach, also has same error "Send is not general enough""

This reverts commit ef2b384cf8.
This commit is contained in:
Christian Schwarz
2024-08-20 10:07:07 +00:00
parent ef2b384cf8
commit 521da324ab
2 changed files with 31 additions and 9 deletions

View File

@@ -319,10 +319,11 @@ impl InMemoryLayer {
// Execute the read.
vectored_dio_read::execute(
|_, _| async move { todo!() },
&inner.file,
reads
.iter()
.flat_map(|(_, value_reads)| value_reads.iter().map(|v| &v.read)),
&ctx,
)
.await;
@@ -359,6 +360,17 @@ impl InMemoryLayer {
}
}
impl vectored_dio_read::File for EphemeralFile {
async fn read_at_to_end<'a, 'b, B: tokio_epoll_uring::IoBufMut + Send>(
&'b self,
start: u32,
dst: tokio_epoll_uring::Slice<B>,
ctx: &'a RequestContext,
) -> std::io::Result<(tokio_epoll_uring::Slice<B>, usize)> {
EphemeralFile::read_at_to_end(self, start, dst, ctx).await
}
}
fn inmem_layer_display(mut f: impl Write, start_lsn: Lsn, end_lsn: Lsn) -> std::fmt::Result {
write!(f, "inmem-{:016X}-{:016X}", start_lsn.0, end_lsn.0)
}

View File

@@ -8,6 +8,15 @@ use tokio_epoll_uring::{BoundedBuf, IoBufMut, Slice};
use crate::context::RequestContext;
pub trait File {
async fn read_at_to_end<'a, 'b, B: IoBufMut + Send>(
&'b self,
start: u32,
dst: Slice<B>,
ctx: &'a RequestContext,
) -> std::io::Result<(Slice<B>, usize)>;
}
trait Sealed {}
pub trait Buffer: Sealed + std::ops::Deref<Target = [u8]> {
@@ -71,11 +80,10 @@ impl Buffer for Vec<u8> {
}
}
pub async fn execute<'a, 'b, I, F, Fut, B>(file: F, reads: I)
pub async fn execute<'a, 'b, 'c, I, F, B>(file: &'c F, reads: I, ctx: &'b RequestContext)
where
I: IntoIterator<Item = &'a ValueRead<B>> + Send,
F: Fn(u32, Slice<Vec<u8>>) -> Fut + Send,
Fut: std::future::Future<Output = Result<(Slice<Vec<u8>>, usize), Arc<std::io::Error>>> + Send,
F: File + Send,
B: Buffer + IoBufMut + Send,
{
const DIO_CHUNK_SIZE: usize = 512;
@@ -198,11 +206,13 @@ where
if all_done {
continue;
}
let (merged_read_buf_slice, nread) = match file(
start_chunk_no * DIO_CHUNK_SIZE as u32,
get_chunk_buf(nchunks).slice_full(),
)
.await
let (merged_read_buf_slice, nread) = match file
.read_at_to_end(
start_chunk_no * DIO_CHUNK_SIZE as u32,
get_chunk_buf(nchunks).slice_full(),
ctx,
)
.await
{
Ok(t) => t,
Err(e) => {