store

package
v0.25.1-staging Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2020 License: Apache-2.0 Imports: 9 Imported by: 3

Documentation

Index

Constants

View Source
const (
	// DefaultFreeListSize is the size we hold for free node in btree
	DefaultFreeListSize = btree.DefaultFreeListSize
)

Variables

View Source
var Pair = weave.Pair

Pair is an alias to function in root package

Functions

func LogableStore added in v0.11.2

func LogableStore() (CacheableKVStore, ShowOpser)

LogableStore will return a store, along with insight into all operations that were run on it

Types

type BTreeCacheWrap

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

BTreeCacheWrap places a btree cache over a KVStore

func NewBTreeCacheWrap

func NewBTreeCacheWrap(kv ReadOnlyKVStore, batch Batch,
	free *btree.FreeList) BTreeCacheWrap

NewBTreeCacheWrap initializes a BTree to cache around this kv store. Use ReadOnlyKVStore to emphasize that all writes must go through the Batch.

free may be nil, but set to an existing list to reuse it for memory savings

func (BTreeCacheWrap) CacheWrap

func (b BTreeCacheWrap) CacheWrap() KVCacheWrap

CacheWrap layers another BTree on top of this one. Don't change horses in mid-stream....

Uses NonAtomicBatch as it is only backed by another in-memory batch

func (BTreeCacheWrap) Delete

func (b BTreeCacheWrap) Delete(key []byte) error

Delete deletes from the BTree and to the batch

func (BTreeCacheWrap) Discard

func (b BTreeCacheWrap) Discard()

Discard invalidates this CacheWrap and releases all data

TODO: currently noop....leave it to the garbage collector

func (BTreeCacheWrap) Get

func (b BTreeCacheWrap) Get(key []byte) ([]byte, error)

Get reads from btree if there, else backing store

func (BTreeCacheWrap) Has

func (b BTreeCacheWrap) Has(key []byte) (bool, error)

Has reads from btree if there, else backing store

func (BTreeCacheWrap) Iterator

func (b BTreeCacheWrap) Iterator(start, end []byte) (Iterator, error)

Iterator over a domain of keys in ascending order. Combines results from btree and backing store

func (BTreeCacheWrap) NewBatch

func (b BTreeCacheWrap) NewBatch() Batch

NewBatch returns a non-atomic batch that eventually may write to our cachewrap

func (BTreeCacheWrap) ReverseIterator

func (b BTreeCacheWrap) ReverseIterator(start, end []byte) (Iterator, error)

ReverseIterator over a domain of keys in descending order. Combines results from btree and backing store

func (BTreeCacheWrap) Set

func (b BTreeCacheWrap) Set(key, value []byte) error

Set writes to the BTree and to the batch

func (BTreeCacheWrap) Write

func (b BTreeCacheWrap) Write() error

Write syncs with the underlying store. And then cleans up

type BTreeCacheable

type BTreeCacheable struct {
	KVStore
}

BTreeCacheable adds a simple btree-based CacheWrap strategy to a KVStore

func (BTreeCacheable) CacheWrap

func (b BTreeCacheable) CacheWrap() KVCacheWrap

CacheWrap returns a BTreeCacheWrap that can be later written to this store, or rolled back

type Batch

type Batch = weave.Batch

Batch is an alias to interface in root package

type CacheableKVStore

type CacheableKVStore = weave.CacheableKVStore

CacheableKVStore is an alias to interface in root package

func MemStore

func MemStore() CacheableKVStore

MemStore returns a simple implementation useful for tests. There is no persistence here....

type CommitID

type CommitID = weave.CommitID

CommitID is an alias to interface in root package

type CommitKVStore

type CommitKVStore = weave.CommitKVStore

CommitKVStore is an alias to interface in root package

type EmptyKVStore

type EmptyKVStore struct{}

EmptyKVStore never holds any data, used as a base layer to test caching

func (EmptyKVStore) Delete

func (e EmptyKVStore) Delete(key []byte) error

Delete is a noop

func (EmptyKVStore) Get

func (e EmptyKVStore) Get(key []byte) ([]byte, error)

Get always returns nil

func (EmptyKVStore) Has

func (e EmptyKVStore) Has(key []byte) (bool, error)

Has always returns false

func (EmptyKVStore) Iterator

func (e EmptyKVStore) Iterator(start, end []byte) (Iterator, error)

Iterator is always empty

func (EmptyKVStore) NewBatch

func (e EmptyKVStore) NewBatch() Batch

NewBatch returns a batch that can write to this tree later

func (EmptyKVStore) ReverseIterator

func (e EmptyKVStore) ReverseIterator(start, end []byte) (Iterator, error)

ReverseIterator is always empty

func (EmptyKVStore) Set

func (e EmptyKVStore) Set(key, value []byte) error

Set is a noop

type Iterator

type Iterator = weave.Iterator

