etcdutil

package
v0.0.0-...-a6492d2 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2022 License: Apache-2.0 Imports: 14 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEtcdNodeExist     = errors.New("etcd: node exist")
	ErrEtcdValueExist    = errors.New("etcd: value exist")
	ErrEtcdValueNotMatch = errors.New("etcd: value not match")
	ErrUnexpected        = errors.New("etcd: unexpected")
)
View Source
var (
	DefaultRequestTimeout = 1 * time.Second
)

Functions

func ContainerPath

func ContainerPath(service, id string) string

func LeaseBridgePath

func LeaseBridgePath(service string) string

func LeaseGuardPath

func LeaseGuardPath(service string) string

func LeasePath

func LeasePath(service string) string

func LeaseSessionDir

func LeaseSessionDir(service string) string

func LeaseSessionPath

func LeaseSessionPath(service string, container string) string

LeaseSessionPath 作为guard lease过期的监控点,在得到新的lease的时候创建,server可以通过不续约让这个节点过期, 这样shardkeeper感知到guard lease被过期,发起shard drop动作,注意

func ServicePath

func ServicePath(service string) string

func SetPfx

func SetPfx(v string)

func ShardDir

func ShardDir(service, containerId string) string

func ShardPath

func ShardPath(service, containerId, shardId string) string

func WatchLoop

func WatchLoop(ctx context.Context, client EtcdWrapper, key string, rev int64, fn func(ctx context.Context, ev *clientv3.Event) error)

Types

type EtcdClient

type EtcdClient struct {
	*clientv3.Client
}

func NewEtcdClient

func NewEtcdClient(endpoints []string) (*EtcdClient, error)

func NewEtcdClientWithClient

func NewEtcdClientWithClient(client *clientv3.Client) *EtcdClient

func (*EtcdClient) CompareAndSwap

func (w *EtcdClient) CompareAndSwap(ctx context.Context, node string, curValue string, newValue string, leaseID clientv3.LeaseID) (string, error)

func (*EtcdClient) CreateAndGet

func (w *EtcdClient) CreateAndGet(ctx context.Context, nodes []string, values []string, leaseID clientv3.LeaseID) error

func (*EtcdClient) DelKV

func (w *EtcdClient) DelKV(ctx context.Context, prefix string) error

func (*EtcdClient) DelKVs

func (w *EtcdClient) DelKVs(ctx context.Context, prefixes []string) error

func (*EtcdClient) Delete

func (w *EtcdClient) Delete(ctx context.Context, key string, opts ...clientv3.OpOption) (*clientv3.DeleteResponse, error)

func (*EtcdClient) Get

func (w *EtcdClient) Get(ctx context.Context, key string, opts ...clientv3.OpOption) (*clientv3.GetResponse, error)

func (*EtcdClient) GetClient

func (w *EtcdClient) GetClient() *EtcdClient

func (*EtcdClient) GetKV

func (w *EtcdClient) GetKV(ctx context.Context, node string, opts []clientv3.OpOption) (*clientv3.GetResponse, error)

func (*EtcdClient) GetKVs

func (w *EtcdClient) GetKVs(ctx context.Context, prefix string) (map[string]string, error)

func (*EtcdClient) Inc

func (w *EtcdClient) Inc(ctx context.Context, pfx string) (string, error)

func (*EtcdClient) NewSession

func (w *EtcdClient) NewSession(_ context.Context, client *clientv3.Client, opts ...concurrency.SessionOption) (*concurrency.Session, error)

func (*EtcdClient) Put

func (w *EtcdClient) Put(ctx context.Context, key, val string, opts ...clientv3.OpOption) (*clientv3.PutResponse, error)

func (*EtcdClient) UpdateKV

func (w *EtcdClient) UpdateKV(ctx context.Context, key string, value string) error

func (*EtcdClient) Watch

func (w *EtcdClient) Watch(ctx context.Context, key string, opts ...clientv3.OpOption) clientv3.WatchChan

type EtcdWrapper

type EtcdWrapper interface {
	io.Closer

	GetClient() *EtcdClient
	GetKV(_ context.Context, node string, opts []clientv3.OpOption) (*clientv3.GetResponse, error)
	GetKVs(ctx context.Context, prefix string) (map[string]string, error)
	UpdateKV(ctx context.Context, key string, value string) error
	DelKV(ctx context.Context, prefix string) error
	DelKVs(ctx context.Context, prefixes []string) error

	CreateAndGet(ctx context.Context, nodes []string, values []string, leaseID clientv3.LeaseID) error
	CompareAndSwap(_ context.Context, node string, curValue string, newValue string, leaseID clientv3.LeaseID) (string, error)
	Inc(_ context.Context, pfx string) (string, error)
	NewSession(ctx context.Context, client *clientv3.Client, opts ...concurrency.SessionOption) (*concurrency.Session, error)

	Ctx() context.Context
	Get(ctx context.Context, key string, opts ...clientv3.OpOption) (*clientv3.GetResponse, error)
	Put(ctx context.Context, key, val string, opts ...clientv3.OpOption) (*clientv3.PutResponse, error)
	Delete(ctx context.Context, key string, opts ...clientv3.OpOption) (*clientv3.DeleteResponse, error)
	Watch(ctx context.Context, key string, opts ...clientv3.OpOption) clientv3.WatchChan
}

EtcdWrapper 4 unit test etcd的方法已经是通过interface开放出来,这里进行二次封装

type MockedEtcdWrapper

type MockedEtcdWrapper struct {
	mock.Mock
}

func (*MockedEtcdWrapper) Close

func (m *MockedEtcdWrapper) Close() error

func (*MockedEtcdWrapper) CompareAndSwap

func (m *MockedEtcdWrapper) CompareAndSwap(ctx context.Context, node string, curValue string, newValue string, leaseID clientv3.LeaseID) (string, error)

func (*MockedEtcdWrapper) CreateAndGet

func (m *MockedEtcdWrapper) CreateAndGet(ctx context.Context, nodes []string, values []string, leaseID clientv3.LeaseID) error

func (*MockedEtcdWrapper) Ctx

func (*MockedEtcdWrapper) DelKV

func (m *MockedEtcdWrapper) DelKV(ctx context.Context, prefix string) error

func (*MockedEtcdWrapper) DelKVs

func (m *MockedEtcdWrapper) DelKVs(ctx context.Context, prefixes []string) error

func (*MockedEtcdWrapper) Delete

func (*MockedEtcdWrapper) Get

func (*MockedEtcdWrapper) GetClient

func (m *MockedEtcdWrapper) GetClient() *EtcdClient

func (*MockedEtcdWrapper) GetKV

func (*MockedEtcdWrapper) GetKVs

func (m *MockedEtcdWrapper) GetKVs(ctx context.Context, prefix string) (map[string]string, error)

func (*MockedEtcdWrapper) Inc

func (m *MockedEtcdWrapper) Inc(ctx context.Context, pfx string) (string, error)

func (*MockedEtcdWrapper) NewSession

func (*MockedEtcdWrapper) Put

func (m *MockedEtcdWrapper) Put(ctx context.Context, key, val string, opts ...clientv3.OpOption) (*clientv3.PutResponse, error)

func (*MockedEtcdWrapper) UpdateKV

func (m *MockedEtcdWrapper) UpdateKV(ctx context.Context, key string, value string) error

func (*MockedEtcdWrapper) Watch

Jump to

Keyboard shortcuts

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