https://github.com/aixiasang/bitcask
一个基于Bitcask论文实现的高性能键值存储系统,具有简单、高效、持久化和崩溃恢复的特性。🚀 高性能读写操作:写入复杂度O(1),读取复杂度O(1) 💾 数据持久化:所有操作都会被记录到WAL文件 🛡️ 崩溃恢复:通过hint文件和WAL文件确保数据不丢失 🔄 自动文件轮转:防止单个数据文件过大 🔒 并发安全:支持多线程并发访问 🧹 数据合并:支持清理过期数据,优化存储空间
https://github.com/aixiasang/bitcask
bitcask database nosql
Last synced: about 2 months ago
JSON representation
一个基于Bitcask论文实现的高性能键值存储系统,具有简单、高效、持久化和崩溃恢复的特性。🚀 高性能读写操作:写入复杂度O(1),读取复杂度O(1) 💾 数据持久化:所有操作都会被记录到WAL文件 🛡️ 崩溃恢复:通过hint文件和WAL文件确保数据不丢失 🔄 自动文件轮转:防止单个数据文件过大 🔒 并发安全:支持多线程并发访问 🧹 数据合并:支持清理过期数据,优化存储空间
- Host: GitHub
- URL: https://github.com/aixiasang/bitcask
- Owner: aixiasang
- Created: 2025-03-21T03:38:24.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-03-29T12:11:10.000Z (about 1 year ago)
- Last Synced: 2025-03-29T13:23:05.617Z (about 1 year ago)
- Topics: bitcask, database, nosql
- Language: Go
- Homepage:
- Size: 105 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Bitcask
A high-performance key-value storage engine based on the [Bitcask](https://riak.com/assets/bitcask-intro.pdf) paper, written in Go.
Bitcask uses a log-structured storage model:
- **Write**: Append-only writes to the active data file, one sequential disk IO
- **Read**: In-memory index maps keys to file positions, one random disk IO
- **Merge**: Background compaction reclaims space from deleted/overwritten entries
## Features
**Core**
- High-performance read/write with O(1) complexity
- Multiple index types: B-tree / Skip List
- Atomic batch writes with WriteBatch
- CRC32 checksum for data integrity
- Configurable merge/compaction strategies
**Protocol**
- HTTP RESTful API
- Redis RESP protocol (compatible with redis-cli)
- Redis data structures: String / Hash / List / Set / ZSet
**Optimization**
- LRU cache for hot data
- Bloom filter to reduce disk IO
- TTL support with background cleanup
- Memory-mapped file IO (MMap)
## Quick Start
```go
opts := bitcask.DefaultOptions
opts.DirPath = "/tmp/bitcask"
db, _ := bitcask.Open(opts)
defer db.Close()
// Basic operations
db.Put([]byte("name"), []byte("bitcask"))
val, _ := db.Get([]byte("name"))
db.Delete([]byte("name"))
// Batch operations
wb := db.NewWriteBatch(bitcask.DefaultWriteBatchOptions)
wb.Put([]byte("k1"), []byte("v1"))
wb.Put([]byte("k2"), []byte("v2"))
wb.Commit()
// Iterator
iter := db.NewIterator(bitcask.DefaultIteratorOptions)
for iter.Rewind(); iter.Valid(); iter.Next() {
fmt.Printf("%s = %s\n", iter.Key(), iter.Value())
}
iter.Close()
```
## HTTP Server
```bash
# Start server
go run ./cmd/bitcask-server -dir ./data -http :8080
# Usage
curl -X PUT localhost:8080/api/v1/kv/name -d '{"value":"bitcask"}'
curl localhost:8080/api/v1/kv/name
curl -X DELETE localhost:8080/api/v1/kv/name
```
## Redis Server
```bash
# Start server
go run ./cmd/redis-server -dir ./data -addr :6379
# Use redis-cli
redis-cli -p 6379
> SET name bitcask
> GET name
> HSET user:1 name alice age 30
> LPUSH queue task1 task2
> ZADD scores 100 alice 90 bob
```
## License
MIT