Skip to content

Commit

Permalink
Use tokio-uring and kioto-uring-executor from crates.io (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kai Mast authored and kaimast committed Jul 22, 2024
1 parent ed6cc25 commit 904a628
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 53 deletions.
68 changes: 29 additions & 39 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "lsm"
version = "0.3.0"
version = "0.4.0"
authors = ["Kai Mast <kai@kaimast.com>"]
edition = "2021"
repository = "https://github.com/kaimast/lsm-rs"
Expand All @@ -23,9 +23,8 @@ cfg-if = "1"
tracing = { version="0.1", default-features=false, features=["attributes"] }
csv = "1"
tokio-condvar = { version="0.3", features=["parking_lot"] }
#tokio-uring = { version="0.4", optional=true }
tokio-uring = { git="https://github.com/kaimast/tokio-uring.git", features=["mmap"], optional=true }
tokio-uring-executor = { git="https://github.com/kaimast/tokio-uring-executor.git", optional=true }
tokio-uring = { version="0.5", optional=true }
tokio-uring-executor = { package="kioto-uring-executor", version="0.1", optional=true }
bloomfilter = { version="1", optional=true }

[dependencies.tokio]
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2021 Kai Mast
Copyright (c) 2024 Kai Mast

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
3 changes: 2 additions & 1 deletion NEWS
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
UNRELEASED:
0.4:
- Move sync API into a separate lsm-sync crate
- Removed KvTrait. The crate now only accept and returns bytes
- Get operations now return a reference to the data without copying
- Leverage zerocopy wherever possible to reduce serialization cost
- Update tokio-uring and kioto-uring-executor dependencies

0.3:
- Write-Ahead logging moved to a dedicated thread (or async task)
Expand Down
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ This implementation does *not* aim to reimplement LevelDB. The major differences
* *io_uring-support*: For async file system access on Linux. Optional and still considered experimental.
* *Bloom filters* for faster lookups

## Latest Version
The version on crates.io is quite outdated as it does not allow to publish crates with git dependencies.
It is recommended to use the `main` git branch instead.

## Supported Platfomrs and Architectures
Currently, the code is only tested with Linux on x86 machines, but it should run on most systems supported by the Rust compiler.

Expand Down
2 changes: 1 addition & 1 deletion src/data_blocks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ mod tests {
use tempfile::tempdir;

#[cfg(feature = "async-io")]
use tokio_uring::test as async_test;
use tokio_uring_executor::test as async_test;

#[cfg(not(feature = "async-io"))]
use tokio::test as async_test;
Expand Down
26 changes: 24 additions & 2 deletions src/disk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,36 @@ use std::path::Path;

use cfg_if::cfg_if;

/// Read from the offset to the end of the file
/// Not supported by tokio-uring yet, so added as a helper function here
#[cfg(feature = "async-io")]
async fn read_to_end(file: &fs::File, offset: u64) -> Result<Vec<u8>, std::io::Error> {
let mut buffer = vec![0u8; 4096];
let mut result = vec![];
let mut pos = offset;

loop {
let (res, buf) = file.read_at(buffer, pos).await;

match res {
Ok(0) => return Ok(result),
Ok(n) => {
buffer = buf;
result.extend_from_slice(&buffer[..n]);
pos += n as u64;
}
Err(err) => return Err(err),
}
}
}

#[inline(always)]
#[tracing::instrument]
pub async fn read_uncompressed(fpath: &Path, offset: u64) -> Result<Vec<u8>, std::io::Error> {
cfg_if! {
if #[ cfg(feature="async-io") ] {
let file = fs::File::open(fpath).await?;
let (res, buf) = file.read_at_to_end(offset, vec![]).await;
res?;
let buf = read_to_end(&file, offset).await?;
} else {
let mut file = fs::File::open(fpath)?;

Expand Down
2 changes: 1 addition & 1 deletion src/sorted_table/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::manifest::Manifest;
use tempfile::tempdir;

#[cfg(feature = "async-io")]
use tokio_uring::test as async_test;
use tokio_uring_executor::test as async_test;

#[cfg(not(feature = "async-io"))]
use tokio::test as async_test;
Expand Down

0 comments on commit 904a628

Please sign in to comment.