kv

package
v0.66.0 Latest Latest
Warning

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

Go to latest
Published: May 25, 2022 License: Apache-2.0 Imports: 13 Imported by: 2

Documentation

Index

Constants

View Source
const (
	InitialMigrateVersion = 1
	PathDelimiter         = "/"
	DBSchemaVersionKey    = "kv" + PathDelimiter + "schema" + PathDelimiter + "version"
)

Variables

View Source
var (
	ErrClosedEntries       = errors.New("closed entries")
	ErrConnectFailed       = errors.New("connect failed")
	ErrDriverConfiguration = errors.New("driver configuration")
	ErrMissingKey          = errors.New("missing key")
	ErrMissingValue        = errors.New("missing value")
	ErrNotFound            = errors.New("not found")
	ErrOperationFailed     = errors.New("operation failed")
	ErrPredicateFailed     = errors.New("predicate failed")
	ErrSetupFailed         = errors.New("setup failed")
	ErrUnknownDriver       = errors.New("unknown driver")
)
View Source
var ErrInvalidFormat = errors.New("invalid format")

Functions

func Drivers

func Drivers() []string

Drivers returns a list of registered drive names

func FormatPath added in v0.65.0

func FormatPath(p ...string) string

func GetDBSchemaVersion added in v0.66.0

func GetDBSchemaVersion(ctx context.Context, store Store) (int, error)

GetDBSchemaVersion returns the current KV DB schema version

func Import added in v0.66.0

func Import(ctx context.Context, reader io.Reader, store Store) error

func Register

func Register(name string, driver Driver)

Register 'driver' implementation under 'name'. Panic in case of empty name, nil driver or name already registered.

func UnregisterAllDrivers

func UnregisterAllDrivers()

UnregisterAllDrivers remove all loaded drivers, used for test code.

Types

type Driver

type Driver interface {
	// Open opens access to the database store. Implementations give access to the same storage based on the dsn.
	// Implementation can return the same Storage instance based on dsn or new one as long as it provides access to
	// the same storage.
	Open(ctx context.Context, dsn string) (Store, error)
}

Driver is the interface to access a kv database as a Store. Each kv provider implements a Driver.

type EntriesIterator

type EntriesIterator interface {
	// Next should be called first before access Entry.
	// it will process the next entry and return true if it was successful, and false when none or error.
	Next() bool

	// Entry current entry read after calling Next, set to nil in case of an error or no more entries.
	Entry() *Entry

	// Err set to last error by reading or parse the next entry.
	Err() error

	// Close should be called at the end of processing entries, required to release resources used to scan entries.
	// After calling 'Close' the instance should not be used as the behaviour will not be defined.
	Close()
}

EntriesIterator used to enumerate over Scan results

func ScanPrefix

func ScanPrefix(ctx context.Context, store Store, prefix []byte) (EntriesIterator, error)

ScanPrefix returns an iterator on store that scan the set of keys that start with prefix

type Entry

type Entry struct {
	Key   []byte
	Value []byte
}

Entry holds a pair of key/value

func (*Entry) String

func (e *Entry) String() string
type Header struct {
	LakeFSVersion   string
	PackageName     string
	DBSchemaVersion int
	CreatedAt       time.Time
}

Header contains metadata information for import / export file

type MessageEntry added in v0.66.0

type MessageEntry struct {
	Key   string
	Value protoreflect.ProtoMessage
}

type MessageIterator added in v0.66.0

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

func NewMessageIterator added in v0.66.0

func NewMessageIterator(ctx context.Context, store Store, msgType protoreflect.MessageType, prefix string) (*MessageIterator, error)

func (*MessageIterator) Close added in v0.66.0

func (m *MessageIterator) Close()

func (*MessageIterator) Entry added in v0.66.0

func (m *MessageIterator) Entry() *MessageEntry

func (*MessageIterator) Err added in v0.66.0

func (m *MessageIterator) Err() error

func (*MessageIterator) Next added in v0.66.0

func (m *MessageIterator) Next() bool

type Predicate added in v0.66.0

type Predicate interface{}

Predicate value used to update a key base on a previous fetched value.

Store's Get used to pull the key's value with the associated predicate.
Store's SetIf used to set the key's value based on the predicate.

type PrefixIterator

type PrefixIterator struct {
	Iterator EntriesIterator
	Prefix   []byte
	// contains filtered or unexported fields
}

func (*PrefixIterator) Close

func (b *PrefixIterator) Close()

func (*PrefixIterator) Entry

func (b *PrefixIterator) Entry() *Entry

func (*PrefixIterator) Err

func (b *PrefixIterator) Err() error

func (*PrefixIterator) Next

func (b *PrefixIterator) Next() bool

type Store

type Store interface {
	// Get returns a result containing the Value and Predicate for the given key, or ErrNotFound if key doesn't exist
	//   Predicate can be used for SetIf operation
	Get(ctx context.Context, key []byte) (*ValueWithPredicate, error)

	// Set stores the given value, overwriting an existing value if one exists
	Set(ctx context.Context, key, value []byte) error

	// SetIf returns an ErrPredicateFailed error if the key with valuePredicate passed
	//  doesn't match the currently stored value. SetIf is a simple compare-and-swap operator:
	//  valuePredicate is either the existing value, or nil for no previous key exists.
	//  this is intentionally simplistic: we can model a better abstraction on top, keeping this interface simple for implementors
	SetIf(ctx context.Context, key, value []byte, valuePredicate Predicate) error

	// Delete will delete the key, no error in if key doesn't exist
	Delete(ctx context.Context, key []byte) error

	// Scan returns entries that can be read by key order, starting at or after the `start` position
	Scan(ctx context.Context, start []byte) (EntriesIterator, error)

	// Close access to the database store. After calling Close the instance is unusable.
	Close()
}

func Open

func Open(ctx context.Context, name, dsn string) (Store, error)

Open lookup driver with 'name' and return Store based on 'dsn' (data source name). Failed with ErrUnknownDriver in case 'name' is not registered

type StoreMessage added in v0.65.0

type StoreMessage struct {
	Store
}

StoreMessage protobuf generic implementation for kv.Store interface applicable for all data models

func (*StoreMessage) DeleteMsg added in v0.66.0

func (s *StoreMessage) DeleteMsg(ctx context.Context, path string) error

func (*StoreMessage) GetMsg added in v0.65.0

GetMsg based on 'path' the value will be loaded into 'msg' and return a predicate.

In case 'msg' is nil, a predicate will be returned

func (*StoreMessage) Scan added in v0.66.0

func (s *StoreMessage) Scan(ctx context.Context, msgType protoreflect.MessageType, prefix string) (*MessageIterator, error)

Scan returns a prefix iterator which returns entries in deserialized format. Scan in store message implementation is msg specific.

Therefore, the prefix given should limit the range of the data to those that can be deserialized by the proto message type.

func (*StoreMessage) SetMsg added in v0.65.0

func (s *StoreMessage) SetMsg(ctx context.Context, path string, msg protoreflect.ProtoMessage) error

func (*StoreMessage) SetMsgIf added in v0.66.0

func (s *StoreMessage) SetMsgIf(ctx context.Context, path string, msg protoreflect.ProtoMessage, predicate Predicate) error

type ValueWithPredicate added in v0.66.0

type ValueWithPredicate struct {
	Value     []byte
	Predicate Predicate
}

ValueWithPredicate value with predicate - Value holds the data and Predicate a value used for conditional set.

Get operation will return this struct, holding the key's information
SetIf operation will use the Predicate for conditional set

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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