Documentation ¶
Index ¶
- Constants
- Variables
- type Bitcask
- func (b *Bitcask) Close() error
- func (b *Bitcask) Delete(key []byte) error
- func (b *Bitcask) DeleteAll() error
- func (b *Bitcask) Get(key []byte) (io.ReadCloser, 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) MergeWithWaitLimit(lim *priorate.Limiter) error
- func (b *Bitcask) MergeWithWaitLimitByBytesPerSecond(bytesPerSecond int) error
- func (b *Bitcask) Put(key []byte, value io.Reader) error
- func (b *Bitcask) PutBytes(key, value []byte) error
- func (b *Bitcask) PutBytesWithTTL(key, value []byte, ttl time.Duration) error
- func (b *Bitcask) PutWithTTL(key []byte, value io.Reader, ttl time.Duration) error
- func (b *Bitcask) Range(start, end []byte, f func(key []byte) error) (err error)
- func (b *Bitcask) Reopen() error
- func (b *Bitcask) RunGC() error
- func (b *Bitcask) Scan(prefix []byte, f func(key []byte) error) error
- func (b *Bitcask) Stats() (Stats, error)
- func (b *Bitcask) Sync() error
- type OptionFunc
- func WithCopyTempThreshold(size int64) OptionFunc
- func WithDirFileModeBeforeUmask(mode os.FileMode) OptionFunc
- func WithFileFileModeBeforeUmask(mode os.FileMode) OptionFunc
- func WithLogger(logger *log.Logger) OptionFunc
- func WithMaxDatafileSize(size int) OptionFunc
- func WithRepli(bindIP string, bindPort int) OptionFunc
- func WithRepliClient(serverIP string, serverPort int) OptionFunc
- func WithRepliClientRequestTimeout(rto time.Duration) OptionFunc
- func WithRuntimeContext(ctx runtime.Context) OptionFunc
- func WithSync(sync bool) OptionFunc
- func WithTempDir(dir string) OptionFunc
- func WithValidateChecksum(enable bool) OptionFunc
- type Stats
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 = 100 * 1024 * 1024 // 100MB // Data size exceeding this threshold to temporarily copied to TempDir DefaultCopyTempThrshold int64 = 10 * 1024 * 1024 // DefaultSync is the default file synchronization action DefaultSync = false DefaultNoRepliEmit bool = true DefaultRepliBindIP string = "[0.0.0.0]" DefaultRepliBindPort int = 4220 DefaultNoRepliRecv bool = true DefaultRepliServerIP string = "127.0.0.1" DefaultRepliServerPort int = 4220 DefaultRepliRequestTimeout time.Duration = 10 * time.Second )
const ( AppName string = "bitcaskdb" Version string = "1.6.1" )
Variables ¶
var ( // ErrKeyNotFound is the error returned when a key is not found ErrKeyNotFound = errors.New("error: key not found") // 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") // 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") // 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 ¶
func Open(path string, funcs ...OptionFunc) (*Bitcask, error)
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) DeleteAll ¶
DeleteAll deletes all the keys. If an I/O error occurs the error is returned.
func (*Bitcask) Get ¶
func (b *Bitcask) Get(key []byte) (io.ReadCloser, error)
Get fetches value for a key
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) MergeWithWaitLimit ¶ added in v1.3.1
func (*Bitcask) MergeWithWaitLimitByBytesPerSecond ¶ added in v1.3.1
func (*Bitcask) PutBytesWithTTL ¶
func (*Bitcask) PutWithTTL ¶
PutWithTTL stores the key and value in the database with the given TTL
func (*Bitcask) Range ¶
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) 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.
type OptionFunc ¶
type OptionFunc func(*option) error
Option is a function that takes a option struct and modifies it
func WithCopyTempThreshold ¶
func WithCopyTempThreshold(size int64) OptionFunc
func WithDirFileModeBeforeUmask ¶
func WithDirFileModeBeforeUmask(mode os.FileMode) OptionFunc
WithDirFileModeBeforeUmask sets the FileMode used for each new file created.
func WithFileFileModeBeforeUmask ¶
func WithFileFileModeBeforeUmask(mode os.FileMode) OptionFunc
WithFileFileModeBeforeUmask sets the FileMode used for each new file created.
func WithLogger ¶
func WithLogger(logger *log.Logger) OptionFunc
func WithMaxDatafileSize ¶
func WithMaxDatafileSize(size int) OptionFunc
WithMaxDatafileSize sets the maximum datafile size option
func WithRepli ¶
func WithRepli(bindIP string, bindPort int) OptionFunc
func WithRepliClient ¶
func WithRepliClient(serverIP string, serverPort int) OptionFunc
func WithRepliClientRequestTimeout ¶
func WithRepliClientRequestTimeout(rto time.Duration) OptionFunc
func WithRuntimeContext ¶
func WithRuntimeContext(ctx runtime.Context) OptionFunc
func WithSync ¶
func WithSync(sync bool) OptionFunc
WithSync causes Sync() to be called on every key/value written increasing durability and safety at the expense of performance
func WithTempDir ¶
func WithTempDir(dir string) OptionFunc
func WithValidateChecksum ¶
func WithValidateChecksum(enable bool) OptionFunc