state

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2024 License: Apache-2.0 Imports: 18 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")
	// ErrTxnConvert transaction covert failed.
	ErrTxnConvert = fmt.Errorf("cannot covert etcd transaction")
)
View Source
var (
	// ErrNotExist represents key not exist.
	ErrNotExist = errors.New("key 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.

func (EventType) String

func (e EventType) String() string

String returns event type string value

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) ([]KeyValue, error)
	// WalkEntry walks each kv entry via fn for given prefix from repository.
	WalkEntry(ctx context.Context, prefix string, fn func(key, value []byte)) error
	// Put puts a key-value pair into repository.
	Put(ctx context.Context, key string, val []byte) error
	PutWithTX(ctx context.Context, key string, val []byte, check func(oldVal []byte) error) (bool, 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)
	// Elect 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
	Elect(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.
	// fetchVal: if fetch prefix key's values for init.
	Watch(ctx context.Context, key string, fetchVal bool) WatchEventChan
	// WatchPrefix watches on a prefix. All the changes who have the prefix
	// will be notified through the WatchEventChan channel.
	// fetchVal: if fetch prefix key's values for init
	WatchPrefix(ctx context.Context, prefixKey string, fetchVal bool) WatchEventChan
	// Batch puts k/v list, this operation is atomic.
	Batch(ctx context.Context, batch Batch) (bool, error)
	// NextSequence returns next sequence number.
	NextSequence(ctx context.Context, key string) (int64, error)
	// NewTransaction creates a new transaction
	NewTransaction() Transaction
	// Commit commits the transaction, if fail return err
	Commit(ctx context.Context, txn Transaction) error
	// Close closes repository and release resources
	Close() error
}

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

type RepositoryFactory

type RepositoryFactory interface {
	// CreateRootRepo creates root state repository based on config.
	CreateRootRepo(repoState *config.RepoState) (Repository, error)
	// CreateBrokerRepo creates broker state repository based on config.
	CreateBrokerRepo(repoState *config.RepoState) (Repository, error)
	// CreateStorageRepo creates storage state repository based on config.
	CreateStorageRepo(repoState *config.RepoState) (Repository, error)
}

RepositoryFactory represents the repository create factory.

func NewRepositoryFactory

func NewRepositoryFactory(owner string) RepositoryFactory

NewRepositoryFactory creates a repository factory by owner

type Transaction

type Transaction interface {
	ModRevisionCmp(key, op string, v interface{})
	Put(key string, value []byte)
	Delete(key string)
}

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