fastfood

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2023 License: Apache-2.0 Imports: 9 Imported by: 5

README

fastfood interface

Transactional Data Store interface for several embedded fast key-value storage engines:

Supported back-ends:

  • badger (including encryption)
  • boltdb
  • bbolt
  • pebbledb (like rocksdb)

All back-ends represented in separate repositories to keep flexibility of dependencies in your application.

The goal of this repository is to have a single interface for known embedded fast storage engines supported in one place with minimal differences in APIs. This approach will simplify selection and migration between embedded fast storage engines for multi-purpose applications.

Documentation

Index

Constants

View Source
const NoTTL = 0

* Marker that TTL (time-to-live in seconds) is not defined, therefore not setup, meaning eternal record

Variables

View Source
var (
	ErrNotFound = os.ErrNotExist

	// ErrInvalidRequest is returned if the user request is invalid.
	ErrInvalidRequest = errors.New("invalid request")

	// ErrConcurrentTransaction is returned when a transaction conflicts with another transaction.
	ErrConcurrentTxn = errors.New("concurrent transaction, try again")

	// ErrReadOnlyTxn is returned if an update function is called on a read-only transaction.
	ErrReadOnlyTxn = errors.New("read-only transaction has update operation")

	// ErrDiscardedTxn is returned if a previously discarded transaction is re-used.
	ErrDiscardedTxn = errors.New("transaction has been discarded")

	// ErrCanceledTxn is returned if user canceled transaction.
	ErrCanceledTxn = errors.New("transaction has been canceled")

	// ErrTooBigTxn is returned if too many writes are fit into a single transaction.
	ErrTooBigTxn = errors.New("transaction is too big")

	// ErrEmptyKey is returned if an empty key is passed on an update function.
	ErrEmptyKey = errors.New("empty key")

	// ErrInvalidKey is returned if the key has wrong character(s)
	ErrInvalidKey = errors.New("key is invalid")

	// ErrAlreadyClosed is returned when fastfood is already closed
	ErrAlreadyClosed = errors.New("already closed")

	// ErrInternal
	ErrInternal = errors.New("internal error")
)
View Source
var DataStoreClass = reflect.TypeOf((*DataStore)(nil)).Elem()
View Source
var DataStoreManagerClass = reflect.TypeOf((*DataStoreManager)(nil)).Elem()
View Source
var DefaultBatchSize = 256

* Default batch size, could be overwritten

View Source
var ManagedDataStoreClass = reflect.TypeOf((*ManagedDataStore)(nil)).Elem()
View Source
var ManagedTransactionalDataStoreClass = reflect.TypeOf((*ManagedTransactionalDataStore)(nil)).Elem()
View Source
var TransactionClass = reflect.TypeOf((*Transaction)(nil)).Elem()
View Source
var TransactionalDataStoreClass = reflect.TypeOf((*TransactionalDataStore)(nil)).Elem()
View Source
var TransactionalManagerClass = reflect.TypeOf((*TransactionalManager)(nil)).Elem()

Functions

func WithTransaction

func WithTransaction(ctx context.Context, beanName string, tx Transaction) context.Context

Types

type CompareAndSetOperation

type CompareAndSetOperation struct {
	DataStore                 // should be initialized
	Context   context.Context // should be initialized
	// contains filtered or unexported fields
}

func (*CompareAndSetOperation) Binary

func (t *CompareAndSetOperation) Binary(value []byte) (bool, error)

func (*CompareAndSetOperation) ByKey

func (t *CompareAndSetOperation) ByKey(formatKey string, args ...interface{}) *CompareAndSetOperation

func (*CompareAndSetOperation) ByRawKey

func (*CompareAndSetOperation) Counter

func (t *CompareAndSetOperation) Counter(value uint64) (bool, error)

func (*CompareAndSetOperation) Proto

func (t *CompareAndSetOperation) Proto(msg proto.Message) (bool, error)

