Skip to content

Commit

Permalink
Batch insertion (#5)
Browse files Browse the repository at this point in the history
- Refactor constructors, use `Builder` and `GenericBuilder` to construct WALs
- Support atomic batch insertion
  • Loading branch information
al8n authored Sep 19, 2024
1 parent ebb9c0d commit 1688250
Show file tree
Hide file tree
Showing 45 changed files with 4,476 additions and 2,589 deletions.
3 changes: 1 addition & 2 deletions .codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ ignore:
- "**/benches/"
- "src/tests.rs"
- "src/error.rs"
- "src/swmr/generic/traits/impls/"
- "src/swmr/generic/traits/impls.rs"
- "src/swmr/generic/tests.rs"
- "src/swmr/generic/tests/"
- "src/swmr/wal/tests.rs"
- "src/swmr/wal/tests/"
- "src/wal/type/"
- "src/unsync/tests.rs"
- "src/unsync/tests/"

Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,12 @@ jobs:
- unsync_iters
- unsync_get
- unsync_constructor
- unsync_insert_batch
- swmr_insert
- swmr_iters
- swmr_get
- swmr_constructor
- swmr_insert_batch
- swmr_generic_insert
- swmr_generic_iters
- swmr_generic_get
Expand Down
5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "orderwal"
version = "0.1.1"
version = "0.2.0"
edition = "2021"
repository = "https://github.com/al8n/orderwal"
homepage = "https://github.com/al8n/orderwal"
Expand Down Expand Up @@ -34,6 +34,7 @@ thiserror = "1"

bytes = { version = "1", default-features = false, optional = true }
smallvec = { version = "1", default-features = false, optional = true, features = ["const_generics"] }
smallvec-wrapper = { version = "0.1", optional = true, default-features = false, features = ["const_generics"] }
smol_str = { version = "0.3", default-features = false, optional = true }
faststr = { version = "0.2", default-features = false, optional = true }

Expand Down Expand Up @@ -67,10 +68,12 @@ unexpected_cfgs = { level = "warn", check-cfg = [
'cfg(all_tests)',
'cfg(test_unsync_constructor)',
'cfg(test_unsync_insert)',
'cfg(test_unsync_insert_batch)',
'cfg(test_unsync_iters)',
'cfg(test_unsync_get)',
'cfg(test_swmr_constructor)',
'cfg(test_swmr_insert)',
'cfg(test_swmr_insert_batch)',
'cfg(test_swmr_iters)',
'cfg(test_swmr_get)',
'cfg(test_swmr_generic_constructor)',
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ English | [简体中文][zh-cn-url]
orderwal = "0.1"
```

## Example

See [examples](./examples/) for more information.

## Related projects

- [`aol`](https://github.com/al8n/aol): Yet another generic purpose, append-only write-ahead log implementation based on `std::fs::File`.
Expand Down
26 changes: 15 additions & 11 deletions examples/zero_cost.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
use std::{cmp, sync::Arc, thread::spawn};

use orderwal::{swmr::generic::*, utils::*, OpenOptions, Options};
use orderwal::{
swmr::generic::{Comparable, Equivalent, GenericBuilder, KeyRef, Type, TypeRef},
utils::*,
OpenOptions,
};

#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
struct Person {
Expand Down Expand Up @@ -112,7 +116,7 @@ impl Type for Person {
}

impl<'a> TypeRef<'a> for PersonRef<'a> {
fn from_slice(src: &'a [u8]) -> Self {
unsafe fn from_slice(src: &'a [u8]) -> Self {
let (id_size, id) = decode_u64_varint(src).unwrap();
let name = std::str::from_utf8(&src[id_size..]).unwrap();
PersonRef { id, name }
Expand All @@ -132,15 +136,15 @@ fn main() {
.collect::<Vec<_>>();

let mut wal = unsafe {
GenericOrderWal::<Person, String>::map_mut(
&path,
Options::new(),
OpenOptions::new()
.create_new(Some(1024 * 1024))
.write(true)
.read(true),
)
.unwrap()
GenericBuilder::new()
.map_mut::<Person, String, _>(
&path,
OpenOptions::new()
.create_new(Some(1024 * 1024))
.write(true)
.read(true),
)
.unwrap()
};

// Create 100 readers
Expand Down
11 changes: 10 additions & 1 deletion src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,22 @@ macro_rules! builder {
impl<F> [< $name Builder >]<F> {
#[doc = "Creates a new `" [<$name Builder>] "` with the given size and builder closure."]
#[inline]
pub const fn new<E>(size: $size, f: F) -> Self
pub const fn once<E>(size: $size, f: F) -> Self
where
F: for<'a> FnOnce(&mut VacantBuffer<'a>) -> Result<(), E>,
{
Self { size, f }
}

#[doc = "Creates a new `" [<$name Builder>] "` with the given size and builder closure."]
#[inline]
pub const fn new<E>(size: $size, f: F) -> Self
where
F: for<'a> Fn(&mut VacantBuffer<'a>) -> Result<(), E>,
{
Self { size, f }
}

#[doc = "Returns the required" [< $name: snake>] "size."]
#[inline]
pub const fn size(&self) -> $size {
Expand Down
Loading

0 comments on commit 1688250

Please sign in to comment.