consuldsync

package
v0.15.1 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Module = &bootstrap.Module{
	Name:       "distributed",
	Precedence: bootstrap.DistributedLockPrecedence,
	Options: []fx.Option{
		fx.Provide(provideSyncManager),
	},
	Modules: []*bootstrap.Module{dsync.Module},
}

Functions

func Use

func Use()

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

func (*ConsulLock) TryLock

func (l *ConsulLock) TryLock(ctx context.Context) 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 ConsulSessionOption struct {
	Name       string
	TTL        time.Duration
	LockDelay  time.Duration
	RetryDelay time.Duration
}

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)

func (*ConsulSyncManager) Start

func (m *ConsulSyncManager) Start(_ context.Context) error

func (*ConsulSyncManager) Stop

func (m *ConsulSyncManager) Stop(ctx context.Context) error

Jump to

Keyboard shortcuts

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