func (*CompareAndSetOperation) String

func (t *CompareAndSetOperation) String(value string) (bool, error)

func (*CompareAndSetOperation) WithTtl

func (t *CompareAndSetOperation) WithTtl(ttlSeconds int) *CompareAndSetOperation

func (*CompareAndSetOperation) WithVersion

func (t *CompareAndSetOperation) WithVersion(version int64) *CompareAndSetOperation

type DataStore

type DataStore interface {
	gluten.DisposableBean
	gluten.NamedBean

	Get(ctx context.Context) *GetOperation

	Set(ctx context.Context) *SetOperation

	// equivalent of i++ operation, always returns previous value
	Increment(ctx context.Context) *IncrementOperation

	CompareAndSet(ctx context.Context) *CompareAndSetOperation

	Remove(ctx context.Context) *RemoveOperation

	Enumerate(ctx context.Context) *EnumerateOperation

	GetRaw(ctx context.Context, key []byte, ttlPtr *int, versionPtr *int64, required bool) ([]byte, error)

	SetRaw(ctx context.Context, key, value []byte, ttlSeconds int) error

	CompareAndSetRaw(ctx context.Context, key, value []byte, ttlSeconds int, version int64) (bool, error)

	IncrementRaw(ctx context.Context, key []byte, initial, delta int64, ttlSeconds int) (int64, error)

	RemoveRaw(ctx context.Context, key []byte) error

	EnumerateRaw(ctx context.Context, prefix, seek []byte, batchSize int, onlyKeys bool, reverse bool, cb func(*RawEntry) bool) error
}

type DataStoreManager

type DataStoreManager interface {
	Compact(discardRatio float64) error

	Backup(w io.Writer, since uint64) (uint64, error)

	Restore(r io.Reader) error

	DropAll() error

	DropWithPrefix(prefix []byte) error
}

type EnumerateOperation

type EnumerateOperation struct {
	DataStore                 // should be initialized
	Context   context.Context // should be initialized
	// contains filtered or unexported fields
}

func (*EnumerateOperation) ByPrefix

func (t *EnumerateOperation) ByPrefix(formatPrefix string, args ...interface{}) *EnumerateOperation

func (*EnumerateOperation) ByRawPrefix

func (t *EnumerateOperation) ByRawPrefix(prefix []byte) *EnumerateOperation

func (*EnumerateOperation) Do

func (t *EnumerateOperation) Do(cb func(*RawEntry) bool) error

func (*EnumerateOperation) DoProto

func (t *EnumerateOperation) DoProto(factory func() proto.Message, cb func(*ProtoEntry) bool) error

func (*EnumerateOperation) OnlyKeys

func (t *EnumerateOperation) OnlyKeys() *EnumerateOperation

func (*EnumerateOperation) Reverse

func (t *EnumerateOperation) Reverse() *EnumerateOperation

func (*EnumerateOperation) Seek

func (t *EnumerateOperation) Seek(formatSeek string, args ...interface{}) *EnumerateOperation

func (*EnumerateOperation) WithBatchSize

func (t *EnumerateOperation) WithBatchSize(batchSize int) *EnumerateOperation

type GetOperation

type GetOperation struct {
	DataStore                 // should be initialized
	Context   context.Context // should be initialized
	// contains filtered or unexported fields
}

func (*GetOperation) ByKey

func (t *GetOperation) ByKey(formatKey string, args ...interface{}) *GetOperation

func (*GetOperation) ByRawKey

func (t *GetOperation) ByRawKey(key []byte) *GetOperation

func (*GetOperation) Required

func (t *GetOperation) Required() *GetOperation

func (*GetOperation) ToBinary

func (t *GetOperation) ToBinary() ([]byte, error)

func (*GetOperation) ToCounter

func (t *GetOperation) ToCounter() (uint64, error)

func (*GetOperation) ToEntry

func (t *GetOperation) ToEntry() (entry RawEntry, err error)

