etcd

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2022 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrKeyNotFound is thrown when the key is not found in the store during a Get operation
	ErrKeyNotFound = errors.New("key not found")
	ErrKeyModified = errors.New("unable to complete atomic operation, key modified")
)
View Source
var ErrLocked = errors.New("mutex: Locked by another session")

ErrLocked is returned by TryLock when Mutex is already locked by another session.

Functions

func FromEtcdError

func FromEtcdError(err error) error

func NewLocker added in v0.4.0

func NewLocker(s *concurrency.Session, pfx string) sync.Locker

NewLocker creates a sync.Locker backed by an etcd mutex.

Types

type Config

type Config struct {
	Log           zerolog.Logger
	Endpoints     string
	Prefix        string
	CertFile      string
	KeyFile       string
	CAFile        string
	SkipTLSVerify bool

	CompactionInterval time.Duration
}

type ListPagedContinuation

type ListPagedContinuation struct {
	Revision int64
	LastKey  string
}

type ListPagedResp

type ListPagedResp struct {
	Resp         *clientv3.GetResponse
	HasMore      bool
	Continuation *ListPagedContinuation
}

type Mutex added in v0.4.0

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

Mutex implements the sync Locker interface with etcd

func NewMutex added in v0.4.0

func NewMutex(s *concurrency.Session, pfx string) *Mutex

func (*Mutex) Header added in v0.4.0

func (m *Mutex) Header() *pb.ResponseHeader

Header is the response header received from etcd on acquiring the lock.

func (*Mutex) IsOwner added in v0.4.0

func (m *Mutex) IsOwner() v3.Cmp

func (*Mutex) Key added in v0.4.0

func (m *Mutex) Key() string

func (*Mutex) Lock added in v0.4.0

func (m *Mutex) Lock(ctx context.Context) error

Lock locks the mutex with a cancelable context. If the context is canceled while trying to acquire the lock, the mutex tries to clean its stale lock entry.

func (*Mutex) TryLock added in v0.4.0

func (m *Mutex) TryLock(ctx context.Context) error

TryLock locks the mutex if not already locked by another session. If lock is held by another session, return immediately after attempting necessary cleanup The ctx argument is used for the sending/receiving Txn RPC.

func (*Mutex) Unlock added in v0.4.0

func (m *Mutex) Unlock(ctx context.Context) error

type Store

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

func New

func New(cfg Config) (*Store, error)

func (*Store) AtomicDelete

func (s *Store) AtomicDelete(ctx context.Context, key string, revision int64) (*etcdclientv3.TxnResponse, error)

func (*Store) AtomicPut

func (s *Store) AtomicPut(ctx context.Context, key string, value []byte, prevRevision int64, options *WriteOptions) (*etcdclientv3.TxnResponse, error)

func (*Store) Client

func (s *Store) Client() *etcdclientv3.Client

func (*Store) Close

func (s *Store) Close() error

func (*Store) Delete

func (s *Store) Delete(ctx context.Context, key string) error

func (*Store) DeletePrefix added in v0.1.1

func (s *Store) DeletePrefix(ctx context.Context, prefix string) error

func (*Store) Get

func (s *Store) Get(ctx context.Context, key string, revision int64) (*etcdclientv3.GetResponse, error)

func (*Store) List

func (s *Store) List(ctx context.Context, directory, start string, revision int64) (*etcdclientv3.GetResponse, error)

func (*Store) ListPaged

func (s *Store) ListPaged(ctx context.Context, directory string, revision, limit int64, continuation *ListPagedContinuation) (*ListPagedResp, error)

func (*Store) Put

func (s *Store) Put(ctx context.Context, key string, value []byte, options *WriteOptions) (*etcdclientv3.PutResponse, error)

func (*Store) Watch

func (s *Store) Watch(ctx context.Context, prefix string, revision int64) etcdclientv3.WatchChan

func (*Store) WatchKey

func (s *Store) WatchKey(ctx context.Context, prefix string, revision int64) etcdclientv3.WatchChan

type WriteOptions

type WriteOptions struct {
	TTL time.Duration
}

Jump to

Keyboard shortcuts

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