dsync

package
v0.1.50 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2024 License: LGPL-2.1 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Name  = self.Name
	Using = self.Using
)
View Source
var (
	// ErrNotAcquired is an error indicating that the distributed lock was not acquired. It is returned by IDistMutex.Unlock and IDistMutex.Extend when the lock was not successfully acquired or has expired.
	ErrNotAcquired = errors.New("dsync: lock is not acquired")
)
View Source
var With _Option

Functions

This section is empty.

Types

type DelayFunc

type DelayFunc = generic.Func1[int, time.Duration]

A DelayFunc is used to decide the amount of time to wait between retries.

type DistMutexOptions

type DistMutexOptions struct {
	Expiry        time.Duration
	Tries         int
	DelayFunc     DelayFunc
	DriftFactor   float64
	TimeoutFactor float64
	GenValueFunc  GenValueFunc
	Value         string
}

DistMutexOptions represents the options for acquiring a distributed mutex.

type GenValueFunc

type GenValueFunc = generic.PairFunc0[string, error]

GenValueFunc is used to generate a random value.

type IDistMutex

type IDistMutex interface {
	// Name returns mutex name.
	Name() string
	// Value returns the current random value. The value will be empty until a lock is acquired (or Value option is used).
	Value() string
	// Until returns the time of validity of acquired lock. The value will be zero value until a lock is acquired.
	Until() time.Time
	// Lock locks m. In case it returns an error on failure, you may retry to acquire the lock by calling this method again.
	Lock(ctx context.Context) error
	// Unlock unlocks m and returns the status of unlock.
	Unlock(ctx context.Context) error
	// Extend resets the mutex's expiry and returns the status of expiry extension.
	Extend(ctx context.Context) error
	// Valid returns true if the lock acquired through m is still valid. It may also return true erroneously if quorum is achieved during the call and at
	// least one node then takes long enough to respond for the lock to expire.
	Valid(ctx context.Context) (bool, error)
}

A IDistMutex is a distributed mutual exclusion lock. Avoid sharing the same IDistMutex instance among multiple goroutines. Create a separate IDistMutex instance for each goroutine.

type IDistSync

type IDistSync interface {
	// NewMutex returns a new distributed mutex with given name.
	NewMutex(name string, settings ...option.Setting[DistMutexOptions]) IDistMutex
	// GetSeparator return name path separator.
	GetSeparator() string
}

IDistSync represents a distributed synchronization mechanism.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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