Skip to content

Commit 158dd59

Browse files
committed
add CompactedSegment::read_page
1 parent dcf8aad commit 158dd59

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

libsql-wal/src/segment/compacted.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use zerocopy::{AsBytes, FromBytes, FromZeroes};
66

77
use crate::io::buf::{IoBufMut, ZeroCopyBuf};
88
use crate::io::FileExt;
9+
use crate::segment::FrameHeader;
910
use crate::{LIBSQL_MAGIC, LIBSQL_PAGE_SIZE, LIBSQL_WAL_VERSION};
1011

1112
use super::{Frame, Result};
@@ -97,5 +98,18 @@ impl<F: FileExt> CompactedSegment<F> {
9798
let (buf, ret) = self.file.read_exact_at_async(buf, offset as u64).await;
9899
(buf, ret)
99100
}
101+
102+
pub(crate) async fn read_page<B: IoBufMut + Send + 'static>(
103+
&self,
104+
buf: B,
105+
offset: u32,
106+
) -> (B, io::Result<()>) {
107+
assert_eq!(buf.bytes_init(), 0);
108+
assert_eq!(buf.bytes_total(), LIBSQL_PAGE_SIZE as usize);
109+
let offset = size_of::<CompactedSegmentDataHeader>()
110+
+ size_of::<Frame>() * offset as usize
111+
+ size_of::<FrameHeader>();
112+
let (buf, ret) = self.file.read_exact_at_async(buf, offset as u64).await;
113+
(buf, ret)
100114
}
101115
}

0 commit comments

Comments
 (0)