Documentation
¶
Overview ¶
Package bitcask implements a high-performance key-value store based on a WAL and LSM.
By default, the client assumes a default configuration regarding maximum key size, maximum value size, maximum datafile size, and memory pools to avoid allocations. Refer to Constants section to know default values.
For extra performance, configure the memory pool option properly. This option requires to specify the maximum number of concurrent use of the package. Failing to set a high-enough value would impact latency and throughput. Likewise, overestimating would yield in an unnecessary big memory footprint. The default configuration doesn't use a memory pool.
Example ¶
_, _ = Open("path/to/db")
Example (WithOptions) ¶
opts := []Option{ WithMaxKeySize(1024), WithMaxValueSize(4096), WithMemPool(10), } _, _ = Open("path/to/db", opts...)
Index ¶
- Constants
- Variables
- func Merge(path string, force bool) error
- type Bitcask
- func (b *Bitcask) Close() error
- func (b *Bitcask) Delete(key string) error
- func (b *Bitcask) Fold(f func(key string) error) error
- func (b *Bitcask) Get(key string) ([]byte, error)
- func (b *Bitcask) Has(key string) bool
- func (b *Bitcask) Keys() chan string
- func (b *Bitcask) Len() int
- func (b *Bitcask) Merge() error
- func (b *Bitcask) Put(key string, value []byte) error
- func (b *Bitcask) Scan(prefix string, f func(key string) error) error
- func (b *Bitcask) Stats() (stats Stats, err error)
- func (b *Bitcask) Sync() error
- type Option
- type Stats
Examples ¶
Constants ¶
const ( // DefaultMaxDatafileSize is the default maximum datafile size in bytes DefaultMaxDatafileSize = 1 << 20 // 1MB // DefaultMaxKeySize is the default maximum key size in bytes DefaultMaxKeySize = 64 // 64 bytes // DefaultMaxValueSize is the default value size in bytes DefaultMaxValueSize = 1 << 16 // 65KB )
Variables ¶
var ( // ErrKeyNotFound is the error returned when a key is not found ErrKeyNotFound = errors.New("error: key not found") // ErrKeyTooLarge is the error returned for a key that exceeds the // maximum allowed key size (configured with WithMaxKeySize). ErrKeyTooLarge = errors.New("error: key too large") // ErrValueTooLarge is the error returned for a value that exceeds the // maximum allowed value size (configured with WithMaxValueSize). ErrValueTooLarge = errors.New("error: value too large") // ErrChecksumFailed is the error returned if a key/value retrieved does // not match its CRC checksum ErrChecksumFailed = errors.New("error: checksum failed") // ErrDatabaseLocked is the error returned if the database is locked // (typically opened by another process) ErrDatabaseLocked = errors.New("error: database locked") // ErrCreatingMemPool is the error returned when trying to configurate // the mempool fails ErrCreatingMemPool = errors.New("error: creating the mempool failed") )
var ( // ErrMaxConcurrencyLowerEqZero is the error returned for // maxConcurrency option not greater than zero ErrMaxConcurrencyLowerEqZero = errors.New("error: maxConcurrency must be greater than zero") )
Functions ¶
Types ¶
type Bitcask ¶
Bitcask is a struct that represents a on-disk LSM and WAL data structure and in-memory hash of key/value pairs as per the Bitcask paper and seen in the Riak database.
func Open ¶
Open opens the database at the given path with optional options. Options can be provided with the `WithXXX` functions that provide configuration options as functions.
func (*Bitcask) Close ¶
Close closes the database and removes the lock. It is important to call Close() as this is the only way to cleanup the lock held by the open database.
func (*Bitcask) Delete ¶
Delete deletes the named key. If the key doesn't exist or an I/O error occurs the error is returned.
func (*Bitcask) Fold ¶
Fold iterates over all keys in the database calling the function `f` for each key. If the function returns an error, no further keys are processed and the error returned.
func (*Bitcask) Get ¶
Get retrieves the value of the given key. If the key is not found or an/I/O error occurs a null byte slice is returned along with the error.
func (*Bitcask) Merge ¶ added in v0.2.2
Merge merges all datafiles in the database. Old keys are squashed and deleted keys removes. Duplicate key/value pairs are also removed. Call this function periodically to reclaim disk space.
func (*Bitcask) Scan ¶
Scan performs a prefix scan of keys matching the given prefix and calling the function `f` with the keys found. If the function returns an error no further keys are processed and the first error returned.
type Option ¶
type Option func(*config) error
Option is a function that takes a config struct and modifies it
func WithMaxDatafileSize ¶
WithMaxDatafileSize sets the maximum datafile size option
func WithMaxKeySize ¶
WithMaxKeySize sets the maximum key size option
func WithMaxValueSize ¶
WithMaxValueSize sets the maximum value size option
func WithMemPool ¶ added in v0.3.1
WithMemPool configures usage of a memory pool to avoid allocations