setcd

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

@Title @Description @Author Wangwengang 2024/1/8 13:05 @Update Wangwengang 2024/1/8 13:05

@Title @Description @Author Wangwengang 2024/1/8 12:59 @Update Wangwengang 2024/1/8 12:59

@Title @Description @Author Wangwengang 2024/1/8 13:00 @Update Wangwengang 2024/1/8 13:00

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewLocker

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

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

Types

type Mutex

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

Mutex implements the sync Locker interface with etcd

func NewMutex

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

func (*Mutex) Header

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

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

func (*Mutex) IsOwner

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

func (*Mutex) Key

func (m *Mutex) Key() string

func (*Mutex) Lock

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) Unlock

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

type Session

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

Session represents a lease kept alive for the lifetime of a client. Fault-tolerant applications may use sessions to reason about liveness.

func NewSession

func NewSession(client *v3.Client, opts ...SessionOption) (*Session, error)

NewSession gets the leased session for a client.

func (*Session) Client

func (s *Session) Client() *v3.Client

Client is the etcd client that is attached to the session.

func (*Session) Close

func (s *Session) Close() error

Close orphans the session and revokes the session lease.

func (*Session) Done

func (s *Session) Done() <-chan struct{}

Done returns a channel that closes when the lease is orphaned, expires, or is otherwise no longer being refreshed.

func (*Session) Lease

func (s *Session) Lease() v3.LeaseID

Lease is the lease ID for keys bound to the session.

func (*Session) Orphan

func (s *Session) Orphan()

Orphan ends the refresh for the session lease. This is useful in case the state of the client connection is indeterminate (revoke would fail) or when transferring lease ownership. 终止刷新租约

type SessionOption

type SessionOption func(*sessionOptions)

SessionOption configures Session.

func WithContext

func WithContext(ctx context.Context) SessionOption

WithContext assigns a context to the session instead of defaulting to using the client context. This is useful for canceling NewSession and Close operations immediately without having to close the client. If the context is canceled before Close() completes, the session's lease will be abandoned and left to expire instead of being revoked.

func WithLease

func WithLease(leaseID v3.LeaseID) SessionOption

WithLease specifies the existing leaseID to be used for the session. This is useful in process restart scenario, for example, to reclaim leadership from an election prior to restart.

func WithTTL

func WithTTL(ttl int) SessionOption

WithTTL configures the session's TTL in seconds. If TTL is <= 0, the default 60 seconds TTL will be used.

Jump to

Keyboard shortcuts

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