Skip to content

Commit

Permalink
0.20.0 (#48)
Browse files Browse the repository at this point in the history
- Add dynamic `SkipMap`s
- Support create multiple `SkipMap`s on the same Arena
- Improve docs on some constructor methods
  • Loading branch information
al8n committed Nov 12, 2024
1 parent f2b6a11 commit e4be48c
Show file tree
Hide file tree
Showing 57 changed files with 14,006 additions and 1,733 deletions.
54 changes: 36 additions & 18 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -250,15 +250,24 @@ jobs:
- x86_64-apple-darwin
- aarch64-apple-darwin
cfg:
- unsync_map
- unsync_versioned
- sync_map
- sync_versioned
- sync_map_concurrent
- sync_multiple_version_concurrent
- sync_map_concurrent_with_optimistic_freelist
- sync_map_concurrent_with_pessimistic_freelist
- sync_multiple_version_concurrent_with_pessimistic_freelist
- generic_unsync_map
- generic_unsync_versioned
- generic_sync_map
- generic_sync_versioned
- generic_sync_map_concurrent
- generic_sync_multiple_version_concurrent
- generic_sync_map_concurrent_with_optimistic_freelist
- generic_sync_map_concurrent_with_pessimistic_freelist
- generic_sync_multiple_version_concurrent_with_pessimistic_freelist
- dynamic_unsync_map
- dynamic_unsync_versioned
- dynamic_sync_map
- dynamic_sync_versioned
- dynamic_sync_map_concurrent
- dynamic_sync_multiple_version_concurrent
- dynamic_sync_map_concurrent_with_optimistic_freelist
- dynamic_sync_map_concurrent_with_pessimistic_freelist
- dynamic_sync_multiple_version_concurrent_with_pessimistic_freelist
# Exclude invalid combinations
exclude:
- os: ubuntu-latest
Expand Down Expand Up @@ -302,15 +311,24 @@ jobs:
- x86_64-apple-darwin
- aarch64-apple-darwin
cfg:
- unsync_map
- unsync_versioned
- sync_map
- sync_versioned
- sync_map_concurrent
- sync_multiple_version_concurrent
- sync_map_concurrent_with_optimistic_freelist
- sync_map_concurrent_with_pessimistic_freelist
- sync_multiple_version_concurrent_with_pessimistic_freelist
- generic_unsync_map
- generic_unsync_versioned
- generic_sync_map
- generic_sync_versioned
- generic_sync_map_concurrent
- generic_sync_multiple_version_concurrent
- generic_sync_map_concurrent_with_optimistic_freelist
- generic_sync_map_concurrent_with_pessimistic_freelist
- generic_sync_multiple_version_concurrent_with_pessimistic_freelist
- dynamic_unsync_map
- dynamic_unsync_versioned
- dynamic_sync_map
- dynamic_sync_versioned
- dynamic_sync_map_concurrent
- dynamic_sync_multiple_version_concurrent
- dynamic_sync_map_concurrent_with_optimistic_freelist
- dynamic_sync_map_concurrent_with_pessimistic_freelist
- dynamic_sync_multiple_version_concurrent_with_pessimistic_freelist
# Exclude invalid combinations
exclude:
- os: ubuntu-latest
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# CHANGELOG

## 0.20.0

- Add dynamic `SkipMap`s
- Support create multiple `SkipMap`s on the same `Allocator`
- Improve docs on some constructor methods

## 0.19.0

- Cleanup structures and remove `Trailer`, `TrailedMap` and `FullMap`
Expand Down
41 changes: 28 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "skl"
version = "0.19.2"
version = "0.20.0"
edition = "2021"
rust-version = "1.81.0"
repository = "https://github.com/al8n/skl"
Expand Down Expand Up @@ -30,6 +30,11 @@ name = "mmap-anon"
path = "examples/mmap_anon.rs"
required-features = ["memmap"]

[[example]]
name = "multiple_maps"
path = "examples/multiple_maps.rs"
required-features = ["memmap"]

[features]
default = ["std"]
alloc = ["rarena-allocator/alloc", "dbutils/alloc"]
Expand All @@ -46,7 +51,7 @@ getrandom = { version = "0.2", features = ["js"] }
among = { version = "0.1", default-features = false, features = ["either"] }
arbitrary-int = { version = "1.2", default-features = false }
bitflags = "2"
dbutils = { version = "0.9", default-features = false }
dbutils = { version = "0.10", default-features = false }
either = { version = "1", default-features = false }
memchr = { version = "2", default-features = false, optional = true }
rand = { version = "0.8", default-features = false, features = ["getrandom"] }
Expand Down Expand Up @@ -84,15 +89,25 @@ members = ["integration"]
rust_2018_idioms = "warn"
single_use_lifetimes = "warn"
unexpected_cfgs = { level = "warn", check-cfg = [
'cfg(all_tests)',
'cfg(test_unsync_versioned)',
'cfg(test_unsync_map)',
'cfg(test_sync_versioned)',
'cfg(test_sync_map)',
'cfg(test_sync_multiple_version_concurrent)',
'cfg(test_sync_map_concurrent)',
'cfg(test_sync_multiple_version_concurrent_with_optimistic_freelist)',
'cfg(test_sync_map_concurrent_with_optimistic_freelist)',
'cfg(test_sync_multiple_version_concurrent_with_pessimistic_freelist)',
'cfg(test_sync_map_concurrent_with_pessimistic_freelist)',
'cfg(all_skl_tests)',
'cfg(test_generic_unsync_versioned)',
'cfg(test_generic_unsync_map)',
'cfg(test_generic_sync_versioned)',
'cfg(test_generic_sync_map)',
'cfg(test_generic_sync_multiple_version_concurrent)',
'cfg(test_generic_sync_map_concurrent)',
'cfg(test_generic_sync_multiple_version_concurrent_with_optimistic_freelist)',
'cfg(test_generic_sync_map_concurrent_with_optimistic_freelist)',
'cfg(test_generic_sync_multiple_version_concurrent_with_pessimistic_freelist)',
'cfg(test_generic_sync_map_concurrent_with_pessimistic_freelist)',
'cfg(test_dynamic_unsync_versioned)',
'cfg(test_dynamic_unsync_map)',
'cfg(test_dynamic_sync_versioned)',
'cfg(test_dynamic_sync_map)',
'cfg(test_dynamic_sync_multiple_version_concurrent)',
'cfg(test_dynamic_sync_map_concurrent)',
'cfg(test_dynamic_sync_multiple_version_concurrent_with_optimistic_freelist)',
'cfg(test_dynamic_sync_map_concurrent_with_optimistic_freelist)',
'cfg(test_dynamic_sync_multiple_version_concurrent_with_pessimistic_freelist)',
'cfg(test_dynamic_sync_map_concurrent_with_pessimistic_freelist)',
] }
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@

```toml
[dependencies]
skl = "0.19"
skl = "0.20"
```

- Enable memory map backend

```toml
[dependencies]
skl = { version = "0.19", features = ["memmap"] }
skl = { version = "0.20", features = ["memmap"] }
```

## Features
Expand Down Expand Up @@ -88,15 +88,15 @@ Please see [examples](https://github.com/al8n/skl/tree/main/examples) folder for

```sh
MIRIFLAGS="-Zmiri-strict-provenance -Zmiri-disable-isolation -Zmiri-symbolic-alignment-check" \
RUSTFLAGS = "--cfg all_tests" \
RUSTFLAGS = "--cfg all_skl_tests" \
cargo miri test --all-features
```

- `miri` (Tree Borrows)

```sh
MIRIFLAGS="-Zmiri-strict-provenance -Zmiri-disable-isolation -Zmiri-symbolic-alignment-check -Zmiri-tree-borrows" \
RUSTFLAGS = "--cfg all_tests" \
RUSTFLAGS = "--cfg all_skl_tests" \
cargo miri test --all-features
```

Expand Down
14 changes: 7 additions & 7 deletions benches/bench.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use criterion::*;
use parking_lot::Mutex;
use rand::prelude::*;
use skl::{
map::{sync::SkipMap, Map},
*,
use skl::generic::{
unique::{sync::SkipMap, Map},
Builder,
};
use std::{
collections::*,
Expand Down Expand Up @@ -45,9 +45,9 @@ fn random_key(rng: &mut ThreadRng) -> Vec<u8> {
fn bench_read_write_fixed_skiplist_frac(b: &mut Bencher<'_>, frac: &usize) {
let frac = *frac;
let value = b"00123".to_vec();
let list = Options::new()
let list = Builder::new()
.with_capacity(512 << 20)
.alloc::<_, _, SkipMap<[u8], [u8]>>()
.alloc::<SkipMap<[u8], [u8]>>()
.unwrap();
let l = list.clone();
let stop = Arc::new(AtomicBool::new(false));
Expand Down Expand Up @@ -170,9 +170,9 @@ fn bench_write_fixed_map(c: &mut Criterion) {
}

fn bench_write_fixed_skiplist(c: &mut Criterion) {
let list = Options::new()
let list = Builder::new()
.with_capacity(512 << 20)
.alloc::<_, _, SkipMap<[u8], [u8]>>()
.alloc::<SkipMap<[u8], [u8]>>()
.unwrap();
let l = list.clone();
let value = b"00123".to_vec();
Expand Down
8 changes: 4 additions & 4 deletions ci/sanitizer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ set -ex
export ASAN_OPTIONS="detect_odr_violation=0 detect_leaks=0"

# Run address sanitizer
RUSTFLAGS="--cfg all_tests -Z sanitizer=address" \
RUSTFLAGS="--cfg all_skl_tests -Z sanitizer=address" \
cargo test --lib --all-features --target x86_64-unknown-linux-gnu

# Run leak sanitizer
RUSTFLAGS="--cfg all_tests -Z sanitizer=leak" \
RUSTFLAGS="--cfg all_skl_tests -Z sanitizer=leak" \
cargo test --lib --all-features --target x86_64-unknown-linux-gnu

# Run memory sanitizer
RUSTFLAGS="--cfg all_tests -Zsanitizer=memory -Zsanitizer-memory-track-origins" \
RUSTFLAGS="--cfg all_skl_tests -Zsanitizer=memory -Zsanitizer-memory-track-origins" \
RUSTDOCFLAGS="-Zsanitizer=memory -Zsanitizer-memory-track-origins" \
cargo test -Zbuild-std --release --tests --target x86_64-unknown-linux-gnu --features memmap

# Run thread sanitizer
RUSTFLAGS="--cfg all_tests -Z sanitizer=thread" \
RUSTFLAGS="--cfg all_skl_tests -Z sanitizer=thread" \
cargo -Zbuild-std test --lib --target x86_64-unknown-linux-gnu --features memmap

11 changes: 7 additions & 4 deletions examples/heap.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use skl::{
map::{sync::SkipMap, Map},
Arena, Options,
generic::{
unique::{sync::SkipMap, Map},
Builder,
},
Arena,
};

pub fn key(i: usize) -> Vec<u8> {
Expand All @@ -14,9 +17,9 @@ pub fn new_value(i: usize) -> Vec<u8> {
fn main() {
const N: usize = 1000;

let l = Options::new()
let l = Builder::new()
.with_capacity(1 << 20)
.alloc::<_, _, SkipMap<[u8], [u8]>>()
.alloc::<SkipMap<[u8], [u8]>>()
.unwrap();

for i in 0..N {
Expand Down
12 changes: 8 additions & 4 deletions examples/mmap.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use skl::{
map::{sync::SkipMap, Map},
Arena, Options,
generic::{
unique::{sync::SkipMap, Map},
Builder,
},
Arena,
};

pub fn key(i: usize) -> Vec<u8> {
Expand All @@ -10,16 +13,17 @@ pub fn key(i: usize) -> Vec<u8> {
pub fn new_value(i: usize) -> Vec<u8> {
format!("{:05}", i).into_bytes()
}

fn main() {
const N: usize = 1000;

let l = unsafe {
Options::new()
Builder::new()
.with_capacity(1 << 20)
.with_read(true)
.with_write(true)
.with_create_new(true)
.map_mut::<[u8], [u8], SkipMap<[u8], [u8]>, _>("test.wal")
.map_mut::<SkipMap<[u8], [u8]>, _>("test.wal")
.unwrap()
};

Expand Down
11 changes: 7 additions & 4 deletions examples/mmap_anon.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use skl::{
map::{sync::SkipMap, Map},
Arena, Options,
generic::{
unique::{sync::SkipMap, Map},
Builder,
},
Arena,
};

pub fn key(i: usize) -> Vec<u8> {
Expand All @@ -14,9 +17,9 @@ pub fn new_value(i: usize) -> Vec<u8> {
fn main() {
const N: usize = 1000;

let l = Options::new()
let l = Builder::new()
.with_capacity(1 << 20)
.map_anon::<[u8], [u8], SkipMap<[u8], [u8]>>()
.map_anon::<SkipMap<[u8], [u8]>>()
.unwrap();

for i in 0..N {
Expand Down
77 changes: 77 additions & 0 deletions examples/multiple_maps.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
use skl::{
generic::{
unique::{sync::SkipMap, Map},
Builder,
},
Arena,
};

pub fn key(i: usize) -> Vec<u8> {
format!("{:05}", i).into_bytes()
}

pub fn new_value(i: usize) -> Vec<u8> {
format!("{:05}", i).into_bytes()
}

/// This example demonstrates how to create multiple SkipMaps on the same ARENA allocator.
fn main() {
unsafe {
let header = {
let l = Builder::new()
.with_create_new(true)
.with_read(true)
.with_write(true)
.with_capacity(1024 * 1024)
.map_mut::<SkipMap<[u8], [u8]>, _>("multiple_maps.wal")
.unwrap();
let l2 = SkipMap::<[u8], [u8]>::create_from_allocator(l.allocator().clone()).unwrap();
let h2 = l2.header().copied().unwrap();

let t1 = std::thread::spawn(move || {
for i in 0..500 {
l.get_or_insert(key(i).as_slice(), new_value(i).as_slice())
.unwrap();
}
l.flush().unwrap();
});

let t2 = std::thread::spawn(move || {
for i in 500..1000 {
l2.get_or_insert(key(i).as_slice(), new_value(i).as_slice())
.unwrap();
}
l2.flush().unwrap();
});

t1.join().unwrap();
t2.join().unwrap();

h2
};

let l = Builder::new()
.with_read(true)
.with_write(true)
.with_capacity((1024 * 1024 * 2) as u32)
.map_mut::<SkipMap<[u8], [u8]>, _>("multiple_maps.wal")
.unwrap();
let l2 = SkipMap::<[u8], [u8]>::open_from_allocator(header, l.allocator().clone()).unwrap();
assert_eq!(500, l.len());
assert_eq!(500, l2.len());

for i in 0..500 {
let k = key(i);
let ent = l.get(k.as_slice()).unwrap();
assert_eq!(new_value(i).as_slice(), ent.value());
assert_eq!(ent.key(), k.as_slice());
}

for i in 500..1000 {
let k = key(i);
let ent = l2.get(k.as_slice()).unwrap();
assert_eq!(new_value(i).as_slice(), ent.value());
assert_eq!(ent.key(), k.as_slice());
}
}
}
Loading

0 comments on commit e4be48c

Please sign in to comment.