flushable

package
v1.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 22, 2021 License: MIT Imports: 11 Imported by: 2

Documentation

Index

Constants

View Source
const (
	DirtyPrefix = 0xde
	CleanPrefix = 0x00
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Flushable

type Flushable struct {
	// contains filtered or unexported fields
}

Flushable is a kvdb.Store wrapper around any Database. On reading, it looks in memory cache first. If not found, it looks in a parent DB. On writing, it writes only in cache. To flush the cache into parent DB, call Flush().

func Wrap

func Wrap(parent kvdb.DropableStore) *Flushable

Wrap underlying db. All the writes into the cache won't be written in parent until .Flush() is called.

func WrapWithDrop

func WrapWithDrop(parent kvdb.Store, drop func()) *Flushable

WrapWithDrop is the same as Wrap, but defines onDrop callback.

func (*Flushable) Close

func (w *Flushable) Close() error

Close leaves underlying database.

func (*Flushable) Compact

func (w *Flushable) Compact(start []byte, limit []byte) error

Compact flattens the underlying data store for the given key range.

func (*Flushable) Delete

func (w *Flushable) Delete(key []byte) error

Delete removes key-value pair by key. In parent DB, key won't be deleted until .Flush() is called.

func (*Flushable) Drop

func (w *Flushable) Drop()

Drop whole database.

func (*Flushable) DropNotFlushed

func (w *Flushable) DropNotFlushed()

DropNotFlushed drops all the not flushed keys. After this call, the state of parent DB is identical to the state of this DB.

func (*Flushable) Flush

func (w *Flushable) Flush() error

Flush current cache into parent DB.

func (*Flushable) Get

func (w *Flushable) Get(key []byte) ([]byte, error)

Get returns key-value pair by key. Looks in cache first, then - in DB.

func (*Flushable) Has

func (w *Flushable) Has(key []byte) (bool, error)

Has checks if key is in the exists. Looks in cache first, then - in DB.

func (*Flushable) NewBatch

func (w *Flushable) NewBatch() kvdb.Batch

NewBatch creates new batch.

func (*Flushable) NewIterator

func (w *Flushable) NewIterator(prefix []byte, start []byte) kvdb.Iterator

NewIterator creates a binary-alphabetical iterator over a subset of database content with a particular key prefix, starting at a particular initial key (or after, if it does not exist).

func (*Flushable) NotFlushedPairs

func (w *Flushable) NotFlushedPairs() int

NotFlushedPairs returns num of not flushed keys, including deleted keys.

func (*Flushable) NotFlushedSizeEst

func (w *Flushable) NotFlushedSizeEst() int

NotFlushedSizeEst returns estimation of not flushed data, including deleted keys.

func (*Flushable) Put

func (w *Flushable) Put(key []byte, value []byte) error

Put puts key-value pair into the cache.

func (*Flushable) Stat

func (w *Flushable) Stat(property string) (string, error)

Stat returns a particular internal stat of the database.

type LazyFlushable

type LazyFlushable struct {
	*Flushable
	// contains filtered or unexported fields
}

LazyFlushable is a Flushable with delayed DB producer

func NewLazy

func NewLazy(producer func() (kvdb.DropableStore, error), drop func()) *LazyFlushable

NewLazy makes flushable with real db producer. Real db won't be produced until first .Flush() is called. All the writes into the cache won't be written in parent until .Flush() is called.

func (*LazyFlushable) Flush

func (w *LazyFlushable) Flush() (err error)

Flush current cache into parent DB. Real db won't be produced until first .Flush() is called.

func (*LazyFlushable) InitUnderlyingDb

func (w *LazyFlushable) InitUnderlyingDb() (kvdb.Store, error)

InitUnderlyingDb is UnderlyingDb getter. Makes underlying in lazy case.

type SyncedPool

type SyncedPool struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewSyncedPool

func NewSyncedPool(producer kvdb.DBProducer, flushIDKey []byte) *SyncedPool

func (*SyncedPool) Close

func (p *SyncedPool) Close() error

func (*SyncedPool) Flush

func (p *SyncedPool) Flush(id []byte) error

func (*SyncedPool) GetUnderlying

func (p *SyncedPool) GetUnderlying(name string) (kvdb.ReadonlyStore, error)

func (*SyncedPool) Initialize

func (p *SyncedPool) Initialize(dbNames []string) error

func (*SyncedPool) NotFlushedSizeEst

func (p *SyncedPool) NotFlushedSizeEst() int

NotFlushedSizeEst returns a total size of not flushed key pairs

func (*SyncedPool) OpenDB

func (p *SyncedPool) OpenDB(name string) (kvdb.DropableStore, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL