Documentation
¶
Index ¶
- Variables
- type Key
- type Locker
- type LockerConfig
- type Releaser
- type SessionLocker
- func (l *SessionLocker) Close()
- func (l *SessionLocker) Lock(ctx context.Context, key Key) (Releaser, error)
- func (l *SessionLocker) LockWithScopes(ctx context.Context, scopes ...string) (Releaser, error)
- func (l *SessionLocker) Start(ctx context.Context) error
- func (l *SessionLocker) TryLock(ctx context.Context, key Key) (Releaser, error)
- func (l *SessionLocker) TryLockWithScopes(ctx context.Context, scopes ...string) (Releaser, error)
- type SessionLockerConfig
Constants ¶
This section is empty.
Variables ¶
var ( ErrNoLockAcquired = errors.New("lock could not be acquired") ErrNoLockReleased = errors.New("lock could not be released") ErrSessionLockerDone = errors.New("session locker is already closed") ErrSessionLockerBusy = errors.New("session locker is blocked by another lock request") )
var ErrLockTimeout = errors.New("lock operation timed out")
ErrLockTimeout is returned when a lock operation times out
Functions ¶
This section is empty.
Types ¶
type Locker ¶
type Locker struct {
// contains filtered or unexported fields
}
Locker is the generic interface for distributed business level locks.
func NewLocker ¶
func NewLocker(cfg *LockerConfig) (*Locker, error)
type LockerConfig ¶
func (*LockerConfig) Validate ¶
func (c *LockerConfig) Validate() error
type SessionLocker ¶
type SessionLocker struct {
// contains filtered or unexported fields
}
SessionLocker is a locker that uses PostgreSQL advisory locks to acquire locks. It requires a dedicated connection to acquire locks.
func NewSessionLockr ¶
func NewSessionLockr(config SessionLockerConfig) (*SessionLocker, error)
func (*SessionLocker) Close ¶
func (l *SessionLocker) Close()
Close releases all locks held by the SessionLocker and closes the underlying database connection.
func (*SessionLocker) Lock ¶
Lock blocks until a lock is acquired and returns a Releaser that can be used to release the lock if it is successfully acquired. The ErrNoLockAcquired is acquiring the lock is denied by the database server. The ErrSessionLockerDone is returned if SessionLocker is closed, meaning it cannot be used for acquiring locks.
func (*SessionLocker) LockWithScopes ¶
func (*SessionLocker) TryLock ¶
TryLock attempts to acquire a lock for the given key in a non-blocking way and returns a Releaser that can be used to release the lock if it is successfully acquired. The ErrNoLockAcquired is acquiring the lock is denied by the database server. It may return ErrSessionLockerBusy if the SessionLocker is blocked by another caller, indicating that the lock request may be retried. The ErrSessionLockerDone is returned if SessionLocker is closed, meaning it cannot be used for acquiring locks.