-
Notifications
You must be signed in to change notification settings - Fork 236
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5cfb62f
commit 056a01b
Showing
20 changed files
with
1,304 additions
and
70 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
[package] | ||
name = "libsql-wal" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
bytes = "1.6.0" | ||
fst = "0.4.7" | ||
hashbrown = "0.14.3" | ||
libsql-sys = { path = "../libsql-sys", features = ["rusqlite"] } | ||
memmap = "0.7.0" | ||
memoffset = "0.9.1" | ||
mmap = "0.1.1" | ||
nix = { version = "0.28.0", features = ["uio", "fs"] } | ||
parking_lot = "0.12.1" | ||
tokio = { version = "1.36.0", features = ["full"] } | ||
tracing = "0.1.40" | ||
tracing-subscriber = { version = "0.3.18", features = ["env-filter", "time"] } | ||
walkdir = "2.5.0" | ||
zerocopy = { version = "0.7.32", features = ["derive"] } | ||
|
||
[dev-dependencies] | ||
tempfile = "3.10.1" |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
use std::io; | ||
use std::io::ErrorKind; | ||
use std::io::IoSlice; | ||
use std::io::Result; | ||
|
||
use std::fs::File; | ||
use std::io::Write; | ||
|
||
pub trait FileExt { | ||
fn write_all_at(&self, buf: &[u8], offset: u64) -> Result<()>; | ||
fn write_at_vectored(&self, bufs: &[IoSlice], offset: u64) -> Result<usize>; | ||
fn write_at(&self, buf: &[u8], offset: u64) -> Result<usize>; | ||
|
||
fn read_exact_at(&self, buf: &mut [u8], offset: u64) -> Result<()>; | ||
|
||
fn cursor(&self, offset: u64) -> Cursor<Self> where Self: Sized { | ||
Cursor { file: self, offset } | ||
} | ||
} | ||
|
||
impl FileExt for File { | ||
fn write_all_at(&self, buf: &[u8], offset: u64) -> Result<()> { | ||
let mut written = 0; | ||
|
||
while written != buf.len() { | ||
written += nix::sys::uio::pwrite(self, &buf[written..], offset as _)?; | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
fn write_at_vectored(&self, bufs: &[IoSlice], offset: u64) -> Result<usize> { | ||
Ok(nix::sys::uio::pwritev(self, bufs, offset as _)?) | ||
} | ||
|
||
|
||
fn write_at(&self, buf: &[u8], offset: u64) -> Result<usize> { | ||
Ok(nix::sys::uio::pwrite(self, buf, offset as _)?) | ||
} | ||
|
||
fn read_exact_at(&self, buf: &mut [u8], offset: u64) -> Result<()> { | ||
let mut read = 0; | ||
|
||
while read != buf.len() { | ||
let n = nix::sys::uio::pread(self, &mut buf[read..], (offset + read as u64) as _)?; | ||
if n == 0 { | ||
return Err(io::Error::new(ErrorKind::UnexpectedEof, "unexpected end-of-file")) | ||
} | ||
read += n; | ||
|
||
} | ||
|
||
Ok(()) | ||
} | ||
} | ||
|
||
pub struct Cursor<'a, T> { | ||
file: &'a T, | ||
offset: u64, | ||
} | ||
|
||
impl<'a, T: FileExt> Write for Cursor<'a, T> { | ||
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> { | ||
let count = self.file.write_at(buf, self.offset)?; | ||
self.offset += count as u64; | ||
Ok(count) | ||
} | ||
|
||
fn flush(&mut self) -> std::io::Result<()> { | ||
Ok(()) | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
pub mod shared_wal; | ||
pub mod log; | ||
pub mod segment; | ||
pub mod file; | ||
pub mod wal; | ||
pub mod transaction; | ||
pub mod registry; | ||
pub mod name; |
Oops, something went wrong.