Documentation ¶
Overview ¶
Package lock provides a mechanism for distributed locks. Several instances of components (same component name, different component IDs) can compete to execute Jobs. We want that a given job (recognised by its job name) is executed only once at a time. To achive that we use CockroachDB, a distributed ACID DB. Each component will execute a transaction to lock the job, the transaction that succeed will obtain the lock, and the component can execute the corresponding job. Also, when a lock is disabled, the Lock method will always return an ErrDisabled error.
Index ¶
- type ErrDisabled
- type ErrUnauthorised
- type LocalLock
- type Lock
- type NoopLocker
- func (l *NoopLocker) Disable(componentName, jobName string) error
- func (l *NoopLocker) Enable(componentName, jobName string) error
- func (l *NoopLocker) Lock(componentName, componentID, jobName, jobID string, ...) error
- func (l *NoopLocker) Unlock(componentName, componentID, jobName, jobID string) error
- type Storage
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ErrDisabled ¶
type ErrDisabled struct {
// contains filtered or unexported fields
}
ErrDisabled is the error returned when the lock is disabled.
func (*ErrDisabled) Error ¶
func (e *ErrDisabled) Error() string
type ErrUnauthorised ¶
type ErrUnauthorised struct {
// contains filtered or unexported fields
}
ErrUnauthorised is the error returned when there is a call to the Lock method, but there is already another component owning the lock.
func (*ErrUnauthorised) Error ¶
func (e *ErrUnauthorised) Error() string
type LocalLock ¶
type LocalLock struct {
// contains filtered or unexported fields
}
LocalLock is the local lock
func NewLocalLock ¶
func NewLocalLock() *LocalLock
NewLocalLock returns a lock local, that is a lock that does not use the distributed Storage to assure that only one instance of the job is running in the cluster.
type Lock ¶
type Lock struct {
// contains filtered or unexported fields
}
Lock is the locking module.
func (*Lock) Disable ¶
Disable disable the job. It sets the 'enabled' boolean to false for the current job.
func (*Lock) Enable ¶
Enable enable the job. It sets the 'enabled' boolean to true for the current job.
type NoopLocker ¶
type NoopLocker struct{}
NoopLocker is a lock that does nothing, it always accept lock requests. It should be used when no lock is required.
func (*NoopLocker) Disable ¶
func (l *NoopLocker) Disable(componentName, jobName string) error
Disable does nothing.
func (*NoopLocker) Enable ¶
func (l *NoopLocker) Enable(componentName, jobName string) error
Enable does nothing.
func (*NoopLocker) Lock ¶
func (l *NoopLocker) Lock(componentName, componentID, jobName, jobID string, jobMaxDuration time.Duration) error
Lock does nothing.
func (*NoopLocker) Unlock ¶
func (l *NoopLocker) Unlock(componentName, componentID, jobName, jobID string) error
Unlock does nothing.