store

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2017 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotExist is the error returned when specified id does
	// not exist.
	ErrNotExist = errors.New("does not exist")
	// ErrAlreadyExist is the error returned when specified id already
	// exists.
	ErrAlreadyExist = errors.New("already exists")
)

Functions

This section is empty.

Types

type MetadataStore

type MetadataStore interface {
	// Create the metadata containing the passed in data with the
	// specified id.
	// Note:
	// * Create MUST return error if the id already exists.
	// * The id and data MUST be added in one transaction to the store.
	Create(string, []byte) error
	// Get the data by id.
	// Note that Get MUST return ErrNotExist if the id doesn't exist.
	Get(string) ([]byte, error)
	// Update the data by id.
	// Note:
	// * Update MUST return ErrNotExist is the id doesn't exist.
	// * The update MUST be applied in one transaction.
	Update(string, UpdateFunc) error
	// List returns entire array of data from the store.
	List() ([][]byte, error)
	// Delete the data by id.
	// Note:
	// * Delete should be idempotent, it MUST not return error if the id
	// doesn't exist or has been removed.
	// * The id and data MUST be deleted in one transaction.
	Delete(string) error
}

MetadataStore is the interface for storing metadata. All methods should be thread-safe. TODO(random-liu): Initialize the metadata store with a type, and replace []byte with interface{}, so as to avoid extra marshal/unmarshal on the user side.

func NewMetadataStore

func NewMetadataStore() MetadataStore

NewMetadataStore creates a MetadataStore.

type UpdateFunc

type UpdateFunc func([]byte) ([]byte, error)

UpdateFunc is function used to update a specific metadata. The value passed in is the old value, it MUST NOT be changed in the function. The function should make a copy of the old value and apply update on the copy. The updated value should be returned. If there is an error, the update will be rolled back.

Jump to

Keyboard shortcuts

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