discovery

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrWatchFailed = fmt.Errorf("etcd watch returns a nil chan")
	ErrNoKey       = fmt.Errorf("etcd has no such key")
	ErrTxnFailed   = fmt.Errorf("role changed or target revision mismatch")
	ErrTxnConvert  = fmt.Errorf("cannot covert etcd transaction")
)
View Source
var ErrNotExist = fmt.Errorf("discovery is not exist")

Functions

func TxnErr

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

将txn响应和错误转化为一个错误

Types

type Batch

type Batch struct {
	KVs []KeyValue
}

批写入数据

type Closed

type Closed struct{}

type Discovery

type Discovery interface {
	// 从service center中获得数据
	Get(ctx context.Context, key string) ([]byte, error)                                         // 根据key获得value
	List(ctx context.Context, prefix string) ([]KeyValue, error)                                 // 根据前缀获得数据
	Put(ctx context.Context, key string, val []byte) error                                       // key-value写入, 为了控制面使用
	Delete(ctx context.Context, key string) error                                                // 删除key,为了控制面使用
	Heartbeat(ctx context.Context, key string, value []byte, ttl int64) (<-chan Closed, error)   // endponit 健康检查
	Elect(ctx context.Context, key string, value []byte, ttl int64) (bool, <-chan Closed, error) // 选举写入: key 不存在,写入成功,返回成功;key存在,写入失败,返回error
	Watch(ctx context.Context, key string, fetchVal bool) WatchEventChan                         // watch key
	WatchPrefix(ctx context.Context, prefixKey string, fetchVal bool) WatchEventChan             // watch 前缀key
	Batch(ctx context.Context, batch Batch) (bool, error)                                        // 批写入
	NewTransaction() Transaction                                                                 // 新transaction
	Commit(ctx context.Context, txn Transaction) error                                           // commit
	Close() error                                                                                // close discovery
}

type DiscoveryFactory

type DiscoveryFactory interface {
	CreateDiscovery(cfg config.Discovery) (Discovery, error)
}

func NewDiscoveryFactory

func NewDiscoveryFactory(owner string) DiscoveryFactory

type Event

type Event struct {
	Type      EventType
	KeyValues []EventKeyValue

	Err error
}

定义 discovery watch 健值或者前缀的event

type EventKeyValue

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

type EventType

type EventType int
const (
	EventTypeModify EventType = iota
	EventTypeDelete
	EventTypeAll
)

Event类型

func (EventType) String

func (e EventType) String() string

type KeyValue

type KeyValue struct {
	Key   string
	Value []byte
}

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

Watch Event Chan

Jump to

Keyboard shortcuts

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