Iterator is an alias to interface in root package

type KVCacheWrap

type KVCacheWrap = weave.KVCacheWrap

KVCacheWrap is an alias to interface in root package

type KVStore

type KVStore = weave.KVStore

KVStore is an alias to interface in root package

func NewRecordingStore added in v0.2.1

func NewRecordingStore(db KVStore) KVStore

NewRecordingStore initializes a recording store wrapping this base store, using cached alternative if possible

We need to expose this optional functionality through the interface wrapper so downstream components (like Savepoint) can use reflection to CacheWrap.

type Model

type Model = weave.Model

Model is an alias to interface in root package

type NonAtomicBatch

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

NonAtomicBatch just piles up ops and executes them later on the underlying store. Can be used when there is no better option (for in-memory stores).

func NewNonAtomicBatch

func NewNonAtomicBatch(out SetDeleter) *NonAtomicBatch

NewNonAtomicBatch creates an empty batch to be later written to the KVStore

func (*NonAtomicBatch) Delete

func (b *NonAtomicBatch) Delete(key []byte) error

Delete adds a delete operation to the batch

func (*NonAtomicBatch) Set

func (b *NonAtomicBatch) Set(key, value []byte) error

Set adds a set operation to the batch

func (*NonAtomicBatch) ShowOps added in v0.11.2

func (b *NonAtomicBatch) ShowOps() []Op

ShowOps is instrumentation for testing, it returns a copy of the internal Ops list

func (*NonAtomicBatch) Write

func (b *NonAtomicBatch) Write() error

Write writes all the ops to the underlying store and resets

type Op

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

Op is either set or delete

func DelOp

func DelOp(key []byte) Op

DelOp is a helper to create a del operation

func SetOp

func SetOp(key, value []byte) Op

SetOp is a helper to create a set operation

func (Op) Apply

func (o Op) Apply(out SetDeleter) error

Apply performs the stored operation on a writable store

func (Op) IsSetOp added in v0.11.2

func (o Op) IsSetOp() bool

IsSetOp returns true if it is setting (false implies delete)

func (Op) Key added in v0.11.2

func (o Op) Key() []byte

Key returns a copy of the Key

type ReadOnlyKVStore

type ReadOnlyKVStore = weave.ReadOnlyKVStore

ReadOnlyKVStore is an alias to interface in root package

type Recorder added in v0.2.1

type Recorder interface {
	KVPairs() map[string][]byte
}

Recorder interface is implemented by anything returned from NewRecordingStore

type SetDeleter

type SetDeleter = weave.SetDeleter

SetDeleter is an alias to interface in root package

type ShowOpser added in v0.11.2

type ShowOpser interface {
	ShowOps() []Op
}

ShowOpser returns an ordered list of all operations performed

type SliceIterator

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

SliceIterator wraps an Iterator over a slice of models

TODO: make this private and only expose Iterator interface????

func NewSliceIterator

func NewSliceIterator(data []Model) *SliceIterator

NewSliceIterator creates a new Iterator over this slice

func (*SliceIterator) Next

func (s *SliceIterator) Next() (key, value []byte, err error)

func (*SliceIterator) Release added in v0.17.0

func (s *SliceIterator) Release()

Release releases the Iterator.

type TestStoreConstructor added in v0.17.0

type TestStoreConstructor func() (base CacheableKVStore, cleanup func())

type TestSuite added in v0.17.0

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

* TestSuite provides many methods that can be called in package-specific test code. We just customize the store being tested (pass in constructor), the rest of the logic is generic to the KVStore interface.

This is intended in particular to remove duplication between btree_test.go and iavl/adapter_test.go, but can be used for any implementation of KVStore.

func NewTestSuite added in v0.17.0

func NewTestSuite(constructor TestStoreConstructor) *TestSuite

func (*TestSuite) AssertGetHas added in v0.17.0

func (s *TestSuite) AssertGetHas(t testing.TB, kv ReadOnlyKVStore, key, val []byte, has bool)

func (*TestSuite) CacheConflicts added in v0.17.0

func (s *TestSuite) CacheConflicts(t *testing.T)

CacheConflicts checks that we can handle overwriting values and deleting underlying values

func (*TestSuite) FuzzIterator added in v0.17.0

func (s *TestSuite) FuzzIterator(t *testing.T)

FuzzIterator makes sure the basic iterator works. Includes random deletes, but not nested iterators.

func (*TestSuite) GetSet added in v0.17.0

func (s *TestSuite) GetSet(t *testing.T)

GetSet does basic sanity checks on our cache

Other tests should handle deletes, setting same value, iterating over ranges, and general fuzzing

func (*TestSuite) IteratorWithConflicts added in v0.17.0

func (s *TestSuite) IteratorWithConflicts(t *testing.T)

IteratorWithConflicts covers some specific test cases that arose during fuzzing the iterators.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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