etcd

package
v0.3.19 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultConnectTimeOut    = 10 * time.Second
	DefaultMutexLeaseSeconds = 3600
	MaxTTL                   = 3600 * 24
	MinimumTTL               = 1
	ZeroRevision             = 0
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Conn

type Conn struct {
	Endpoints     []string
	KeyLeaseIDMap sync.Map
	clientv3.Config
	clientv3.Client
	clientv3.Lease
}

func NewEtcdConn

func NewEtcdConn(endpoints []string) (*Conn, error)

NewEtcdConn returns connection to etcd, it uses client v3 library api

func NewEtcdConnWithConnectTimeout added in v0.1.1

func NewEtcdConnWithConnectTimeout(endpoints []string, timeout time.Duration) (*Conn, error)

NewEtcdConnWithConnectTimeout returns connection to etcd, it uses client v3 library api

func (*Conn) CheckLeaseGrantExists

func (conn *Conn) CheckLeaseGrantExists(ctx context.Context, leaseID clientv3.LeaseID) (bool, error)

CheckLeaseGrantExists checks if given leaseID still exists

func (*Conn) Close

func (conn *Conn) Close() error

Close closes the connection

func (*Conn) Delete

func (conn *Conn) Delete(ctx context.Context, key string) (*clientv3.DeleteResponse, error)

Delete deletes the key, but does NOT revoke the concerned lease because the lease may be assigned to other keys.

func (*Conn) DeleteWithPrefix

func (conn *Conn) DeleteWithPrefix(ctx context.Context, key string) (*clientv3.DeleteResponse, error)

DeleteWithPrefix delete the keys of which name started with the given key, but does NOT revoke the concerned lease because the lease may be assigned to other keys.

func (*Conn) GetLeaseIDByKey

func (conn *Conn) GetLeaseIDByKey(key string) clientv3.LeaseID

GetLeaseIDByKey returns lease response by mutex key name which was maintained when successfully get the mutex

func (*Conn) LockEtcdMutex

func (conn *Conn) LockEtcdMutex(ctx context.Context, mutexKey, mutexValue string, ttl int64) (bool, error)

LockEtcdMutex tries to get a distributed mutex from etcd, if success, return true, nil

func (*Conn) PutWithTTL

func (conn *Conn) PutWithTTL(ctx context.Context, key, value string, ttl int64) (*clientv3.PutResponse, *clientv3.LeaseKeepAliveResponse, error)

PutWithTTL is an alias of PutWithTTLAndKeepAliveOnce

func (*Conn) PutWithTTLAndKeepAlive

func (conn *Conn) PutWithTTLAndKeepAlive(ctx context.Context, key, value string, ttl int64) (*clientv3.PutResponse, <-chan *clientv3.LeaseKeepAliveResponse, error)

PutWithTTLAndKeepAlive put the key and value and keep alive the lease with given ttl

func (*Conn) PutWithTTLAndKeepAliveOnce

func (conn *Conn) PutWithTTLAndKeepAliveOnce(ctx context.Context, key, value string, ttl int64) (*clientv3.PutResponse, *clientv3.LeaseKeepAliveResponse, error)

PutWithTTLAndKeepAliveOnce puts the key and value and refresh the lease with given ttl once.

func (*Conn) UnlockEtcdMutex

func (conn *Conn) UnlockEtcdMutex(ctx context.Context, mutexKey string) (*clientv3.LeaseRevokeResponse, error)

UnlockEtcdMutex releases the distributed mutex

Jump to

Keyboard shortcuts

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