Documentation ¶
Index ¶
- Variables
- func GetSeparator(servCtx service.Context) string
- func Path(servCtx service.Context, elems ...string) string
- type DelayFunc
- type DistMutexOptions
- type GenValueFunc
- type IDistMutex
- type IDistSync
- type Option
- func (Option) Default() option.Setting[DistMutexOptions]
- func (Option) DriftFactor(factor float64) option.Setting[DistMutexOptions]
- func (Option) Expiry(expiry time.Duration) option.Setting[DistMutexOptions]
- func (Option) GenValueFunc(fn GenValueFunc) option.Setting[DistMutexOptions]
- func (Option) RetryDelay(delay time.Duration) option.Setting[DistMutexOptions]
- func (Option) RetryDelayFunc(fn DelayFunc) option.Setting[DistMutexOptions]
- func (Option) TimeoutFactor(factor float64) option.Setting[DistMutexOptions]
- func (Option) Tries(tries int) option.Setting[DistMutexOptions]
- func (Option) Value(v string) option.Setting[DistMutexOptions]
Constants ¶
This section is empty.
Variables ¶
var ( Name = plugin.Name Using = plugin.Using )
var ( // ErrDsync dsync errors. ErrDsync = errors.New("dsync") // 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 = fmt.Errorf("%w: lock is not acquired", ErrDsync) )
Functions ¶
func GetSeparator ¶
GetSeparator return name path separator.
Types ¶
type DistMutexOptions ¶ added in v0.1.21
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 ¶
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.
func NewMutex ¶
func NewMutex(servCtx service.Context, name string, settings ...option.Setting[DistMutexOptions]) IDistMutex
NewMutex returns a new distributed mutex with given name.
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.
type Option ¶
type Option struct{}
Option is a helper struct to provide default options.
func (Option) Default ¶
func (Option) Default() option.Setting[DistMutexOptions]
Default sets the default options for acquiring a distributed mutex.
func (Option) DriftFactor ¶
func (Option) DriftFactor(factor float64) option.Setting[DistMutexOptions]
DriftFactor can be used to set the clock drift factor.
func (Option) GenValueFunc ¶
func (Option) GenValueFunc(fn GenValueFunc) option.Setting[DistMutexOptions]
GenValueFunc can be used to set the custom value generator.
func (Option) RetryDelay ¶
RetryDelay can be used to set the amount of time to wait between retries.
func (Option) RetryDelayFunc ¶
func (Option) RetryDelayFunc(fn DelayFunc) option.Setting[DistMutexOptions]
RetryDelayFunc can be used to override default delay behavior.
func (Option) TimeoutFactor ¶
func (Option) TimeoutFactor(factor float64) option.Setting[DistMutexOptions]
TimeoutFactor can be used to set the timeout factor.