metastor

package
v0.0.0-...-3e87057 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2018 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotFound is the error returned by a metastor client,
	// in case metadata requested couldn't be found.
	ErrNotFound = dbp.ErrNotFound

	// ErrNilKey is the error returned by a metastor client,
	// in case a nil key is given as part of a request.
	ErrNilKey = errors.New("nil key given")
)

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client defines the client API of a metadata server. It is used to set, get and delete metadata. It is also used as an optional part of the the main 0-stor client, in order to fetch the metadata automatically for a given key.

A Client is thread-safe.

func NewClient

func NewClient(namespace string, db dbp.DB, privKey string) (*Client, error)

NewClient creates new client from the given DB. If privKey is not empty, it uses default encryption with the given encryptKey as private key

func NewClientFromConfig

func NewClientFromConfig(namespace []byte, cfg Config) (*Client, error)

NewClientFromConfig creates a new metastor client from the given config

func (*Client) Close

func (c *Client) Close() error

Close any open resources of this metadata client.

func (*Client) DeleteMetadata

func (c *Client) DeleteMetadata(key []byte) error

DeleteMetadata deletes the metadata linked to the given key. It is not considered an error if the metadata was already deleted.

If an error is returned it should be assumed that the data couldn't be deleted and might still exist.

func (*Client) GetMetadata

func (c *Client) GetMetadata(key []byte) (*metatypes.Metadata, error)

GetMetadata returns the metadata linked to the given key.

An error is returned in case the linked data couldn't be found. ErrNotFound is returned in case the key couldn't be found. The returned data will always be non-nil in case no error was returned.

func (*Client) ListKeys

func (c *Client) ListKeys(cb dbp.ListCallback) error

ListKeys list all keys in the namespace, and exectute the given callback against each keys. Keys are sorted in lexicographically order

func (*Client) SetMetadata

func (c *Client) SetMetadata(md metatypes.Metadata) error

SetMetadata sets the metadata, using the key defined as part of the given metadata.

An error is returned in case the metadata couldn't be set.

func (*Client) UpdateMetadata

func (c *Client) UpdateMetadata(key []byte, cb UpdateMetadataFunc) (*metatypes.Metadata, error)

UpdateMetadata updates already existing metadata, returning an error in case there is no metadata to be found for the given key. See `UpdateMetadataFunc` for more information about the required callback.

UpdateMetadata panics when no callback is given.

type Config

type Config struct {
	// Database is required,
	// and is used to define te actual KV storage logic,
	// of the metadata in binary form.
	//
	// A client cannot be constructed if no database is given.
	Database dbp.DB

	// MarshalFuncPair is optional,
	// and is used to define custom marshal/unmarshal logic,
	// which transforms a Metadata struct to binary form and visa versa.
	// The (gogo) Proto(buf) marshal/unmarshal logic is used if no pair is given.
	//
	// A pair always have to given complete,
	// and a panic will be triggered if a partial one is given.
	MarshalFuncPair *encoding.MarshalFuncPair

	// ProcessorConstructor is optional,
	// and is used to pre- and postprocess the binary data,
	// prior to storage and just after fetching it.
	//
	// No pre- and postprocessing is applied,
	// in case no constructor is given.
	ProcessorConstructor ProcessorConstructor
}

Config is used to create a (metastor) Client.

type ProcessorConstructor

type ProcessorConstructor func() (processing.Processor, error)

ProcessorConstructor is a constructor type which is used to create a unique Processor for each goroutine where the Processor is needed within a pipeline. This is required as a Processor is not thread-safe.

type UpdateMetadataFunc

type UpdateMetadataFunc func(md metatypes.Metadata) (*metatypes.Metadata, error)

UpdateMetadataFunc defines a function which receives an already stored metadata, and which can modify the metadate, safely, prior to returning it. In worst case it can return an error, and that error will be propagated back to the user.

Directories

Path Synopsis
db
proto
Package proto is a generated protocol buffer package.
Package proto is a generated protocol buffer package.

Jump to

Keyboard shortcuts

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