A Java implementation of a Log-Structured Merge Tree (LSM Tree) developed to study write-optimized storage tradeoffs. LSM Trees prioritize write performance through sequential I/O and in-memory buffering, accepting higher read amplification and space usage as tradeoffs for improved write throughput compared to traditional B-Tree based storage systems.
- Memtable: In-memory write buffer using TreeMap
- SSTable: Sorted, immutable on-disk files created from memtable flushes
- WAL: Write-ahead log ensuring durability and crash recovery
Data is first written to the in-memory memtable and simultaneously logged to the WAL for crash recovery. When the memtable reaches its size limit, it's flushed to disk as an immutable SSTable file. Background compaction merges overlapping SSTables to control space amplification while maintaining write performance.
Reads check the memtable first for the most recent data. If not found, they search through SSTables from newest to oldest, potentially checking multiple files (read amplification). Bloom filters and sparse indexes optimize lookups by quickly eliminating irrelevant SSTables and providing efficient key positioning within files.
- JDK 17 or higher
- Maven 3.6 or higher
To build the project, run:
mvn clean installTo run the tests:
mvn testsrc/main/java- Main source codesrc/test/java- Test source codepom.xml- Maven project configuration