sync

package
v0.0.0-...-cbea63e Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2021 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrContended error = errors.New("Could not obtain lock due to contention")
	ErrGenUuid   error = errors.New("Error locking due to UUID generation failure")
	ErrHoldFor   error = errors.New("Error locking - holdFor duration must be 2 seconds or greater")
)
View Source
var (
	ErrRegionHoldFor error = errors.New(fmt.Sprintf("Error locking - holdFor duration must be %v or greater", minRegionHoldFor))
)
View Source
var (
	ErrReserved = errors.New("[Reservation] Item already reserved")
)

Functions

func AnonymousRelease

func AnonymousRelease(path, id string) error

AnonymousRelease will release the reservation of the item with the given id and path

func CleanupRegionLeaders

func CleanupRegionLeaders()

CleanupRegionLeaders is a cleanup callback function which is run when the service is interrupted and rescinds any outstanding region leaders.

func SetRegionLockNamespace

func SetRegionLockNamespace(ns string)

SetRegionLockNamespace should be set to the service name on startup, and never again!

Types

type DefaultReservation

type DefaultReservation struct {
	Ttl time.Duration
	// contains filtered or unexported fields
}

func (*DefaultReservation) Release

func (dr *DefaultReservation) Release() error

Release will release the reservation in the DefaultReservation

func (*DefaultReservation) Reserve

func (dr *DefaultReservation) Reserve(d time.Duration) error

Reserve will reserve an item with the id in the DefaultReservation for the given amount of time.

type Leader

type Leader interface {
	// Rescinded returns a channel that will be closed if/when leadership is rescinded
	Rescinded() chan struct{}
	// Rescind allows clients to manually rescind leadership
	Rescind()
}

Leader is an interface used by return values on things that can elect a leader

func NewGlobalLeader

func NewGlobalLeader(id string) Leader

NewGlobalLocker returns a global leader which is basically just a region leader pinned to one region based on config.

func RegionLeader

func RegionLeader(id string) Leader

RegionLeader block indefinitely until this invocation has been elected the "leader" within the local operating region. It will then return a channel that will eventually be closed when leadership is rescinded.

type Lock

type Lock interface {
	// Unlock allows clients to release the lock
	Unlock()
}

Lock is an interface used by return values on things that can achieve a lock

func GlobalLock

func GlobalLock(id []byte) (Lock, error)

GlobalLock attempts to achieve a lock using default timing values of 1 second and 5 seconds

func GlobalTimedLock

func GlobalTimedLock(id []byte, waitFor, holdFor time.Duration) (Lock, error)

GlobalTimedLock attempts to achieve a global lock on `id`, waiting for `waitFor` time in case of contention (before giving up) and reserving the lock for a maximum `holdFor` in the event of failure NOTE: locks can and will be held for longer than `holdFor`, but in the case of failure (eg: binary crashes) then this is the maximum amount of time other programs will hang around contending for the now defunkt lock

func RegionLock

func RegionLock(id []byte) (Lock, error)

RegionLock attempts to achieve a lock using default timing values

func RegionTimedLock

func RegionTimedLock(id []byte, waitFor, holdFor time.Duration) (Lock, error)

RegionTimedLock attempts to achieve a regional lock on `id`, waiting for `waitFor` time in case of contention (before giving up) and reserving the lock for a maximum `holdFor` in the event of failing to Unlock()

type Reservation

type Reservation interface {
	Reserve(time.Duration) error
	Release() error
}

Reservation will reserve an item given an id. The reservation must expire and may be released at any time by any actor

func NewReservation

func NewReservation(path, id string, acl []gozk.ACL) Reservation

NewReservation creates a default reservation

type ReservationData

type ReservationData struct {
	Expires time.Time
}

Jump to

Keyboard shortcuts

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