Bitcask is an append-only log-structured key-value storage engine. Unlike traditional databases that update data in place, Bitcask writes every change to the end of a data file. This ensures high write throughput by utilizing sequential I/O.
To maintain fast reads, it keeps an in-memory "KeyDir" a hash map that stores the location (offset and size) of the most recent value for every key in the data file.
- Append-only Storage: High-speed sequential writes.
- In-Memory Indexing: lookups for any key.
- Crash Recovery: Automatically rebuilds the in-memory index by scanning the
.bcfile on startup.
SET key value: Stores a string value associated with a key.GET key: Retrieves the most recent value for a key.RECOVERY: Automatically triggered on initialization if a database file is detected.
- Go 1.21+ installed on your machine.
Clone the repository and navigate to the project root:
git clone https://github.com/ganimtron-10/bitcask.git
cd bitcaskYou can run the interactive CLI directly from the cmd directory:
go run cmd/main.goOnce the program is running, you can interact with it via the command line:
- Set a value:
>>> set user_123 John
OK
- Get a value:
>>> get user_123
John
- Testing Recovery:
- Exit the program (
Ctrl+C). - Notice a
.dbfile has been created in your directory. - Run
go run cmd/main.goagain. - Run
get user_123immediately; the data is recovered and available!