store

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2022 License: Apache-2.0 Imports: 15 Imported by: 16

Documentation

Index

Constants

View Source
const Unlimited = 0

Variables

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

Functions

func Register

func Register(reg *Registration)

func RegisterTestKVDBDriver

func RegisterTestKVDBDriver()

func RemoveDSNOptions

func RemoveDSNOptions(dsn string, keys ...string) (string, error)

RemoveDSNOptions takes a DSN url string and removes from it any query options matching one of the `key` received in parameter.

For example, transforms `kv://path?option1=value&option2=test&option3=any` to `kv://path?option2=test` when passing `option1` and `option3` as the keys.

func RemoveDSNOptionsFromURL

func RemoveDSNOptionsFromURL(dsnURL *url.URL, keys ...string) *url.URL

RemoveDSNOptionsFromURL takes a DSN URL and removes from it any query options matching one of the `key` received in parameter.

For example, transforms `kv://path?option1=value&option2=test&option3=any` to `kv://path?option2=test` when passing `option1` and `option3` as the keys.

Types

type BatchOp

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

func NewBatchOp

func NewBatchOp(sizeThreshold int, optsThreshold int, timeThreshold time.Duration) *BatchOp

func (*BatchOp) GetBatch

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

func (*BatchOp) MarshalLogObject

func (b *BatchOp) MarshalLogObject(enc zapcore.ObjectEncoder) error

func (*BatchOp) Op

func (b *BatchOp) Op(key, value []byte)

func (*BatchOp) Reset

func (b *BatchOp) Reset()

func (*BatchOp) ShouldFlush

func (b *BatchOp) ShouldFlush() bool

func (*BatchOp) Size

func (b *BatchOp) Size() int

func (*BatchOp) WouldFlushNext

func (b *BatchOp) WouldFlushNext(key []byte, value []byte) bool

WouldFlushNext determines if adding another item with the specified `len(key) + len(value)` would trigger a flush of the batch. This can be used to push a batch preemptively before inserting and item that would make the batch bigger than allowed max size.

type Compressor

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

	zapcore.ObjectMarshaler
}

func NewCompressor

func NewCompressor(mode string, thresholdInBytes int) (Compressor, error)

type DSNQuery

type DSNQuery url.Values

func (DSNQuery) DurationOption

func (q DSNQuery) DurationOption(name string, defaultValue time.Duration) (time.Duration, string, error)

func (DSNQuery) IntOption

func (q DSNQuery) IntOption(name string, defaultValue int) (int, string, error)

func (DSNQuery) StringOption

func (q DSNQuery) StringOption(name string, defaultValue string) (value string, rawValue string)

type EmtpyValueEnabler

type EmtpyValueEnabler interface {
	EnableEmpty()
}

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
}

func (*KV) Size

func (kv *KV) Size() int

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, options ...ReadOption) *Iterator

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

	BatchDelete(ctx context.Context, keys [][]byte) (err error)

	// Close the underlying store engine and clear up any resources currently hold
	// by this instance.
	//
	// Once this instance's `Close` method has been called, it's assumed to be terminated
	// and cannot be reliably used to perform read/write operation on the backing engine.
	Close() error
}

func New

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

func NewTestKVDBDriverFactory

func NewTestKVDBDriverFactory(dsn string) (KVStore, error)

type Key

type Key []byte

func (Key) Next

func (k Key) Next() Key

Next returns the next key in byte-order.

Copied from https://github.com/tikv/client-go/blob/master/key/key.go

func (Key) PrefixNext

func (k Key) PrefixNext() Key

PrefixNext returns the next prefix key.

Assume there are keys like:

rowkey1
rowkey1_column1
rowkey1_column2
rowKey2

If we seek 'rowkey1' Next, we will get 'rowkey1_column1'. If we seek 'rowkey1' PrefixNext, we will get 'rowkey2'.

Copied from https://github.com/tikv/client-go/blob/master/key/key.go

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) (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)

func (NoOpCompressor) MarshalLogObject

