store

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2020 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const Unlimited = 0

Variables

View Source
var (
	ErrNotFound = errors.New("not found")
)

Functions

func Register

func Register(reg *Registration)

Types

type BatchPut

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

func NewBatchPut

func NewBatchPut(sizeThreshold int, putsThreshold int, timeThreshold time.Duration) *BatchPut

func (*BatchPut) GetBatch

func (b *BatchPut) GetBatch() []*KV

func (*BatchPut) Put

func (b *BatchPut) Put(key, value []byte)

func (*BatchPut) Reset

func (b *BatchPut) Reset()

func (*BatchPut) ShouldFlush

func (b *BatchPut) ShouldFlush() bool

type Compressor

type Compressor interface {
	Compress(in []byte) []byte
	Decompress(in []byte) ([]byte, error)
}

func NewCompressor

func NewCompressor(mode string) (Compressor, error)

type Iterator

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

Iterator can end in any of those scenarios:

  1. PushError() is called by the db backend
  2. PushComplete() is called by the db backend and Next() is called by consumer until items channel is empty
  3. The context given by the consumer is cancelled, notifying the db backend and (hopefully) causing a PushError() to be called with context.Canceled

In any of these cases, the following call to Next() returns false.

Assumptions:

* Next() must never be called again after it returned `false` * No other Push...() function is called PushFinished() or PushError(). * Next(), Item() and Error() are never called concurrently. * PushItem(), PushFinished() and PushError() are never called concurrently. * If the reader wants to finish early, it should close the context to prevent waste

func NewIterator

func NewIterator(ctx context.Context) *Iterator

NewIterator provides a streaming resultset for key/value queries

func (*Iterator) Err

func (it *Iterator) Err() error

func (*Iterator) Item

func (it *Iterator) Item() KV

func (*Iterator) Next

func (it *Iterator) Next() bool

func (*Iterator) PushError

func (it *Iterator) PushError(err error)

func (*Iterator) PushFinished

func (it *Iterator) PushFinished()

func (*Iterator) PushItem

func (it *Iterator) PushItem(res KV) bool

Results gathering primitives

type KV

type KV struct {
	Key, Value []byte
}

type KVStore

type KVStore interface {
	// Put writes to a transaction, which might be flushed from time to time. Call FlushPuts() to ensure all Put entries are properly written to the database.
	Put(ctx context.Context, key, value []byte) (err error)
	// FlushPuts takes any pending writes (calls to Put()), and flushes them.
	FlushPuts(ctx context.Context) (err error)

	// Get a given key.  Returns `kvdb.ErrNotFound` if not found.
	Get(ctx context.Context, key []byte) (value []byte, err error)
	// Get a batch of keys.  Returns `kvdb.ErrNotFound` the first time a key is not found: not finding a key is fatal and interrupts the resultset from being fetched completely.  BatchGet guarantees that Iterator return results in the exact same order as keys
	BatchGet(ctx context.Context, keys [][]byte) *Iterator

	Scan(ctx context.Context, start, exclusiveEnd []byte, limit int) *Iterator

	Prefix(ctx context.Context, prefix []byte, limit int) *Iterator
	BatchPrefix(ctx context.Context, prefixes [][]byte, limit int) *Iterator
}

func New

func New(dsn string, opts ...Option) (KVStore, error)

type Key

type Key []byte

func (Key) String

func (k Key) String() string

type Limit

type Limit int

func (Limit) Bounded

func (l Limit) Bounded() bool

func (Limit) Reached

func (l Limit) Reached(count uint64) bool

func (Limit) String

func (l Limit) String() string

func (Limit) Unbounded

func (l Limit) Unbounded() bool

type NewStoreFunc

type NewStoreFunc func(path string, opts ...Option) (KVStore, error)

NewStoreFunc is a function for opening a databse.

type NoOpCompressor

type NoOpCompressor struct{}

func NewNoOpCompressor

func NewNoOpCompressor() *NoOpCompressor

func (NoOpCompressor) Compress

func (NoOpCompressor) Compress(in []byte) []byte

func (NoOpCompressor) Decompress

func (NoOpCompressor) Decompress(in []byte) ([]byte, error)

type Option

type Option string
const (
	// TIKV does not support empty values, thus the consumer of KVDB needs
	// to let the underlying driver (i.e. TIVK) know that the values may
	// be empty ( i.e. flux writing keys with no values to signify deletion)
	// in which case said driver woudl take that into account when
	// writing and reading data
	WithEmptyValueSupport Option = "WithEmptyValueSupport"
)

type Registration

type Registration struct {
	Name        string // unique name
	Title       string // human-readable name
	FactoryFunc NewStoreFunc
}

func ByName

func ByName(name string) *Registration

ByName returns a registered store driver

type ReversibleKVStore

type ReversibleKVStore interface {
	ReverseScan(ctx context.Context, start, exclusiveEnd []byte, limit int) *Iterator
	ReversePrefix(ctx context.Context, prefix []byte, limit int) *Iterator
}

type ZstdCompressor

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

func NewZstdCompressor

func NewZstdCompressor() *ZstdCompressor

func (*ZstdCompressor) Compress

func (c *ZstdCompressor) Compress(in []byte) (out []byte)

func (*ZstdCompressor) Decompress

func (c *ZstdCompressor) Decompress(in []byte) ([]byte, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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