DDIA
Lab
/ practice / log-index
Overview
Learn
Chapters
Practice
Cheatsheets
Search the book…
⌘K
0/12 chapters
All labs
Lab · Chapter 3 · Storage and Retrieval
Log + Hash Index
Each write is
appended
to the current segment file (a new segment starts every 4 entries). An in-memory
hash map
remembers the byte offset of every key's latest value.
key
cat
dog
owl
fox
value
Write (append)
Delete (tombstone)
Read
Compact & merge
Reset
Segment files on disk (append-only)
seg-1 ✎
@0
cat=meow
@1
dog=woof
@2
cat=purr
In-memory hash index
key
→ offset
value
cat
@2
purr
dog
@1
woof
3
entries on disk
2
live keys
1 · 33%
garbage (stale + ✝)