baradb is a Key/Value storage engine based on Bitcask model, which is a log-structured storage.
bara: バラ, Japanese name of rose
WRITE:
- Append a log record to the current active log file
- Update the index
READ:
- Find the position in the index by the given key
- If the position is found, then find the value of the given key in a log file by the position
$ go get -u github.com/saint-yellow/baradb
// launch a DB engine
opts := baradb.DefaultDBOptions
db, err := baradb.Launch(opts)
if err != nil {
panic(err)
}
// put a key/value pair to the DB engine
err = db.Put([]byte("114514"), []byte("1919810"))
if err != nil {
panic(err)
}
// get vlue of a key from the DB engine
value, err := db.Get([]byte("114514"))
if err != nil {
panic(err)
}
fmt.Println(string(value))
// delete a key/value pair from the DB engine
err = db.Delete([]byte("114514"))
if err != nil {
panic(err)
}
// initialze a write batch
wb := db.NewWriteBatch(baradb.DefaultWriteBatchOptions)
// put a key/value pair to the write batch
err = wb.Put([]byte("1919"), []byte("1919"))
if err != nil {
panic(err)
}
// the DB engine will not store data in the write batch
// since the write batch is not committed
value, err = db.Get([]byte("1919"))
if err != nil {
panic(err)
}
fmt.Println(string(value))
// delete a key/value pair in the write batch
err = wb.Delete([]byte("114514"))
if err != nil {
panic(err)
}
// commit the write batch
err = wb.Commit()
if err != nil {
panic(err)
}
// the DB engine can get data in the write batch
// that is successfully committed
value, err = db.Get([]byte("1919"))
if err != nil {
panic(err)
}
fmt.Println(string(value))
- Low latency per item read or written
- High throughput, especially when writing an incoming stream of random items
- Ability to handle datasets larger than RAM without degradation
- Single seek to retrieve any value
- Predictable lookup and insert performance
- Easy backup
- Batch options which guarantee atomicity, consistency, and durability
- Support iterator for forward and backward
- Keys must fit in memory
- Startup speed is affected by the amount of data
Integrate HTTP into the K/V storage engine
- Case: baradb-http
Implement Redis on the top of the K/V storage engine
- Case: baradb-redis
And... More!
PRs accepted.
MIT © Saint-Yellow