lockmanager

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GroupConfig

type GroupConfig struct {
	Slots int `yaml:"slots"`
}

type Groups

type Groups map[string]GroupConfig

func NewDefaultGroups

func NewDefaultGroups() Groups

func (Groups) Validate

func (g Groups) Validate() error

type LockManager

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

func NewManager

func NewManager(groups Groups, storageCfg StorageConfig) (*LockManager, error)

Create a new LockManager from the given configuration

func NewManagerWithStorage

func NewManagerWithStorage(groups Groups, storage StorageBackend) *LockManager

Create a new LockManager with custom StorageBackend

func (*LockManager) Close

func (lm *LockManager) Close() error

func (*LockManager) Release

func (lm *LockManager) Release(group, id string) error

func (*LockManager) Reserve

func (lm *LockManager) Reserve(group, id string) (bool, error)

type StorageBackend

type StorageBackend interface {
	// Reserve a lock for the given group.
	// Returns true if the lock is successfully reserved, even if the lock is already held by the specific id
	Reserve(group, id string) error
	// Returns the current number of locks for the given group
	GetLocks(group string) (int, error)
	// Release the lock currently held by the id.
	// Does not fail when no lock is held.
	Release(group, id string) error
	// Return all locks older than x
	GetStaleLocks(ts time.Duration) ([]types.Lock, error)
	// Check if a given id already has a lock for this group
	HasLock(group, id string) (bool, error)
	// Calls all necessary finalization if necessary
	Close() error
}

It is assumed that each group itself is multi-read, single-write. There can be multiple writes to different groups happening in parallel though.

type StorageConfig

type StorageConfig struct {
	Type       string                      `yaml:"type"`
	SQLite     sql.SQLiteConfig            `yaml:"sqlite,omitempty"`
	Postgres   sql.PostgresConfig          `yaml:"postgres,omitempty"`
	MySQL      sql.MySQLConfig             `yaml:"mysql,omitempty"`
	Redis      redis.RedisConfig           `yaml:"redis,omitempty"`
	Etcd       etcd.EtcdConfig             `yaml:"etcd,omitempty"`
	Kubernetes kubernetes.KubernetesConfig `yaml:"kubernetes,omitempty"`
}

func NewDefaultStorageConfig

func NewDefaultStorageConfig() StorageConfig

Create a new storage config with default values

Directories

Path Synopsis
storage
sql

Jump to

Keyboard shortcuts

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