storage

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2021 License: BSD-3-Clause Imports: 20 Imported by: 25

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Builder

type Builder func(topic string, partition int32) (Storage, error)

Builder creates a local storage (a persistent cache) for a topic table. Builder creates one storage for each partition of the topic.

func BuilderWithOptions

func BuilderWithOptions(path string, opts *opt.Options) Builder

BuilderWithOptions builds LevelDB storage with the given options and in the given path.

func DefaultBuilder

func DefaultBuilder(path string) Builder

DefaultBuilder builds a LevelDB storage with default configuration. The database will be stored in the given path.

func MemoryBuilder

func MemoryBuilder() Builder

MemoryBuilder builds in-memory storage.

type Iterator

type Iterator interface {
	// Next moves the iterator to the next key-value pair and whether such a pair
	// exists. Caller should check for possible error by calling Error after Next
	// returns false.
	Next() bool
	// Err returns the error that stopped the iteration if any.
	Err() error
	// Key returns the current key. Caller should not keep references to the
	// buffer or modify its contents.
	Key() []byte
	// Value returns the current value. Caller should not keep references to the
	// buffer or modify its contents.
	Value() ([]byte, error)
	// Release releases the iterator. After release, the iterator is not usable
	// anymore.
	Release()
	// Seek moves the iterator to the begining of a key-value pair sequence that
	// is greater or equal to the given key. It returns whether at least one of
	// such key-value pairs exist. Next must be called after seeking to access
	// the first pair.
	Seek(key []byte) bool
}

Iterator provides iteration access to the stored values.

func NewMultiIterator

func NewMultiIterator(iters []Iterator) Iterator

NewMultiIterator returns an Iterator that iterates over the given subiterators. Iteration happens in lexicographical order given that the subiterators also return values in order.

type Null

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

Null storage discards everything that it is given. This can be useful for debugging.

func (*Null) Close

func (n *Null) Close() error

Close does nothing and doesn't error

func (*Null) Delete

func (n *Null) Delete(string) error

Delete does nothing and doesn't error.

func (*Null) Get

func (n *Null) Get(key string) ([]byte, error)

Get returns nil values.

func (*Null) GetOffset

func (n *Null) GetOffset(def int64) (int64, error)

GetOffset returns the default offset given to it.

func (*Null) Has

func (n *Null) Has(key string) (bool, error)

Has returns false as in key not found.

func (*Null) Iterator

func (n *Null) Iterator() (Iterator, error)

Iterator returns an Iterator that is immediately exhausted.

func (*Null) IteratorWithRange

func (n *Null) IteratorWithRange(start, limit []byte) (Iterator, error)

IteratorWithRange returns an Iterator that is immediately exhausted.

func (*Null) MarkRecovered

func (n *Null) MarkRecovered() error

MarkRecovered does nothing.

func (*Null) Open

func (n *Null) Open() error

Open does nothing and doesn't error.

func (*Null) Recovered

func (n *Null) Recovered() bool

Recovered returns whether the storage has recovered.

func (*Null) Set

func (n *Null) Set(key string, val []byte) error

Set will do nothing and doesn't error.

func (*Null) SetOffset

func (n *Null) SetOffset(val int64) error

SetOffset does nothing and doesn't error.

type NullIter

type NullIter struct{}

NullIter is an iterator which is immediately exhausted.

func (*NullIter) Err added in v0.1.2

func (*NullIter) Err() error

func (*NullIter) Key

func (ni *NullIter) Key() []byte

Key returns always nil.

func (*NullIter) Next

func (ni *NullIter) Next() bool

Next returns always false.

func (*NullIter) Release

func (ni *NullIter) Release()

Release does nothing.

func (*NullIter) Seek

func (ni *NullIter) Seek(key []byte) bool

Seek do nothing

func (*NullIter) Value

func (ni *NullIter) Value() ([]byte, error)

Value returns always a nil value and no errors.

type Storage

type Storage interface {

	// Opens/Initialize the storage
	Open() error

	// Close closes the storage.
	Close() error
	// Has returns whether the given key exists in the database.
	Has(key string) (bool, error)

	// Get returns the value associated with the given key. If the key does not
	// exist, a nil will be returned.
	Get(key string) ([]byte, error)

	// Set stores a key-value pair.
	Set(key string, value []byte) error

	// Delete deletes a key-value pair from the storage.
	Delete(key string) error

	// GetOffset gets the local offset of the storage.
	GetOffset(def int64) (int64, error)

	// SetOffset sets the local offset of the storage.
	SetOffset(offset int64) error

	// MarkRecovered marks the storage as recovered. Recovery message throughput
	// can be a lot higher than during normal operation. This can be used to switch
	// to a different configuration after the recovery is done.
	MarkRecovered() error

	// Iterator returns an iterator that traverses over a snapshot of the storage.
	Iterator() (Iterator, error)

	// Iterator returns a new iterator that iterates over the key-value
	// pairs. Start and limit define a half-open range [start, limit). If either
	// is nil, the range will be unbounded on the respective side.
	IteratorWithRange(start, limit []byte) (Iterator, error)
}

Storage is the interface Goka expects from a storage implementation. Implementations of this interface must be safe for any number of concurrent readers with one writer.

func New

func New(db *leveldb.DB) (Storage, error)

New creates a new Storage backed by LevelDB.

func NewFile

func NewFile(path string, part int32) (Storage, error)

NewFile retuns a new on-disk storage.

func NewMemory

func NewMemory() Storage

NewMemory returns a new in-memory storage.

func NewNull

func NewNull() Storage

NewNull returns a new Null storage.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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