Documentation ¶
Overview ¶
Package bitcask implements a high-performance key-value store based on a WAL and LSM.
Example ¶
_, _ = Open("path/to/db")
Output:
Example (WithOptions) ¶
opts := []Option{ WithMaxKeySize(1024), WithMaxValueSize(4096), } _, _ = Open("path/to/db", opts...)
Output:
Index ¶
- Constants
- Variables
- type Bitcask
- func (b *Bitcask) Backup(path string) error
- func (b *Bitcask) Close() error
- func (b *Bitcask) Delete(key []byte) error
- func (b *Bitcask) DeleteAll() (err error)
- func (b *Bitcask) Fold(f func(key []byte) error) (err error)
- func (b *Bitcask) Get(key []byte) ([]byte, error)
- func (b *Bitcask) Has(key []byte) bool
- func (b *Bitcask) Keys() chan []byte
- func (b *Bitcask) Len() int
- func (b *Bitcask) Merge() error
- func (b *Bitcask) Put(key, value []byte) error
- func (b *Bitcask) PutWithTTL(key, value []byte, ttl time.Duration) error
- func (b *Bitcask) Range(start, end []byte, f func(key []byte) error) (err error)
- func (b *Bitcask) Reclaimable() int64
- func (b *Bitcask) Reopen() error
- func (b *Bitcask) RunGC() error
- func (b *Bitcask) Scan(prefix []byte, f func(key []byte) error) (err error)
- func (b *Bitcask) Sift(f func(key []byte) (bool, error)) (err error)
- func (b *Bitcask) SiftRange(start, end []byte, f func(key []byte) (bool, error)) (err error)
- func (b *Bitcask) SiftScan(prefix []byte, f func(key []byte) (bool, error)) (err error)
- func (b *Bitcask) Stats() (stats Stats, err error)
- func (b *Bitcask) Sync() error
- type ErrBadConfig
- type ErrBadMetadata
- type Option
- func WithAutoRecovery(enabled bool) Option
- func WithDirFileModeBeforeUmask(mode os.FileMode) Option
- func WithFileFileModeBeforeUmask(mode os.FileMode) Option
- func WithMaxDatafileSize(size int) Option
- func WithMaxKeySize(size uint32) Option
- func WithMaxValueSize(size uint64) Option
- func WithSync(sync bool) Option
- type Stats
Examples ¶
Constants ¶
const ( // DefaultDirFileModeBeforeUmask is the default os.FileMode used when creating directories DefaultDirFileModeBeforeUmask = os.FileMode(0700) // DefaultFileFileModeBeforeUmask is the default os.FileMode used when creating files DefaultFileFileModeBeforeUmask = os.FileMode(0600) // DefaultMaxDatafileSize is the default maximum datafile size in bytes DefaultMaxDatafileSize = 1 << 20 // 1MB // DefaultMaxKeySize is the default maximum key size in bytes DefaultMaxKeySize = uint32(64) // 64 bytes // DefaultMaxValueSize is the default value size in bytes DefaultMaxValueSize = uint64(1 << 16) // 65KB // DefaultSync is the default file synchronization action DefaultSync = false CurrentDBVersion = uint32(1) )
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") // ErrKeyExpired is the error returned when a key is queried which has // already expired (due to ttl) ErrKeyExpired = errors.New("error: key expired") // ErrEmptyKey is the error returned for a value with an empty key. ErrEmptyKey = errors.New("error: empty key") // 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") // ErrInvalidRange is the error returned when the range scan is invalid ErrInvalidRange = errors.New("error: invalid range") // ErrInvalidVersion is the error returned when the database version is invalid ErrInvalidVersion = errors.New("error: invalid db version") // ErrMergeInProgress is the error returned if merge is called when already a merge // is in progress ErrMergeInProgress = errors.New("error: merge already in progress") )
Functions ¶
This section is empty.
Types ¶
type Bitcask ¶
type Bitcask struct {
// contains filtered or unexported fields
}
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) Backup ¶
Backup copies db directory to given path it creates path if it does not exist
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) DeleteAll ¶
DeleteAll deletes all the keys. If 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 is returned.
func (*Bitcask) Merge ¶
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) PutWithTTL ¶
PutWithTTL stores the key and value in the database with the given TTL
func (*Bitcask) Range ¶ added in v0.3.14
Range performs a range scan of keys matching a range of keys between the start key and end key 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.
func (*Bitcask) Reclaimable ¶
Reclaimable returns space that can be reclaimed
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 is returned.
func (*Bitcask) Sift ¶ added in v0.3.14
Sift iterates over all keys in the database calling the function `f` for each key. If the KV pair is expired or the function returns true, that key is deleted from the database. If the function returns an error on any key, no further keys are processed, no keys are deleted, and the first error is returned.
func (*Bitcask) SiftRange ¶ added in v0.3.14
SiftRange performs a range scan of keys matching a range of keys between the start key and end key and calling the function `f` with the keys found. If the KV pair is expired or the function returns true, that key is deleted from the database. If the function returns an error on any key, no further keys are processed, no keys are deleted, and the first error is returned.
func (*Bitcask) SiftScan ¶ added in v0.3.14
SiftScan iterates over all keys in the database beginning with the given prefix, calling the function `f` for each key. If the KV pair is expired or the function returns true, that key is deleted from the database.
If the function returns an error on any key, no further keys are processed,
no keys are deleted, and the first error is returned.
type ErrBadConfig ¶ added in v1.0.1
type ErrBadConfig struct {
Err error
}
ErrBadConfig is the error returned on failure to load the database config
func (*ErrBadConfig) Error ¶ added in v1.0.1
func (e *ErrBadConfig) Error() string
func (*ErrBadConfig) Is ¶ added in v1.0.1
func (e *ErrBadConfig) Is(target error) bool
func (*ErrBadConfig) Unwrap ¶ added in v1.0.1
func (e *ErrBadConfig) Unwrap() error
type ErrBadMetadata ¶ added in v1.0.1
type ErrBadMetadata struct {
Err error
}
ErrBadMetadata is the error returned on failure to load the database metadata
func (*ErrBadMetadata) Error ¶ added in v1.0.1
func (e *ErrBadMetadata) Error() string
func (*ErrBadMetadata) Is ¶ added in v1.0.1
func (e *ErrBadMetadata) Is(target error) bool
func (*ErrBadMetadata) Unwrap ¶ added in v1.0.1
func (e *ErrBadMetadata) Unwrap() error
type Option ¶
Option is a function that takes a config struct and modifies it
func WithAutoRecovery ¶
WithAutoRecovery sets auto recovery of data and index file recreation. IMPORTANT: This flag MUST BE used only if a proper backup was made of all the existing datafiles.
func WithDirFileModeBeforeUmask ¶
WithDirFileModeBeforeUmask sets the FileMode used for each new file created.
func WithFileFileModeBeforeUmask ¶
WithFileFileModeBeforeUmask sets the FileMode used for each new file created.
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