store

package
v0.0.0-...-ab75566 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2022 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotFound should be returned by storage during a read operation if no
	// item exists for the given key.
	ErrNotFound = errors.New("that key does not exist")

	// ErrDirtyItem should be returned by storage if the latest version for the
	// key has not been committed yet.
	ErrDirtyItem = errors.New("key has an uncommitted version")
)

Functions

func Encode

func Encode(i interface{}) ([]byte, error)

Encode returns the byte representation of the interface given, using gob.NewEncoder.

Types

type Item

type Item struct {
	Version   uint64
	Committed bool
	Value     []byte
	Key       string
}

Item is an object in the Store. A key inside the store might have multiple versions.

func DecodeMany

func DecodeMany(b []byte) ([]*Item, error)

DecodeMany decodes a byte slice into a slice of Items.

type Storer

type Storer interface {
	// Read an item from the store by key. If there is an uncommitted (dirty)
	// version of the item in the store, it returns a ErrDirtyItem error. If
	// no item exists for that key it returns a ErrNotFound error.
	Read(key string) (*Item, error)

	// Write a new item to the store.
	Write(key string, val []byte, version uint64) error

	// Commit a version for the given key. All items with matching key and older
	// than version are cleared.
	Commit(key string, version uint64) error

	// ReadVersion finds an item for the given key with the matching version. If
	// no item is found for that version of key, ErrNotFound is returned
	ReadVersion(key string, version uint64) (*Item, error)

	// AllNewerCommitted returns all committed items who's key is not in
	// versionsByKey or who's version is higher than the versions in
	// versionsByKey.
	AllNewerCommitted(versionsByKey map[string]uint64) ([]*Item, error)

	// AllNewerDirty returns all uncommitted items who's key is not in
	// versionsByKey or who's version is higher than the versions in
	// versionsByKey.
	AllNewerDirty(versionsByKey map[string]uint64) ([]*Item, error)

	// AllDirty returns all uncommitted items.
	AllDirty() ([]*Item, error)

	// AllCommitted returns all committed items.
	AllCommitted() ([]*Item, error)
}

Directories

Path Synopsis
mongodb package is for using MongoDB as the storage layer for a CRAQ node.
mongodb package is for using MongoDB as the storage layer for a CRAQ node.

Jump to

Keyboard shortcuts

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