Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrEntryTooLarge = errors.New("entry too large for the configured table size")
ErrEntryTooLarge returned if required space for an entry is bigger than table size.
var ErrKeyNotFound = errors.New("key not found")
ErrKeyNotFound is an error that indicates that the requested key could not be found in the DB.
var ErrKeyTooLarge = errors.New("key too large")
ErrKeyTooLarge is an error that indicates the given key is larger than the determined key size. The current maximum key length is 256.
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 ¶
Config defines a new storage engine configuration
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) // GetLastAccess extracts LastAccess of an entry. GetLastAccess(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 exist. UpdateTTL(uint64, Entry) error // TransferIterator returns a new TransferIterator instance to the caller. TransferIterator() TransferIterator // Import imports an encoded table of the storage engine implementation and // calls f for every Entry item in that table. Import(data []byte, f func(uint64, Entry) error) 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) // RangeHKey implements a loop for hashed keys(HKeys). RangeHKey(func(uint64) bool) // Scan implements an iterator. The caller starts iterating from the cursor. "count" is the number of entries // that will be returned during the iteration. Scan calls the function "f" on Entry items for every iteration. //It returns the next cursor if everything is okay. Otherwise, it returns an error. Scan(cursor uint64, count int, f func(Entry) bool) (uint64, error) // ScanRegexMatch is the same with the Scan method, but it supports regular expressions on keys. ScanRegexMatch(cursor uint64, match string, count int, f func(Entry) bool) (uint64, 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.
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 SetLastAccess(int64) LastAccess() 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.
type TransferIterator ¶ added in v0.5.0
type TransferIterator interface { // Next returns true if there are more tables to Export in the storage instance. // Otherwise, it returns false. Next() bool // Export encodes a table and returns result. This encoded table can be moved to another Olric node. Export() ([]byte, int, error) // Drop drops a table with its index from the storage engine instance and frees allocated resources. Drop(int) error }
TransferIterator is an interface to implement iterators to encode and transfer the underlying tables to another Olric member.