state

package
v0.0.0-...-034a78d Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2019 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrWatchFailed indicates the watch failed.
	ErrWatchFailed = fmt.Errorf("etcd watch returns a nil chan")
	// ErrNoKey indicates the key does not exist.
	ErrNoKey = fmt.Errorf("etcd has no such key")
	// ErrTxnFailed indicates the txn failed.
	ErrTxnFailed = fmt.Errorf("role changed or target revision mismatch")
)
View Source
var (
	// ErrNotExist represents key not exist
	ErrNotExist = errors.New("not exist")
)

Functions

func TxnErr

func TxnErr(resp *etcdcliv3.TxnResponse, err error) error

TxnErr converts txn response and error into one error.

Types

type Batch

type Batch struct {
	KVs []KeyValue
}

Batch represents put list for batch operation

type Closed

type Closed struct{}

Closed represents close status

type Config

type Config struct {
	Namespace   string   `toml:"namespace" json:"namespace"`
	Endpoints   []string `toml:"endpoints" json:"endpoints"`
	DialTimeout int64    `toml:"dialTimeout" json:"dialTimeout"`
}

Config represents state repository config

type Event

type Event struct {
	Type      EventType
	KeyValues []EventKeyValue

	Err error
}

Event defines repository watch event on key or perfix

type EventKeyValue

type EventKeyValue struct {
	Key   string
	Value []byte
	Rev   int64
}

EventKeyValue represents task event

type EventType

type EventType int

EventType represents a watch event type.

const (
	EventTypeModify EventType = iota
	EventTypeDelete
	EventTypeAll
)

Event types.

type KeyValue

type KeyValue struct {
	Key   string
	Value []byte
}

KeyValue represents key/value pair

type Repository

type Repository interface {
	// Get retrieves value for given key from repository
	Get(ctx context.Context, key string) ([]byte, error)
	// List retrieves list for given prefix from repository
	List(ctx context.Context, prefix string) ([][]byte, error)
	// Put puts a key-value pair into repository
	Put(ctx context.Context, key string, val []byte) error
	// Delete deletes value for given key from repository
	Delete(ctx context.Context, key string) error
	// Heartbeat does heartbeat on the key with a value and ttl
	Heartbeat(ctx context.Context, key string, value []byte, ttl int64) (<-chan Closed, error)
	// PutIfNotExist puts a key with a value,
	// 1) returns success if the key does not exist and puts success
	// 2) returns failure if key exist
	// When this operation success, it will do keepalive background for keep session
	PutIfNotExist(ctx context.Context, key string, value []byte, ttl int64) (bool, <-chan Closed, error)
	// Watch watches on a key. The watched events will be returned through the returned channel.
	Watch(ctx context.Context, key string) WatchEventChan
	// WatchPrefix watches on a prefix.All of the changes who has the prefix
	// will be notified through the WatchEventChan channel.
	WatchPrefix(ctx context.Context, prefixKey string) WatchEventChan
	// Batch puts k/v list, this operation is atomic
	Batch(ctx context.Context, batch Batch) (bool, error)
	// Close closes repository and release resources
	Close() error
}

Repository stores state data, such as metadata/config/status/task etc.

func NewRepo

func NewRepo(config Config) (Repository, error)

NewRepo create state repository based on config

type WatchEventChan

type WatchEventChan <-chan *Event

WatchEventChan notify event channel

Jump to

Keyboard shortcuts

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