storage

package
v0.0.0-...-b0c7fd6 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2023 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotFound is returned when a key is not found in the storage.
	ErrNotFound = errors.New("key not found")
	// ErrObsolete is returned when a write operation is performed on a key that
	// already has a newer version.
	ErrObsolete = errors.New("obsolete write")
	// ErrNoMoreItems is returned when there are no more items in the iterator.
	ErrNoMoreItems = errors.New("no more items in the iterator")
)

Functions

func ToProtoValues

func ToProtoValues(values []Value) []*proto.VersionedValue

Types

type Engine

type Engine interface {
	Get(key string) ([]Value, error)
	Put(key string, value Value) error
}

Engine is the interface that wraps the basic storage operations. It is implemented by different storage engines, such as LSM-tree or in-memory storage, and can be easily swapped out. Not all storage engines may support all operations, so the interface is intentionally small. Note that in case of concurrent versions, the storage engine will return all versions of the key, and it is up to the caller to decide which one to use.

type ScanIterator

type ScanIterator interface {
	Item() (string, []Value)
	Next() error
}

ScanIterator is the interface for iterating over the key-value pairs in the storage, in lexicographical order. It is not usually safe for concurrent use, so we must create a new iterator for each goroutine.

type Scannable

type Scannable interface {
	Scan(key string) ScanIterator
}

Scannable is a storage that supports range scans. It may be supported by some storage engines, but not all of them. In case of concurrent versions, the storage engine will return all versions of the key, and it is up to the caller to decide which one to use.

type Value

type Value struct {
	Version   vclock.Version
	Data      []byte
	Tombstone bool
}

Value represents a single value associated with a key.

func AppendVersion

func AppendVersion(values []Value, newValue Value) ([]Value, error)

AppendVersion appends a new version to the list of versions. In case the new version overtakes the existing ones, the older existing versions are discarded. If the new version is older than the existing ones, an ErrObsolete is returned. In case of concurrent versions, the new version is added to the list.

Directories

Path Synopsis
Package mock is a generated GoMock package.
Package mock is a generated GoMock package.

Jump to

Keyboard shortcuts

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