#skip-list #lock-free #arena #concurrency #memtable #memory-map #data-structures

no-std skl

A lock-free thread-safe concurrent ARENA based (heap backend or memory map backend) skiplist implementation which helps develop MVCC memtable for LSM-Tree

9 releases

new 0.9.0 May 15, 2024
0.7.1 May 9, 2024
0.4.0-alpha.1 Sep 19, 2023
0.2.4 Jul 17, 2022
0.1.0 Oct 25, 2021

#125 in Database interfaces

Download history 5/week @ 2024-02-14 19/week @ 2024-02-21 2/week @ 2024-02-28 5/week @ 2024-03-06 4/week @ 2024-03-13 1/week @ 2024-03-27 1/week @ 2024-04-03 135/week @ 2024-04-24 264/week @ 2024-05-01 910/week @ 2024-05-08

1,309 downloads per month

MIT/Apache

295KB
7.5K SLoC

SKL

github LoC Build codecov

docs.rs crates.io crates.io

wakatime license
  1. A lock-free thread-safe concurrent SkipMap and SkipSet implementation based on ARENA skiplist which helps develop MVCC memtable for LSM-Tree.
  2. A lock-free thread-safe concurrent memory map based on-disk SkipMap and SkipSet.

Installation

  • Only use heap backend (suppport no_std)

    [dependencies]
    skl = "0.9"
    
  • Enable memory map backend

    [dependencies]
    skl = { version = "0.9", features = ["memmap"] }
    

Features

  • MVCC and 3D access: Builtin MVCC (multiple versioning concurrency control) and key-value-version access support.
  • Lock-free and Concurrent-Safe: SkipMap and SkipSet provide lock-free operations, ensuring efficient concurrent access without the need for explicit locking mechanisms.
  • Extensible for Key-Value Database Developers: Designed as a low-level crate, SkipMap and SkipSet offer a flexible foundation for key-value database developers. You can easily build your own memtable or write-ahead-log (WAL) using these structures.
  • Memory Efficiency: These data structures are optimized for minimal memory overhead. They operate around references, avoiding unnecessary allocations and deep copies, which can be crucial for efficient memory usage.
  • Efficient Iteration: Enjoy fast forward and backward iteration through the elements in your SkipMap or SkipSet. Additionally, bounded iterators are supported, allowing you to traverse only a specified range of elements efficiently.
  • Snapshot Support: Create snapshots of your SkipMap or SkipSet, offering a read-only view of the contents at a specific moment in time. Snapshots provide a consistent view of the data, enabling implementations of transactional semantics and other use cases where data consistency is crucial.
  • Memory Management Options:
    • Heap Allocation: Memory allocation is handled by Rust's allocator, ensuring all data resides in RAM.
    • Mmap: Data can be mapped to a disk file by the operating system, making it suitable for write-ahead-logs (WAL) and durable storage.
    • Mmap Anonymous: Mapped to anonymous memory (virtual memory) by the OS, ideal for large in-memory memtables, optimizing memory utilization.

Examples

Please see examples folder for more details.

Tests

  • test:

    cargo test --all-features
    
  • miri:

    cargo miri test --all-features
    

Support Platforms

targets status
aarch64-linux-android
aarch64-unknown-linux-gnu
aarch64-unknown-linux-musl
i686-pc-windows-gnu
i686-linux-android
i686-unknown-linux-gnu
mips64-unknown-linux-gnuabi64
powerpc64-unknown-linux-gnu
riscv64gc-unknown-linux-gnu
wasm32-unknown-unknown
wasm32-unknown-emscripten
x86_64-unknown-linux-gnu
x86_64-pc-windows-gnu
x86_64-linux-android

Pedigree

This code is inspired and modified based on Cockroachdb's pebble arenaskl and Dgraph's badger skl code:

https://github.com/cockroachdb/pebble/tree/master/internal/arenaskl

https://github.com/dgraph-io/badger/tree/master/skl

The pebble's arenaskl code is based on Andy Kimball's arenaskl code:

https://github.com/andy-kimball/arenaskl

The arenaskl code is based on the skiplist found in Badger, a Go-based KV store:

https://github.com/dgraph-io/badger/tree/master/skl

The skiplist in Badger is itself based on a C++ skiplist built for Facebook's RocksDB:

https://github.com/facebook/rocksdb/tree/master/memtable

TODO (help wanted)

  • make the crate test cases pass cargo loom

License

skl-rs is under the terms of both the MIT license and the Apache License (Version 2.0).

See LICENSE-APACHE, LICENSE-MIT for details.

Copyright (c) 2022 Al Liu.

Dependencies

~0.4–31MB
~444K SLoC