Baobab is a simple B+ Tree based key-value store written in Go.
This is a work in progress and is not intended for production use - yet.
- B+ Tree index - supports adding keys, retreving keys and range queries.
- Buffer Manager - TinyLFU filter with W-TinyLFU cache eviction.
- A background writer to flush dirty pages periodically. Similar to PostgreSQL.
- A disk maneger that supports concurrent writes on distinct page IDs.
- Free list - A record of available page IDs after deletion.
- A http API for get, put and range queries
-
Ensure you have go installed. This project uses go v1.24.2
-
Clone the repo.
git clone- Build and run the server.
make build && make runThis will start the server on port :8080
This will create two files in the root directory: i. data - the data file where all data will be stored. ii. data_fl - a free list file. This stores all the available page IDs on a 4K page.
- PUT a value.
ubuntu@ubuntu:~$ curl -X PUT -d '{"key":"data:item_1","val":"value_1"}' http://127.0.0.1:8080/kv
{"key":"data:item_1","val":"value_1"}
ubuntu@ubuntu:~$- GET the value.
ubuntu@ubuntu:~$ curl http://127.0.0.1:8080/kv/data:item_1
{"key":"data:item_1","val":"value_1"}- DELETE the value.
ubuntu@ubuntu:~$ curl -X DELETE http://127.0.0.1:8080/kv/remove/data:item_1
{"status":"success","deleted":true}- Check again.
ubuntu@ubuntu:~$ curl http://127.0.0.1:8080/kv/data:item_1
{"error":"Key not found"}- Range Query
A range query will return a number of items(item_count) starting from the start_item.
curl http://127.0.0.1:8080/kv/range?start=<start_item>&limit=<item_count>ubuntu@ubuntu:~$ curl http://127.0.0.1:8080/kv/range?start=data:item_1&limit=4
{
"status": "success",
"count": 4,
"results": [
{
"key": "data:item_1",
"val": "Status_1_Value_1"
},
{
"key": "data:item_10",
"val": "Status_0_Value_10"
},
{
"key": "data:item_11",
"val": "Status_1_Value_11"
},
{
"key": "data:item_12",
"val": "Status_2_Value_12"
}
]
}- Design page layout and file format
- Disk Manager
- Background writer
- B+ Tree Algorithm - Splits and merges
- Buffer Management - W-TinyLFU (90%)
- Recovery - WAL, Checkpointing
- Transactions
- Replication - Raft