func (NoOpCompressor) MarshalLogObject(enc zapcore.ObjectEncoder) error

type Option

type Option interface {
	// contains filtered or unexported methods
}

func WithEmptyValue

func WithEmptyValue() Option

type Purgeable

type Purgeable interface {
	MarkCurrentHeight(height uint64)
	PurgeKeys(ctx context.Context) error
}

type PurgeableKVStore

type PurgeableKVStore struct {
	KVStore
	// contains filtered or unexported fields
}

func NewPurgeableStore

func NewPurgeableStore(tablePrefix []byte, store KVStore, ttlInBlocks uint64) *PurgeableKVStore

func (*PurgeableKVStore) MarkCurrentHeight

func (s *PurgeableKVStore) MarkCurrentHeight(height uint64)

func (*PurgeableKVStore) PurgeKeys

func (s *PurgeableKVStore) PurgeKeys(ctx context.Context) error

func (*PurgeableKVStore) Put

func (s *PurgeableKVStore) Put(ctx context.Context, key, value []byte) error

type ReadOption

type ReadOption interface {
	Apply(o *ReadOptions)
}

func KeyOnly

func KeyOnly() ReadOption

type ReadOptions

type ReadOptions struct {
	KeyOnly bool
}

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
}

ReversibleKVStore is not currently used. Was to be an optimization to avoid writing block numbers twice (to search the timeline), for stores that support reverse scans (unlike Bigtable).

type TestKVDBDriver

type TestKVDBDriver struct {
	DSN string
}

func NewTestKVDBDriver

func NewTestKVDBDriver(dsn string) *TestKVDBDriver

func (*TestKVDBDriver) BatchDelete

func (t *TestKVDBDriver) BatchDelete(ctx context.Context, keys [][]byte) (err error)

func (*TestKVDBDriver) BatchGet

func (t *TestKVDBDriver) BatchGet(ctx context.Context, keys [][]byte) *Iterator

func (*TestKVDBDriver) BatchPrefix

func (t *TestKVDBDriver) BatchPrefix(ctx context.Context, prefixes [][]byte, limit int, options ...ReadOption) *Iterator

func (*TestKVDBDriver) Close

func (t *TestKVDBDriver) Close() error

func (*TestKVDBDriver) FlushPuts

func (t *TestKVDBDriver) FlushPuts(ctx context.Context) (err error)

func (*TestKVDBDriver) Get

func (t *TestKVDBDriver) Get(ctx context.Context, key []byte) (value []byte, err error)

func (*TestKVDBDriver) Prefix

func (t *TestKVDBDriver) Prefix(ctx context.Context, prefix []byte, limit int, options ...ReadOption) *Iterator

func (*TestKVDBDriver) Put

func (t *TestKVDBDriver) Put(ctx context.Context, key, value []byte) (err error)

func (*TestKVDBDriver) Scan

func (t *TestKVDBDriver) Scan(ctx context.Context, start, exclusiveEnd []byte, limit int, options ...ReadOption) *Iterator

type TestPurgeableKVDBDriver

type TestPurgeableKVDBDriver struct {
	KVStore
	DSN string
}

func NewTestPurgeableKVDBDriver

func NewTestPurgeableKVDBDriver(dsn string) *TestPurgeableKVDBDriver

func (*TestPurgeableKVDBDriver) MarkCurrentHeight

func (t *TestPurgeableKVDBDriver) MarkCurrentHeight(height uint64)

func (*TestPurgeableKVDBDriver) PurgeKeys

func (t *TestPurgeableKVDBDriver) PurgeKeys(ctx context.Context) error

type ZstdCompressor

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

func NewZstdCompressor

func NewZstdCompressor(thresholdInBytes int) *ZstdCompressor

func (*ZstdCompressor) Compress

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

func (*ZstdCompressor) Decompress

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

func (*ZstdCompressor) MarshalLogObject

func (c *ZstdCompressor) MarshalLogObject(enc zapcore.ObjectEncoder) error

Directories

Path Synopsis
pb

Jump to

Keyboard shortcuts

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