Documentation ¶
Overview ¶
Package distlock provides an interface for distributed locking mechanisms.
Index ¶
Constants ¶
const DefaultLockName = "onex-distributed-lock"
DefaultLockName is the default name used for the distributed lock.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ConsulLocker ¶
type ConsulLocker struct {
// contains filtered or unexported fields
}
ConsulLocker is a structure that implements distributed locking using Consul.
func NewConsulLocker ¶
func NewConsulLocker(consulAddr string, opts ...Option) (*ConsulLocker, error)
NewConsulLocker creates a new ConsulLocker instance.
func (*ConsulLocker) Lock ¶
func (l *ConsulLocker) Lock(ctx context.Context) error
Lock attempts to acquire the distributed lock.
type EtcdLocker ¶
type EtcdLocker struct {
// contains filtered or unexported fields
}
EtcdLocker provides a distributed locking mechanism using etcd.
func NewEtcdLocker ¶
func NewEtcdLocker(endpoints []string, opts ...Option) (*EtcdLocker, error)
NewEtcdLocker initializes a new EtcdLocker instance.
func (*EtcdLocker) Lock ¶
func (l *EtcdLocker) Lock(ctx context.Context) error
Lock acquires the distributed lock.
type GORMLocker ¶
type GORMLocker struct {
// contains filtered or unexported fields
}
GORMLocker provides a distributed locking mechanism using GORM.
func NewGORMLocker ¶
func NewGORMLocker(db *gorm.DB, opts ...Option) (*GORMLocker, error)
NewGORMLocker initializes a new GORMLocker instance.
func (*GORMLocker) Lock ¶
func (l *GORMLocker) Lock(ctx context.Context) error
Lock acquires the distributed lock.
type Lock ¶
type Lock struct { ID uint `gorm:"primarykey"` Name string `gorm:"unique"` OwnerID string ExpiredAt time.Time CreatedAt time.Time UpdatedAt time.Time }
Lock represents a database record for a distributed lock.
type Locker ¶
type Locker interface { // Lock attempts to acquire the lock. Lock(ctx context.Context) error // Unlock releases the previously acquired lock. Unlock(ctx context.Context) error // Renew updates the expiration time of the lock. // It should be called periodically to keep the lock active. Renew(ctx context.Context) error }
Locker is an interface that defines the methods for a distributed lock. It provides methods to acquire, release, and renew a lock in a distributed system.
type MemcachedLocker ¶
type MemcachedLocker struct {
// contains filtered or unexported fields
}
MemcachedLocker provides a distributed locking mechanism using Memcached.
func NewMemcachedLocker ¶
func NewMemcachedLocker(memcachedAddr string, opts ...Option) *MemcachedLocker
NewMemcachedLocker creates a new MemcachedLocker instance.
func (*MemcachedLocker) Lock ¶
func (l *MemcachedLocker) Lock(ctx context.Context) error
Lock attempts to acquire the distributed lock.
type MongoLocker ¶
type MongoLocker struct {
// contains filtered or unexported fields
}
MongoLocker provides a distributed locking mechanism using MongoDB.
func NewMongoLocker ¶
func NewMongoLocker(mongoURI string, dbName string, opts ...Option) (*MongoLocker, error)
NewMongoLocker creates a new MongoLocker instance.
func (*MongoLocker) Lock ¶
func (l *MongoLocker) Lock(ctx context.Context) error
Lock attempts to acquire the distributed lock.
type NoopLocker ¶
type NoopLocker struct {
// contains filtered or unexported fields
}
NoopLocker provides a no-operation implementation of a distributed lock.
func NewNoopLocker ¶
func NewNoopLocker(opts ...Option) *NoopLocker
NewNoopLocker creates a new NoopLocker instance.
func (*NoopLocker) Lock ¶
func (l *NoopLocker) Lock(ctx context.Context) error
Lock simulates acquiring a distributed lock.
type Option ¶
type Option func(o *Options)
Option is a function that modifies Options.
func WithLockName ¶
WithLockName sets the lock name in Options.
func WithLockTimeout ¶
WithLockTimeout sets the lock timeout in Options.
func WithLogger ¶
WithLogger sets the logger in Options.
func WithOwnerID ¶
WithOwnerID sets the owner ID in Options.
type Options ¶
type Options struct {
// contains filtered or unexported fields
}
Options holds the configuration for the distributed lock.
func ApplyOptions ¶
ApplyOptions applies a series of Option functions to configure Options.
type RedisLocker ¶
type RedisLocker struct {
// contains filtered or unexported fields
}
RedisLocker provides a distributed locking mechanism using Redis.
func NewRedisLocker ¶
func NewRedisLocker(client *redis.Client, opts ...Option) *RedisLocker
NewRedisLocker creates a new RedisLocker instance.
func (*RedisLocker) Lock ¶
func (l *RedisLocker) Lock(ctx context.Context) error
Lock attempts to acquire the distributed lock.
type ZookeeperLocker ¶
type ZookeeperLocker struct {
// contains filtered or unexported fields
}
ZookeeperLocker provides a distributed locking mechanism using Zookeeper.
func NewZookeeperLocker ¶
func NewZookeeperLocker(zkServers []string, opts ...Option) (*ZookeeperLocker, error)
NewZookeeperLocker creates a new ZookeeperLocker instance.
func (*ZookeeperLocker) Lock ¶
func (l *ZookeeperLocker) Lock(ctx context.Context) error
Lock attempts to acquire the distributed lock.