client

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2022 License: MPL-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Lock

type Lock struct {
	Acquired bool
	// contains filtered or unexported fields
}

Lock is a convenience wrapper around an inner `*consul.Client` with methods to aquire and release a mutually exclusive distributed lock using Consul sessions. This is used by attache-control to ensure that only one Redis Cluster node operation (create, add, remove) happens at once.

func New

func New(conf config.ConsulOpts, key string, sessionTimeout string) (*Lock, error)

New creates a new Consul client, aquires an ephemeral session with that client, and returns a `*Lock` to the caller.

func (*Lock) Acquire

func (l *Lock) Acquire() error

Acquire attempts to obtain a lock for the Consul KV path of `l.key`. Sets `l.Acquired` true on success and false on failure.

func (*Lock) Cleanup

func (l *Lock) Cleanup()

Cleanup stops periodic session renewals used to hold the lock, releases the lock by deleting the key, and destroys the session. Deleting the key and destroying the session only need to be best effort. In the event that either of these calls fail the lock will be released and the session will be destroyed l.sessionTimeout after l.renewChan is closed.

Jump to

Keyboard shortcuts

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