Documentation ¶
Index ¶
- Constants
- Variables
- func WithRefreshInterval(d time.Duration) lockerOpt
- type Lock
- type MysqlLocker
- func (l MysqlLocker) Obtain(key string) (*Lock, error)
- func (l MysqlLocker) ObtainContext(ctx context.Context, key string) (*Lock, error)
- func (l MysqlLocker) ObtainTimeout(key string, timeout int) (*Lock, error)
- func (l MysqlLocker) ObtainTimeoutContext(ctx context.Context, key string, timeout int) (*Lock, error)
Constants ¶
const DefaultRefreshInterval = time.Second
DefaultRefreshInterval is the periodic duration with which a connection is refreshed/pinged
Variables ¶
var ErrGetLockContextCancelled = errors.New("context cancelled while trying to obtain lock")
ErrGetLockContextCancelled is returned when user given context is cancelled while trying to obtain the lock
var ErrMySQLInternalError = errors.New("internal mysql error acquiring the lock")
ErrMySQLInternalError is returned when MySQL is returning a generic internal error
var ErrMySQLTimeout = errors.New("(mysql) timeout while acquiring the lock")
ErrMySQLTimeout is returned when the MySQL server can't acquire the lock in the specified timeout
Functions ¶
func WithRefreshInterval ¶
WithRefreshInterval sets the duration for refresh interval for each obtained lock
Types ¶
type Lock ¶
type Lock struct {
// contains filtered or unexported fields
}
Lock denotes an acquired lock and presents two methods, one for getting the context which is cancelled when the lock is lost/released and other for Releasing the lock
func (Lock) GetContext ¶
GetContext returns a context which is cancelled when the lock is lost or released
type MysqlLocker ¶
type MysqlLocker struct {
// contains filtered or unexported fields
}
MysqlLocker is the client which provide APIs to obtain lock
func NewMysqlLocker ¶
func NewMysqlLocker(db *sql.DB, lockerOpts ...lockerOpt) *MysqlLocker
NewMysqlLocker returns an instance of locker which can be used to obtain locks
func (MysqlLocker) Obtain ¶
func (l MysqlLocker) Obtain(key string) (*Lock, error)
Obtain tries to acquire lock (with no MySQL timeout) with background context. This call is expected to block is lock is already held
func (MysqlLocker) ObtainContext ¶
ObtainContext tries to acquire lock and gives up when the given context is cancelled
func (MysqlLocker) ObtainTimeout ¶
func (l MysqlLocker) ObtainTimeout(key string, timeout int) (*Lock, error)
ObtainTimeout tries to acquire lock with background context and a MySQL timeout. This call is expected to block is lock is already held
func (MysqlLocker) ObtainTimeoutContext ¶
func (l MysqlLocker) ObtainTimeoutContext(ctx context.Context, key string, timeout int) (*Lock, error)
ObtainTimeoutContext tries to acquire lock and gives up when the given context is cancelled