storage

package
Version: v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2021 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrFragmented = errors.New("storage fragmented")

ErrFragmented is an error that indicates this storage instance is currently fragmented and it cannot be serialized.

View Source
var ErrKeyNotFound = errors.New("key not found")

ErrKeyNotFound is an error that indicates that the requested key could not be found in the DB.

View Source
var ErrKeyTooLarge = errors.New("key too large")

ErrKeyTooLarge is an error that indicates the given key is large than the determined key size. The current maximum key length is 256.

View Source
var ErrNotImplemented = errors.New("not implemented yet")

ErrNotImplemented means that the interface implementation does not support the functionality required to fulfill the request.

Functions

This section is empty.

Types

type Config

type Config struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Config defines a new storage engine configuration

func NewConfig

func NewConfig(cfg map[string]interface{}) *Config

NewConfig returns a new Config

func (*Config) Add

func (c *Config) Add(key string, value interface{})

Add adds a new key/value pair to Config

func (*Config) Copy

func (c *Config) Copy() *Config

Copy creates a thread-safe copy of the existing Config struct.

func (*Config) Delete

func (c *Config) Delete(key string)

Delete deletes a configuration variable with its key.

func (*Config) Get

func (c *Config) Get(key string) (interface{}, error)

Get loads a configuration variable with its key, otherwise it returns an error.

func (*Config) ToMap

func (c *Config) ToMap() map[string]interface{}

ToMap casts Config to map[string]interface{} type.

type Engine

type Engine interface {
	// SetConfig sets a storage engine configuration. nil can be accepted, but
	// it depends on the implementation.
	SetConfig(*Config)

	// SetLogger sets a logger. nil can be accepted, but it depends on the implementation.
	SetLogger(*log.Logger)

	// Start can be used to run background services before starting operation.
	Start() error

	// NewEntry returns a new Entry interface implemented by the current storage
	// engine implementation.
	NewEntry() Entry

	// Name returns name of the current storage engine implementation.
	Name() string

	// Fork creates an empty instance of an online engine by using the current
	// configuration.
	Fork(*Config) (Engine, error)

	// PutRaw inserts an encoded entry into the storage engine.
	PutRaw(uint64, []byte) error

	// Put inserts a new Entry into the storage engine.
	Put(uint64, Entry) error

	// GetRaw reads an encoded entry from the storage engine.
	GetRaw(uint64) ([]byte, error)

	// Get reads an entry from the storage engine.
	Get(uint64) (Entry, error)

	// GetTTL extracts TTL of an entry.
	GetTTL(uint64) (int64, error)

	// GetKey extracts key of an entry.
	GetKey(uint64) (string, error)

	// Delete deletes an entry from the storage engine.
	Delete(uint64) error

	// UpdateTTL updates TTL of an entry. It returns ErrKeyNotFound,
	// if the key doesn't exists.
	UpdateTTL(uint64, Entry) error

	// Import creates a new storage engine instance from its encoded form.
	Import([]byte) (Engine, error)

	// Exports encodes a storage engine into its binary form.
	Export() ([]byte, error)

	// Stats returns metrics for an online storage engine.
	Stats() Stats

	// Check returns true, if the key exists.
	Check(uint64) bool

	// Range implements a loop over the storage engine
	Range(func(uint64, Entry) bool)

	// RegexMatchOnKeys runs a regular expression over keys and loops over the result.
	RegexMatchOnKeys(string, func(uint64, Entry) bool) error

	// Compaction reorganizes storage tables and reclaims wasted resources.
	Compaction() (bool, error)

	// Close stops an online storage engine instance. It may free some of allocated
	// resources. A storage engine implementation should be started again, but it
	// depends on the implementation.
	Close() error

	// Destroy stops an online storage engine instance and frees allocated resources.
	// It should not be possible to reuse a destroyed storage engine.
	Destroy() error
}

Engine defines methods for a storage engine implementation.

func LoadAsPlugin

func LoadAsPlugin(pluginPath string) (Engine, error)

type Entry

type Entry interface {
	// SetKey accepts strings as a key and inserts the key into the underlying
	// data structure.
	SetKey(string)

	// Key returns the key as string
	Key() string

	// SetValue accepts a byte slice as a value and inserts the value into the
	// underlying data structure.
	SetValue([]byte)

	// Value returns the value as a byte slice.
	Value() []byte

	// SetTTL sets TTL to an entry.
	SetTTL(int64)

	// TTL returns the current TTL for an entry.
	TTL() int64

	// SetTimestamp sets the current timestamp to an entry.
	SetTimestamp(int64)

	// Timestamp returns the current timestamp for an entry.
	Timestamp() int64

	// Encode encodes an entry into a binary form and returns the result.
	Encode() []byte

	// Decode decodes a byte slice into an Entry.
	Decode([]byte)
}

Entry interface defines methods for a storage entry.

type Stats

type Stats struct {
	// Currently allocated memory by the engine.
	Allocated int

	// Used portion of allocated memory
	Inuse int

	// Deleted portions of allocated memory.
	Garbage int

	// Total number of keys hosted by the engine instance.
	Length int

	// Number of tables hosted by the engine instance.
	NumTables int

	// Any other metrics that's specific to an engine implementation.
	Extras map[string]interface{}
}

Stats defines metrics exposed by a storage engine implementation.

Jump to

Keyboard shortcuts

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