Skip to content

Latest commit

 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Bitcask

What is Bitcask?

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.

Key Features

  • 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 .bc file on startup.

Supported Commands

  • 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.

Getting Started

Prerequisites

  • Go 1.21+ installed on your machine.

Installation

Clone the repository and navigate to the project root:

git clone https://github.com/ganimtron-10/bitcask.git
cd bitcask

Running the Application

You can run the interactive CLI directly from the cmd directory:

go run cmd/main.go

Example Usage

Once the program is running, you can interact with it via the command line:

  1. Set a value:
>>> set user_123 John
OK
  1. Get a value:
>>> get user_123
John
  1. Testing Recovery:
  • Exit the program (Ctrl+C).
  • Notice a .db file has been created in your directory.
  • Run go run cmd/main.go again.
  • Run get user_123 immediately; the data is recovered and available!

About

Bitcask is a lightweight, high-performance Key-Value (KV) store implementation in Golang, based on the original Bitcask design used in Riak.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Contributors

Languages