func (*GetOperation) ToProto

func (t *GetOperation) ToProto(container proto.Message) error

func (*GetOperation) ToProtoEntry

func (t *GetOperation) ToProtoEntry(factory func() proto.Message) (entry ProtoEntry, err error)

func (*GetOperation) ToString

func (t *GetOperation) ToString() (string, error)

type IncrementOperation

type IncrementOperation struct {
	DataStore                 // should be initialized
	Context   context.Context // should be initialized

	Initial int64
	Delta   int64 // should be initialized by 1
	// contains filtered or unexported fields
}

func (*IncrementOperation) ByKey

func (t *IncrementOperation) ByKey(formatKey string, args ...interface{}) *IncrementOperation

func (*IncrementOperation) ByRawKey

func (t *IncrementOperation) ByRawKey(key []byte) *IncrementOperation

func (*IncrementOperation) Do

func (t *IncrementOperation) Do() (prev int64, err error)

func (*IncrementOperation) WithDelta

func (t *IncrementOperation) WithDelta(delta int64) *IncrementOperation

func (*IncrementOperation) WithInitialValue

func (t *IncrementOperation) WithInitialValue(initial int64) *IncrementOperation

func (*IncrementOperation) WithTtl

func (t *IncrementOperation) WithTtl(ttlSeconds int) *IncrementOperation

type ManagedDataStore

type ManagedDataStore interface {
	DataStore
	DataStoreManager

	Instance() interface{}
}

type ManagedTransactionalDataStore

type ManagedTransactionalDataStore interface {
	DataStore
	DataStoreManager
	TransactionalManager
}

type ProtoEntry

type ProtoEntry struct {
	Key     []byte
	Value   proto.Message
	Ttl     int
	Version int64
}

type RawEntry

type RawEntry struct {
	Key     []byte
	Value   []byte
	Ttl     int
	Version int64
}

type RemoveOperation

type RemoveOperation struct {
	DataStore                 // should be initialized
	Context   context.Context // should be initialized
	// contains filtered or unexported fields
}

func (*RemoveOperation) ByKey

func (t *RemoveOperation) ByKey(formatKey string, args ...interface{}) *RemoveOperation

func (*RemoveOperation) ByRawKey

func (t *RemoveOperation) ByRawKey(key []byte) *RemoveOperation

func (*RemoveOperation) Do

func (t *RemoveOperation) Do() error

type SetOperation

type SetOperation struct {
	DataStore                 // should be initialized
	Context   context.Context // should be initialized
	// contains filtered or unexported fields
}

func (*SetOperation) Binary

func (t *SetOperation) Binary(value []byte) error

func (*SetOperation) ByKey

func (t *SetOperation) ByKey(formatKey string, args ...interface{}) *SetOperation

func (*SetOperation) ByRawKey

func (t *SetOperation) ByRawKey(key []byte) *SetOperation

func (*SetOperation) Counter

func (t *SetOperation) Counter(value uint64) error

func (*SetOperation) Proto

func (t *SetOperation) Proto(msg proto.Message) error

func (*SetOperation) String

func (t *SetOperation) String(value string) error

func (*SetOperation) WithTtl

func (t *SetOperation) WithTtl(ttlSeconds int) *SetOperation

type Transaction

type Transaction interface {
	ReadOnly() bool

	Commit() error

	Rollback()

	Instance() interface{}
}

func GetTransaction

func GetTransaction(ctx context.Context, beanName string) (Transaction, bool)

func NewInnerTransaction

func NewInnerTransaction(parent Transaction) Transaction

type TransactionalDataStore

type TransactionalDataStore interface {
	DataStore
	TransactionalManager
}

type TransactionalManager

type TransactionalManager interface {
	BeginTransaction(ctx context.Context, readOnly bool) context.Context

	// commit if errOps is nil or rollback otherwise
	EndTransaction(ctx context.Context, errOps error) error
}

Jump to

Keyboard shortcuts

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