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 ¶
Types ¶
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 ¶
EventKeyValue represents task event
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 ¶
Click to show internal directories.
Click to hide internal directories.