Skip to content

Commit

Permalink
Merge pull request #16 from octu0/v1.5.1
Browse files Browse the repository at this point in the history
v1.5.1
  • Loading branch information
octu0 authored Jul 19, 2022
2 parents b391ba1 + f715681 commit d88255d
Show file tree
Hide file tree
Showing 7 changed files with 490 additions and 81 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

/tmp
/dist
/data
/cacheDb
/coverage.txt

Expand Down
69 changes: 68 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,79 @@
[![Releases](https://img.shields.io/github/v/release/octu0/bitcaskdb)](https://github.com/octu0/bitcaskdb/releases)

Original code is [bitcask](https://git.mills.io/prologic/bitcask) and `bitcaskdb` modifies I/O operations and implement replication.
Small Value are still operated in memory, large Value are directly I/O operation on disk.
Small Value are still operated in memory, Large Value are directly I/O operation on disk.
This makes it possible to perform Merge operations and large data store with minimal RAM utilization.

A high performance Key/Value store written in [Go](https://golang.org) with a predictable read/write performance and high throughput.
Uses a [Bitcask](https://en.wikipedia.org/wiki/Bitcask) on-disk layout (LSM+WAL) similar to [Riak](https://riak.com/).

## Installation

```shell
go get github.com/octu0/bitcaskdb
```

## Example

`bitcaskdb` methods are implemented to use [io.Reader](https://pkg.go.dev/io#Reader) / [io.ReadCloser](https://pkg.go.dev/io#ReadCloser), etc.

```go
import (
"bytes"
"io"
"fmt"

"github.com/octu0/bitcaskdb"
)

func main() {
db, err := bitcaskdb.Open("./data/mydb")
if err != nil {
panic(err)
}
defer db.Close()

// PutBytes() can be set using byte slice
db.PutBytes([]byte("hello"), []byte("world"))

// Get() returns io.ReadCloser
r, err := db.Get([]byte("hello"))
if err != nil {
panic(err)
}
defer r.Close()

data, _ := io.ReadAll(r)

// Put() can be specify io.Reader
db.Put([]byte("foo"), bytes.NewReader([]byte("very large data...")))

// PutWithTTL()/PutBytesWithTTL() can be set to data with expiration time
db.PutWithTTL([]byte("bar"), bytes.NewReader(data), 10*time.Second)

// Sync() flushes all buffers to disk
db.Sync()

r, err := db.Get([]byte("foo"))
if err != nil {
panic(err)
}
defer r.Close()

head := make([]byte, 4)
r.Read(head)

// Delete() can delete data with key
db.Delete([]byte("foo"))

// RunGC() deletes all expired keys
db.RunGC()

// Merge() rebuilds databases and reclaims disk space
db.Merge()
}
```

## Benchmark

`bitcaskdb` is tuned for larger sizes of Value, in particular there is a major improvement for inputs and outputs using [io.Reader](https://pkg.go.dev/io#Reader).
Expand Down
Loading

0 comments on commit d88255d

Please sign in to comment.