Documentation ¶
Index ¶
- Variables
- func FastRand() uint32
- type Batch
- type BatchOption
- type BitFlag
- type DB
- func (db *DB) Backup(destpath string) error
- func (db *DB) Batch(opt BatchOption) (*Batch, error)
- func (db *DB) Begin(fn func(txn *Txn) error) error
- func (db *DB) Close() error
- func (db *DB) Del(key Key) error
- func (db *DB) Expire(key Key, ttl time.Duration) error
- func (db *DB) Get(key Key) (Value, error)
- func (db *DB) Merge(domerge bool) error
- func (db *DB) Purge() error
- func (db *DB) Put(key Key, value Value, ttl time.Duration) error
- func (db *DB) Range(option RangeOptions, handler RangeHandler) error
- func (db *DB) Recover(srcpath string) error
- func (db *DB) Stats() Stats
- func (db *DB) Sync() error
- func (db *DB) TTL(key Key) (time.Duration, error)
- func (db *DB) View(fn func(txn *Txn) error) error
- func (db *DB) Watcher(name string, events ...EventType) (*Watcher, error)
- type Event
- type EventType
- type Key
- type Option
- func WithBlockCache(block uint32) Option
- func WithClosedGc(gc bool) Option
- func WithCompare(compare index.Compare) Option
- func WithDir(dir string) Option
- func WithFsync(sync bool) Option
- func WithFsyncThreshold(threshold int64) Option
- func WithMaxSize(size int64) Option
- func WithMergeCheckPoint(checkPoint float64) Option
- func WithTxnLevel(level TxnLevel) Option
- func WithWatchEvent(events ...EventType) Option
- func WithWatchSize(size int) Option
- type Options
- type RangeHandler
- type RangeOptions
- type Record
- type Stats
- type Txn
- func (txn *Txn) Del(key Key) error
- func (txn *Txn) Expire(key Key, ttl time.Duration) error
- func (txn *Txn) Get(key Key) (Value, error)
- func (txn *Txn) Put(key Key, value Value, ttl time.Duration) error
- func (txn *Txn) Range(opt RangeOptions, handler RangeHandler) error
- func (txn *Txn) TTL(key Key) (time.Duration, error)
- type TxnLevel
- type Value
- type Watcher
Constants ¶
This section is empty.
Variables ¶
var ( ErrKeyNotFound = errors.New("key not found") ErrNilKey = entry.ErrNilKey ErrDBClosed = errors.New("db is already closed") ErrDirAlreadyUsed = errors.New("dir already used by another process") )
var ( ErrTxnClosed = errors.New("transaction is closed") ErrTxnReadonly = errors.New("transaction is read-only") ErrTxnConflict = errors.New("transaction is conflict") )
var ( ErrWatcherClosed = errors.New("watcher is closed") ErrInvalidEvent = errors.New("invalid event") ErrWatcherDisabled = errors.New("event watcher disabled") )
var DefaultOptions = Options{ MaxSize: defaultMaxFileSize, BlockCache: defaultMaxFileSize / types.MB, Fsync: false, FsyncThreshold: blockSize * (defaultMaxFileSize / types.MB) / 4, Compare: index.DefaultCompare, WatchSize: 2000, WatchEvents: []EventType{PutEvent, DelEvent}, Level: ReadCommitted, MergeCheckpoint: 0, }
var ErrBatchClosed = errors.New("batch is closed")
var (
ErrMergedNotFinished = errors.New("merged not finished")
)
Functions ¶
Types ¶
type Batch ¶ added in v0.2.0
type Batch struct {
// contains filtered or unexported fields
}
Batch operator
func (*Batch) DeleteAll ¶ added in v0.2.0
DeleteAll delete all given key matching records from db in batchTxn
type BatchOption ¶ added in v0.2.0
type BatchOption struct { // size of per batch Size int64 // call Fsync after per batch has been written SyncPerBatch bool // call Fsync after all batch finished, not recommended enabled both SyncPerBatch and SyncOnFlush simultaneously // if both of SyncPerBatch and SyncOnFlush is false, batch will apply sync rules in db.options SyncOnFlush bool }
type BitFlag ¶ added in v0.2.0
type BitFlag uint64
BitFlag 64-bit mask is used to store different status information
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
DB represents a db instance, which stores wal file in a specific data directory
func OpenWithCtx ¶ added in v0.1.0
OpenWithCtx returns a river db instance with context
func (*DB) Batch ¶ added in v0.2.0
func (db *DB) Batch(opt BatchOption) (*Batch, error)
Batch provides ability to write or delete entries in batch which is update-only, it will split given records into several batches, and run a new goroutine for each batch to handle in batchTxn. each batch records will be stored in memory temporarily, then they will be written to the database in batch finally update db index if commit succeeds.
func (*DB) Del ¶
Del remove the key-value pair match the give key from db. it will return nil if key not exist
func (*DB) Get ¶
Get returns value match the given key, if it expired or not found db will return ErrKeyNotFound. nil Key is not allowed.
func (*DB) Merge ¶
Merge clean the redundant data entry in db, shrinking the db size if domerge is false, it will only record of merged data, will not replace them to data dir
func (*DB) Put ¶
Put puts a key-value pair into db, overwrite value if key already exists. nil key is invalid, but nil value is allowed, it will be overwritten to empty []byte. if tll == 0, key will be persisted, or ttl < 0, key will apply the previous ttl.
func (*DB) Range ¶
func (db *DB) Range(option RangeOptions, handler RangeHandler) error
Range iterates over all the keys that match the given RangeOption and call handler for each key-value
func (*DB) Recover ¶ added in v0.1.0
Recover recovers wal files from specified targz archive. it will purge current data, and overwrite by the backup.
type Option ¶
type Option func(option *Options)
Option applying changes to the given option
func WithBlockCache ¶
func WithClosedGc ¶
func WithCompare ¶
func WithFsyncThreshold ¶
func WithMaxSize ¶
func WithMergeCheckPoint ¶ added in v0.3.0
func WithTxnLevel ¶ added in v0.3.0
func WithWatchEvent ¶ added in v0.1.0
func WithWatchSize ¶ added in v0.1.0
type Options ¶
type Options struct { // data dir that stores data files Dir string // max bytes size of the single data file can hold MaxSize int64 // wal block cache size BlockCache uint32 // call sync per write Fsync bool // call sync when reach the threshold FsyncThreshold int64 // kv put/get events size for watch queue, disabled if is 0 WatchSize int // specified events to watch WatchEvents []EventType // decide how to sort keys Compare index.Compare // check point of auto merge, disabled if is 0 MergeCheckpoint float64 // transaction isolation level Level TxnLevel // manually gc after closed db to release memory used by index ClosedGc bool // contains filtered or unexported fields }
Options represent db configuration
type RangeHandler ¶
RangeHandler iterate over key-value in db
type RangeOptions ¶
type RangeOptions = index.RangeOption
RangeOptions is alias of index.RangeOption
type Stats ¶ added in v0.2.0
type Stats struct { // number of key in db KeyNums int64 // number of values in db, due to bitcask model is append-only, it usually greater than KeyNums. // normally, result of RecordNums / KeyNums can be used to determine if is needed to merge the wal files RecordNums int64 // real data size DataSize int64 // hint file size HintSize int64 }
Stats represents a simple statistics information of db at a moment
type Txn ¶
type Txn struct {
// contains filtered or unexported fields
}
Txn represents a transaction
func (*Txn) Range ¶
func (txn *Txn) Range(opt RangeOptions, handler RangeHandler) error