r/databasedevelopment • u/zer01nt • Jun 18 '24
LSM tree "popular" implementations
Looking for implementations of LSM tree that are used in well-known projects either in Go or Rust. C++ or Zig is ok too but prefer any from the first 2. Please comment the link/s below. It may not be separate package, can be an internal one but at least has well defined interface. Thanks!
2
u/raphaelscarv Jun 18 '24
ScyllaDB / Cassandra implement LSM tree too. Interestingly, a new sstable format s adopting an immutable btree for index.
2
u/zer01nt Jun 19 '24
Thanks! I was actually interested in investigating if LSM trees worked as an index them self or require another data structure. Because to me, it seems like it doesn’t but I looked at some comment in Stackoverflow and that argued that it does. I guess your comment answers my ultimate question. 😅
2
Jun 19 '24
SSTables are sorted by key, but that really only helps with merge, not with binary search (because K/V pairs are variable-length). To do binary search effectively you need to sample every N keys and store their offsets (possibly with key prefixes) in an auxiliary index array.
2
u/raphaelscarv Jun 20 '24
In Cassandra, there's an immutable index for each immutable SSTable data file. You can have a 2-depth index (summary (the sampling of keys) and index itself (set of keys pointing to locations in data file)) or you can also implement an immutable btree-based index, which will go with each SSTable data file too (to get rid of the 2-depth approach).
8
u/eatonphil Jun 18 '24
Here are the docs for TigerBeetle's implementation of an LSM tree in Zig.
https://github.com/tigerbeetle/tigerbeetle/blob/main/docs/about/internals/lsm.md
4
Jun 18 '24
RocksDB? Used in a lot of modern stuff. Cockroach is in Go
I think TiDB too
7
u/eatonphil Jun 18 '24
Cockroach is in Go
It isn't Cockroach, the database, specifically but Cockroach's Pebble library. https://github.com/cockroachdb/pebble
1
3
4
u/dennis_zhuang Jun 18 '24
The GreptimeDB implementation in Rust and is designed for object storage such as S3:
The source code is https://github.com/GreptimeTeam/greptimedb/tree/main/src/mito2
And the document
https://docs.greptime.com/contributor-guide/datanode/storage-engine
https://docs.greptime.com/contributor-guide/datanode/data-persistence-indexing
3
3
2
u/1_am_ir0nman Jun 19 '24
You can also checkout Neon database,they have implemented LSM tree structure in rust. https://github.com/neondatabase/neon
1
u/steve_lau Jan 07 '25
Hmm, I think they follow how the Postgres core works, i.e., use the heap storage engine, but a cloud-native version that targets s3, not a LSM.
2
u/1_am_ir0nman Jun 30 '26
sorry back after a long time :) ,AFAIK Neon have a totally separate storage engine called pageserver , Postgres core uses a mutable, in-place heap storage engine that overwrites 8KB blocks on a local disk, a design that cannot work on Amazon S3 because S3 objects are strictly immutable and do not support random in-place writes. Neon solves this by materializing the WALs into pages, and flushing them into immutable delta and image layers using LSM. These immutable layers are then pushed to S3 and continuously does LSM compaction of these layers.
2
u/m_orazow Jun 20 '24
Apache Paimon for lake format for streaming data: https://paimon.apache.org
WiscKey for separating key & value for reduced I/O amplifications. https://www.usenix.org/system/files/conference/fast16/fast16-papers-lu.pdf
1
1
11
u/eatonphil Jun 18 '24
Here is RisingWave's LSM tree implementation in Rust.
https://github.com/risingwavelabs/risingwave/tree/main/src/storage/src/hummock
And docs/blogs on it
https://risingwave.com/blog/optimizing-rust-code-for-the-lsm-tree-iterator-in-risingwave/
https://github.com/risingwavelabs/risingwave/blob/main/docs/state-store-overview.md