etcdutil

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2025 License: Apache-2.0 Imports: 32 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// DefaultDialTimeout is the maximum amount of time a dial will wait for a
	// connection to setup. 30s is long enough for most of the network conditions.
	DefaultDialTimeout = 30 * time.Second

	// DefaultRequestTimeout 10s is long enough for most of etcd clusters.
	DefaultRequestTimeout = 10 * time.Second

	// DefaultSlowRequestTime 1s for the threshold for normal request, for those
	// longer then 1s, they are considered as slow requests.
	DefaultSlowRequestTime = time.Second

	// MaxEtcdTxnOps is the max value of operations in an etcd txn. The default limit of etcd txn op is 128.
	// We use 120 here to leave some space for other operations.
	// See: https://github.com/etcd-io/etcd/blob/d3e43d4de6f6d9575b489dd7850a85e37e0f6b6c/server/embed/config.go#L61
	MaxEtcdTxnOps = 120
)
View Source
const (

	// RequestProgressInterval is the interval to call RequestProgress for watcher.
	RequestProgressInterval = 1 * time.Second
	// WatchChTimeoutDuration is the timeout duration for a watchChan.
	WatchChTimeoutDuration = DefaultRequestTimeout
)

Variables

This section is empty.

Functions

func AddEtcdMember

func AddEtcdMember(client *clientv3.Client, urls []string) (*clientv3.MemberAddResponse, error)

AddEtcdMember adds an etcd member.

func CheckClusterID

func CheckClusterID(localClusterID etcdtypes.ID, um etcdtypes.URLsMap, tlsConfig *tls.Config) error

CheckClusterID checks etcd cluster ID, returns an error if mismatch. This function will never block even quorum is not satisfied.

func CreateEtcdClient

func CreateEtcdClient(tlsConfig *tls.Config, acURLs []url.URL, sourceOpt ...string) (*clientv3.Client, error)

CreateEtcdClient creates etcd v3 client with detecting endpoints.

func CreateHTTPClient

func CreateHTTPClient(tlsConfig *tls.Config) *http.Client

CreateHTTPClient creates a http client with the given tls config.

func EtcdKVGet

func EtcdKVGet(c *clientv3.Client, key string, opts ...clientv3.OpOption) (*clientv3.GetResponse, error)

EtcdKVGet returns the etcd GetResponse by given key or key prefix

func EtcdKVPutWithTTL

func EtcdKVPutWithTTL(ctx context.Context, c *clientv3.Client, key string, value string, ttlSeconds int64) (clientv3.LeaseID, error)

EtcdKVPutWithTTL put (key, value) into etcd with a ttl of ttlSeconds

func GetProtoMsgWithModRev

func GetProtoMsgWithModRev(c *clientv3.Client, key string, msg proto.Message, opts ...clientv3.OpOption) (bool, int64, error)

GetProtoMsgWithModRev returns boolean to indicate whether the key exists or not.

func GetValue

func GetValue(c *clientv3.Client, key string, opts ...clientv3.OpOption) ([]byte, error)

GetValue gets value with key from etcd.

func IsHealthy

func IsHealthy(ctx context.Context, client *clientv3.Client) bool

IsHealthy checks if the etcd is healthy.

func ListEtcdMembers

func ListEtcdMembers(ctx context.Context, client *clientv3.Client) (*clientv3.MemberListResponse, error)

ListEtcdMembers returns a list of internal etcd members.

func MustAddEtcdMember

func MustAddEtcdMember(t *testing.T, cfg1 *embed.Config, client *clientv3.Client) *embed.Etcd

MustAddEtcdMember is used to add a new etcd member to the cluster for test.

func NewTestEtcdCluster

func NewTestEtcdCluster(t *testing.T, count int) (servers []*embed.Etcd, etcdClient *clientv3.Client, clean func())

NewTestEtcdCluster is used to create a etcd cluster for the unit test purpose.

func NewTestSingleConfig

func NewTestSingleConfig() *embed.Config

NewTestSingleConfig is used to create a etcd config for the unit test purpose.

func RemoveEtcdMember

func RemoveEtcdMember(client *clientv3.Client, id uint64) (*clientv3.MemberRemoveResponse, error)

RemoveEtcdMember removes a member by the given id.

Types

type LoopWatcher

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

LoopWatcher loads data from etcd and sets a watcher for it.

func NewLoopWatcher

func NewLoopWatcher(
	ctx context.Context, wg *sync.WaitGroup,
	client *clientv3.Client,
	name, key string,
	preEventsFn func([]*clientv3.Event) error,
	putFn, deleteFn func(*mvccpb.KeyValue) error,
	postEventsFn func([]*clientv3.Event) error,
	isWithPrefix bool,
) *LoopWatcher

NewLoopWatcher creates a new LoopWatcher.

func (*LoopWatcher) ForceLoad

func (lw *LoopWatcher) ForceLoad()

ForceLoad forces to load the key.

func (*LoopWatcher) SetLoadBatchSize

func (lw *LoopWatcher) SetLoadBatchSize(size int64)

SetLoadBatchSize sets the batch size when loading data from etcd.

func (*LoopWatcher) SetLoadRetryTimes

func (lw *LoopWatcher) SetLoadRetryTimes(times int)

SetLoadRetryTimes sets the retry times when loading data from etcd.

func (*LoopWatcher) StartWatchLoop

func (lw *LoopWatcher) StartWatchLoop()

StartWatchLoop starts a loop to watch the key.

func (*LoopWatcher) WaitLoad

func (lw *LoopWatcher) WaitLoad() error

WaitLoad waits for the result to obtain whether data is loaded.

Jump to

Keyboard shortcuts

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