Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

godb-scratch

A key-value database built from scratch in Go, as an exploratory project to understand how storage engines work. Bitcask-style log-structured storage engine (same basic design as Riak). Writes are appended to a log file and fsync'd for durability, an in-memory hash index gives O(1) lookups, deletes are tombstones, and compaction rewrites the log to drop dead records.

Quickstart

go build -o godb ./cmd/godb
./godb
put <key> <value>   store a key-value pair
get <key>           fetch a value by key
delete <key>        remove a key
compact             reclaim space from stale/deleted records
exit                quit

Structure

cmd/godb/main.go       entry point, REPL loop
bitcask/engine.go      Store, NewStore, rebuildIndex, Put, Get, Delete, Compact
bitcask/record.go      encodeRecord / readRecord, pure byte format
bitcask/engine_test.go tests for put/get/delete/recovery/compaction

Limitations

  • empty value is indistinguishable from a deleted key after restart (tombstones are zero-length values)
  • no range queries or sorted iteration, hash index only
  • no concurrency support

Tests

go test ./...

License

MIT, see LICENSE.

About

An exploration of database internals - a key-value store built from scratch in Go.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages