cluster

package
v0.26.2 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2024 License: AGPL-3.0, Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Mutex

type Mutex struct {
	// contains filtered or unexported fields
}

Mutex is similar to sync.Mutex, except usable by multiple plugin instances across a cluster.

Internally, a mutex relies on an atomic key-value set operation as exposed by the Mattermost plugin API.

Mutexes with different names are unrelated. Mutexes with the same name from different plugins are unrelated. Pick a unique name for each mutex your plugin requires.

A Mutex must not be copied after first use.

func NewMutex

func NewMutex(pluginAPI MutexPluginAPI, metricsAPI MutexMetricsAPI, key string, cfg MutexConfig) (*Mutex, error)

NewMutex creates a mutex with the given key name.

func (*Mutex) Lock

func (m *Mutex) Lock(ctx context.Context) error

Lock locks m unless the context is canceled. If the mutex is already locked by any plugin instance, including the current one, the calling goroutine blocks until the mutex can be locked, or the context is canceled.

The mutex is locked only if a nil error is returned.

func (*Mutex) Unlock

func (m *Mutex) Unlock()

Unlock unlocks m.

type MutexConfig added in v0.19.0

type MutexConfig struct {
	// TTL is the interval after which a locked mutex will expire unless
	// refreshed.
	TTL time.Duration
	// RefreshInterval is the interval on which the mutex will be refreshed when
	// locked.
	RefreshInterval time.Duration
	// PollInterval is the interval to wait between locking attempts.
	PollInterval time.Duration
	// MetricsGroup is an optional group name to use for mutex related metrics.
	MetricsGroup string
}

func (*MutexConfig) IsValid added in v0.19.0

func (c *MutexConfig) IsValid() error

func (*MutexConfig) SetDefaults added in v0.19.0

func (c *MutexConfig) SetDefaults()

type MutexMetricsAPI added in v0.19.0

type MutexMetricsAPI interface {
	ObserveClusterMutexGrabTime(key string, elapsed float64)
	ObserveClusterMutexLockedTime(key string, elapsed float64)
	IncClusterMutexLockRetries(group string)
}

MutexMetricsAPI is an interface to manage cluster mutex metrics.

type MutexPluginAPI

type MutexPluginAPI interface {
	KVSetWithOptions(key string, value []byte, options model.PluginKVSetOptions) (bool, *model.AppError)
	KVDelete(key string) *model.AppError
	LogError(msg string, keyValuePairs ...interface{})
	LogWarn(msg string, keyValuePairs ...interface{})
	LogDebug(msg string, keyValuePairs ...interface{})
}

MutexPluginAPI is the plugin API interface required to manage mutexes.

Jump to

Keyboard shortcuts

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