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 committed Sep 19, 2024
1 parent ebb9c0d commit 915694d
Show file tree
Hide file tree
Showing 44 changed files with 4,450 additions and 2,615 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
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[package]
name = "orderwal"
version = "0.1.1"
version = "0.2.1"
edition = "2021"
repository = "https://github.com/al8n/orderwal"
homepage = "https://github.com/al8n/orderwal"
documentation = "https://docs.rs/orderwal"
description = "A generic-purpose, ordered, zero-copy, Write-Ahead Log implementation for Rust."
description = "A generic-purpose, atomic, ordered, zero-copy, Write-Ahead Log implementation for Rust."
license = "MIT OR Apache-2.0"
rust-version = "1.80"
categories = ["filesystem", "database-implementations", "development-tools", "data-structures"]
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
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
</div>
<div align="center">

A generic-purpose, ordered, zero-copy, Write-Ahead Log implementation for Rust.
A generic-purpose, atomic, ordered, zero-copy, Write-Ahead Log implementation for Rust.

[<img alt="github" src="https://img.shields.io/badge/github-al8n/orderwal-8da0cb?style=for-the-badge&logo=Github" height="22">][Github-url]
<img alt="LoC" src="https://img.shields.io/endpoint?url=https%3A%2F%2Fgist.githubusercontent.com%2Fal8n%2F327b2a8aef9003246e45c6e47fe63937%2Fraw%2Forderwal" height="22">
Expand All @@ -21,17 +21,21 @@ English | [简体中文][zh-cn-url]

## Introduction

`orderwal` is a generic-purpose, ordered, zero-copy, concurrent-safe, pre-allocate style (memory map) write-ahead-log for developing databases.
`orderwal` is generic-purpose, atomic, ordered, zero-copy, concurrent-safe, pre-allocate style (memory map) write-ahead-log for developing databases.

`orderwal` also supports generic structured key and value types, which is not limited to just bytes like other implementations.

## Installation

```toml
[dependencies]
orderwal = "0.1"
orderwal = "0.2"
```

## 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 All @@ -44,7 +48,7 @@ Apache License (Version 2.0).

See [LICENSE-APACHE](LICENSE-APACHE), [LICENSE-MIT](LICENSE-MIT) for details.

Copyright (c) 2021 Al Liu.
Copyright (c) 2024 Al Liu.

[Github-url]: https://github.com/al8n/orderwal/
[CI-url]: https://github.com/al8n/orderwal/actions/workflows/ci.yml
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 915694d

Please sign in to comment.