etcd

package
v0.0.0-...-9649b88 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2020 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MAXTIME               = 5
	DefaultEtcdAPIVersion = 2

	EtcdInitRetryIntervalInSec = 10
)
View Source
const (
	DefaultDialTimeout    = 5 * time.Second
	DefaultRetryTimeout   = 3 * time.Second
	DefaultRequestTimeout = 10 * time.Second
)

Variables

View Source
var (
	ErrKeyNotFound         = errors.New("100: Key not found")
	ErrTooManyRecordsFound = errors.New("too many records found")
)

Functions

func IsNotFindError

func IsNotFindError(err error) bool

func NewEtcd

func NewEtcd(ver int, urls string) dbaccessor.DbAccessor

func NewEtcdWithRetry

func NewEtcdWithRetry(ver int, urls string) dbaccessor.DbAccessor

Types

type DbRecords

type DbRecords struct {
	Records []KvPair
}

type Etcd

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

func NewEtcdV2

func NewEtcdV2(urls []string) *Etcd

func (*Etcd) DeleteDir

func (self *Etcd) DeleteDir(url string) error
func (self *Etcd) DeleteDir(url string) error {
	opt := client.DeleteOptions{}
	opt.Dir = true
	opt.Recursive = true
	klog.Info("del ETCD: key[", url, "]")
	_, err := self.client.Delete(context.Background(), url, &opt)
	if err != nil {
		klog.Error("deleteDir:Delete error!", err)
		return err
	}
	return nil
}

func (*Etcd) DeleteLeaf

func (self *Etcd) DeleteLeaf(k string) error
func (self *Etcd) DeleteLeaf(k string) error {
	klog.Info("del ETCD: key[", k, "]")
	_, err := self.client.Delete(context.Background(), k, nil)
	if err != nil {
		klog.Error("deleteLeaf: Delete error!", err)
		return err
	}
	return nil
}

func (*Etcd) Lock

func (self *Etcd) Lock(k string) bool

func (*Etcd) ReadDir

func (self *Etcd) ReadDir(k string) ([]*client.Node, error)

func (*Etcd) ReadLeaf

func (self *Etcd) ReadLeaf(k string) (string, error)
func (self *Etcd) ReadLeaf(k string) (string, error) {
	klog.Info("get ETCD: key[", k, "]")
	rsp, err := self.client.Get(context.Background(), k, nil)
	if err != nil {
		klog.Error(err)
		return "", err
	}
	return rsp.Node.Value, nil
}

func (*Etcd) SaveLeaf

func (self *Etcd) SaveLeaf(k, v string) error
func (self *Etcd) SaveLeaf(k, v string) error {
	klog.Info("add ETCD: key[", k, "]value[", v, "]")
	_, err := self.client.Set(context.Background(), k, v, nil)
	if err != nil {
		klog.Error("SaveLeaf",err)
		return err
	}
	return nil
}

func (*Etcd) Unlock

func (self *Etcd) Unlock(k string) bool

func (*Etcd) WatcherDir

func (self *Etcd) WatcherDir(url string) (*client.Response, error)
func (self *Etcd) WatcherDir(url string) (*client.Response, error) {
	opts := client.WatcherOptions{
		Recursive:  true,
		AfterIndex: 0,
	}

	//klog.Info("watch ETCD dir [", url, "]")
	got := self.client.Watcher(url, &opts)
	resp, err := got.Next(context.Background())
	if err != nil {
		klog.Error(err)
		return nil,err
	}

	return resp,nil
}

type EtcdV3

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

func NewEtcdV3

func NewEtcdV3(urls []string) *EtcdV3

func (*EtcdV3) DeleteDir

func (self *EtcdV3) DeleteDir(k string) error

func (*EtcdV3) DeleteLeaf

func (self *EtcdV3) DeleteLeaf(k string) error

func (*EtcdV3) Lock

func (self *EtcdV3) Lock(k string) bool

func (*EtcdV3) ReadDir

func (self *EtcdV3) ReadDir(dir string) ([]*client.Node, error)

func (*EtcdV3) ReadDirV3

func (self *EtcdV3) ReadDirV3(k string) (*DbRecords, error)

func (*EtcdV3) ReadLeaf

func (self *EtcdV3) ReadLeaf(k string) (string, error)

func (*EtcdV3) SaveLeaf

func (self *EtcdV3) SaveLeaf(k, v string) error

func (*EtcdV3) Unlock

func (self *EtcdV3) Unlock(k string) bool

func (*EtcdV3) WatcherDir

func (self *EtcdV3) WatcherDir(k string) (*client.Response, error)

type KvPair

type KvPair struct {
	Key   string
	Value string
}

Jump to

Keyboard shortcuts

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