How does a point read work in an LSM tree, and what makes it slow?
Sketch your own answer first, then compare it with the one below.
A strong answer
The read checks the memtable first, then the files from newest to oldest, and returns the first version it finds. A file is checked by looking up its index to find the one block that could hold the key.
A key that is present is usually found early. A key that is absent has to be ruled out in every file, which is the worst case. Each file check can mean a disk read.
Bloom filters fix most of this. A small in-memory filter per file says "definitely not here" for almost every file that does not hold the key. The read then touches only the file that has it, plus a rare false alarm.
Sources
- Fay Chang, Jeffrey Dean, Sanjay Ghemawat, Wilson C. Hsieh, Deborah A. Wallach, Mike Burrows, Tushar Chandra, Andrew Fikes, Robert E. Gruber (2008). Bigtable: A Distributed Storage System for Structured Data.
- Chen Luo, Michael J. Carey (2020). LSM-based storage techniques: a survey.