https://github.com/devvspaces/bitcask-go
https://github.com/devvspaces/bitcask-go
Last synced: 9 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/devvspaces/bitcask-go
- Owner: devvspaces
- License: other
- Created: 2026-04-26T03:33:10.000Z (about 1 month ago)
- Default Branch: master
- Last Pushed: 2026-04-27T02:14:37.000Z (about 1 month ago)
- Last Synced: 2026-04-27T04:17:57.511Z (about 1 month ago)
- Language: Go
- Size: 8.79 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Bitcask Simple Key-Value Store database in Golang
https://riak.com/assets/bitcask-intro.pdf
## Goals
1. DB Write - store data in file
2. DB Read - be able to read data
3. Handle file compaction
4. Handle segment merging
5. frequently writing hashmap into disk for faster reloading when database restarts
## Socket communication protocol
### Operations
1. get key
2. put key=value
3. delete key
format:
`[OPCODE][KEY SIZE][KEY][VALUE SIZE][VALUE]`
`[1][1][2][any size max 65,535 bytes]`
### OPCODE
We could represent op codes with 1 byte
1. GET -> 0
2. PUT -> 1
3. DELETE -> 2
### KEY SIZE
We would represent our key size with 1 byte giving us a maximum of key size of 255 bytes
### VALUE SIZE
We would represent our data length with 2 bytes giving us a maximum of approximately 64KiB of single data write
1 Byte = 8 bits
2 Byte = 16 bits
(2^16 - 1) = 0 - 65,535
### VALUE
we can read this based on the data length
Note: we can improve this protocol later
## Database File Format
SEGMENT would be in binary to save space and for easy write
SEGMENT FILE:
tstamp|key_size|value_sz|key|value
MEM MAP: Memory map
key -> file_id|tstamp|value_sz|value_pos