lock

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2025 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EtcdRWLock

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

The etcd distributed lock enables you to have a powerful mutual exclusion (mutex) system in with an etcd cluster. You can't use a file lock in distributed environments such as Kubernetes because the Pods are isolated in there own contexts hence would not share the filelock information.

This implementation goes further than a simple mutex, as it implements the readers-writer lock for a writer-preference. Moreover, it implements a circuit breaker under the hood to handle network failures smoothly.

Based upon 'Concurrent Control with "Readers" and "Writers"' by Courtois et al. (1971) DOI: 10.1145/362759.362813

func (*EtcdRWLock) Close

func (lock *EtcdRWLock) Close() error

func (*EtcdRWLock) Key

func (lock *EtcdRWLock) Key() string

func (*EtcdRWLock) RLock

func (lock *EtcdRWLock) RLock(ctx context.Context) error

func (*EtcdRWLock) RUnlock

func (lock *EtcdRWLock) RUnlock(ctx context.Context) error

func (*EtcdRWLock) RWLock

func (lock *EtcdRWLock) RWLock(ctx context.Context) error

func (*EtcdRWLock) RWUnlock

func (lock *EtcdRWLock) RWUnlock(ctx context.Context) error

type LocalLock

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

func (*LocalLock) Close

func (lock *LocalLock) Close() error

func (*LocalLock) Key

func (lock *LocalLock) Key() string

func (*LocalLock) RLock

func (lock *LocalLock) RLock(_ context.Context) error

func (*LocalLock) RUnlock

func (lock *LocalLock) RUnlock(_ context.Context) error

func (*LocalLock) RWLock

func (lock *LocalLock) RWLock(_ context.Context) error

func (*LocalLock) RWUnlock

func (lock *LocalLock) RWUnlock(_ context.Context) error

type RWLock

type RWLock interface {
	Key() string

	// RLock is a reader lock
	RLock(context.Context) error
	// RUnlock is a reader unlock
	RUnlock(context.Context) error

	// RWLock is a writer lock, thus as priority over readers
	RWLock(context.Context) error
	// RWUnlock is a writer unlock
	RWUnlock(context.Context) error

	// Close network socket/connections
	Close() error
}

RWLock define an implementation of a readers-writer lock with writer-preference.

Locks should be short-lived and recover from previous states without the need to persist them in memory (for fault-tolerancy and scalability). This imply the context should be passed to the constructor rather than methods.

func NewEtcdRWLock

func NewEtcdRWLock(key string) (RWLock, error)

func NewLocalRWLock

func NewLocalRWLock(key string) (RWLock, error)

func NewRWLock

func NewRWLock(key string) (RWLock, error)

Jump to

Keyboard shortcuts

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