yfractal / blog

10 stars 0 forks source link

Tired LSM Tree #7

Open yfractal opened 2 years ago

yfractal commented 2 years ago

Operations

Let's see how LSM tree changes when we insert entries.

Screen_Shot_2022-03-26_at_11_10_18_PM

(above screen shot is generated by this script)

yfractal commented 2 years ago

A simple tired compacting Log-Structured Merge Tree(LSM Tree) Ruby implementation which is inspired by cs265-lsm-tree.

Data Structures

Screen Shot 2022-03-28 at 6 02 48 PM

Screen Shot 2022-03-28 at 6 09 07 PM

Operations

LSM::LSMTree#put is for writing key value pair into DB.

LSM::LSMTree#get is for query key into DB.

Demo

Entry will be inserted into memtable first if the memtable is not full.

Screen Shot 2022-03-28 at 6 41 03 PM

When the memtable is full, if we want to insert one more entry, DB will write the memtable to disk.

Screen Shot 2022-03-28 at 6 41 27 PM

If level 0 is full, when we want to add one more sstable in level 0, DB will merge all level0's sstables into a big sstable, then the big sstable will be written into level 1.

Screen Shot 2022-03-28 at 6 41 55 PM

This demo can be generated by the ./bin/demo script.

Status

Current Status

Basic implementation.

Future Plan