Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
Functions ¶
Types ¶
type ConsulLock ¶
type ConsulLock struct {
// contains filtered or unexported fields
}
ConsulLock implements Lock interface using consul lock described at https://www.consul.io/docs/guides/leader-election.html The implementation is modified api.Lock. The major difference are: - Session is created/maintained outside. There is no session creation when attempt to lock - "lock or wait" vs "try lock and return" is not pre-determined via options.
func (*ConsulLock) Key ¶
func (l *ConsulLock) Key() string
func (*ConsulLock) Lock ¶
func (l *ConsulLock) Lock(ctx context.Context) error
Lock implements dsync.Lock The acquired lock may get revoked from server-side, unless the session is specifically created without any associated health checks.
func (*ConsulLock) Lost ¶
func (l *ConsulLock) Lost() <-chan struct{}
func (*ConsulLock) Release ¶
func (l *ConsulLock) Release() error
type ConsulLockOption ¶
type ConsulLockOption struct { Context context.Context SessionFunc func(context.Context) (string, error) Key string // Must be set and have write permissions Valuer dsync.LockValuer // cannot be nil, valuer to associate with the lock. Default to static json marshaller QueryWaitTime time.Duration // how long we block per GET to check if lock acquisition is possible RetryDelay time.Duration // how long we wait after a retryable error (usually network error) }
type ConsulLockOptions ¶
type ConsulLockOptions func(opt *ConsulLockOption)
type ConsulSessionOption ¶
type ConsulSessionOptions ¶
type ConsulSessionOptions func(opt *ConsulSessionOption)
type ConsulSyncManager ¶
type ConsulSyncManager struct {
// contains filtered or unexported fields
}
ConsulSyncManager implements SyncManager leveraging consul's session feature See https://learn.hashicorp.com/tutorials/consul/application-leader-elections?in=consul/developer-configuration
https://learn.hashicorp.com/tutorials/consul/distributed-semaphore https://www.consul.io/docs/dynamic-app-config/sessions
func NewConsulLockManager ¶
func NewConsulLockManager(ctx *bootstrap.ApplicationContext, conn *consul.Connection, opts ...ConsulSessionOptions) (ret *ConsulSyncManager)
func (*ConsulSyncManager) Lock ¶
func (m *ConsulSyncManager) Lock(key string, opts ...dsync.LockOptions) (dsync.Lock, error)