+0
Daily
9,112
stars
428
forks
123
watchers
933
prs
605
issues
22
releases
README
key
value
documentation
chat about databases with us
sled - ~~it's all downhill from here!!!~~
An embedded database.
rust
let tree = sled::open("/tmp/welcome-to-sled")?;
// insert and get, similar to std's BTreeMap
let old_value = tree.insert("key", "value")?;
assert_eq!(
tree.get(&"key")?,
Some(sled::IVec::from("value")),
);
// range queries
for kv_result in tree.range("key_1".."key_9") {}
// deletion
let old_value = tree.remove(&"key")?;
// atomic compare and swap
tree.compare_and_swap(
"key",
Some("current_value"),
Some("new_value"),
)?;
// block until all operations are stable on disk
// (flush_async also available to get a Future)
tree.flush()?;
$${\color{red}This \space README \space is \space out \space of \space sync \space with \space the \space main \space branch \space which \space contains \space a \space large \space in-progress \space rewrite }$$
If you would like to work with structured data without paying expensive deserialization costs, check out the structured example!
features
API similar to a threadsafe BTreeMap
serializable (ACID) transactions
for atomically reading and writing to multiple keys in multiple keyspaces.
fully atomic single-key operations, including compare and swap
zero-copy reads
write batches
subscribe to changes on key
prefixes
multiple keyspaces
merge operators
forward and reverse iterators over ranges of items
a crash-safe monotonic ID generator
capable of generating 75-125 million unique ID's per second
zstd compression (use the
compression build feature, disabled by default)
cpu-scalable lock-free implementation
flash-optimized log-structured storage
uses modern b-tree techniques such as prefix encoding and suffix
truncation for reducing the storage costs of long keys with shared
prefixes. If keys are the same length and sequential then the
system can avoid storing 99%+ of the key data in most cases,
essentially acting like a learned index
expectations, gotchas, advice
Maybe one of the first things that seems weird is the IVec type.
This is an inlinable Arced slice that makes some things more efficient.
Durability: sled automatically fsyncs every 500ms by default,
which can be configured with the flush_every_ms configurable, or you may
call flush / flush_async manually after operations.
Transactions are optimistic - do not interact with external state
or perform IO from within a transaction closure unless it is
idempotent.
Internal tree node optimizations: sled performs prefix encoding
on long keys with similar prefixes that are grouped together in a range,
as well as suffix truncation to further reduce the indexing costs of
long keys. Nodes will skip potentially expensive length and offset pointers
if keys or values are all the same length (tracked separately, don't worry
about making keys the same length as values), sTop issues
#1266Support a typed API?17 comments · 2021-01-17#1444Hi I wanted to know if this project is dead?15 comments · 2023-04-08#382Transactional MVCC Pagecache15 comments · 2018-10-30#986High memory usage when using 'many tiny objects'14 comments · 2020-02-24#1112WASM Support13 comments · 2020-06-29#1077ALICE-like write permuter12 comments · 2020-05-23#1162Subscriptions and the Pit of Success10 comments · 2020-09-03#926Doubt about the recovery process10 comments · 2020-01-05
Latest release
0.34.7 v0.34.7 2021-09-12Bug Fixes 1314 Fix a bug in Subscriber's Future impl.