Documentation
¶
Index ¶
- Constants
- type Driver
- type Execer
- type MysqlDriver
- func (MysqlDriver) CreateMutexEntryIfNotExists(ctx context.Context, qe QueryExecer, tableName string, mutexName string) error
- func (MysqlDriver) CreateMutexTableIfNotExists(ctx context.Context, ex Execer, tableName string) error
- func (MysqlDriver) Lock(ctx context.Context, ex Execer, tableName string, mutexName string, ...) (bool, error)
- func (MysqlDriver) Refresh(ctx context.Context, ex Execer, tableName string, mutexName string, ...) (bool, error)
- func (MysqlDriver) Unlock(ctx context.Context, ex Execer, tableName string, mutexName string, ...) (bool, error)
- type PostgresDriver
- func (PostgresDriver) CreateMutexEntryIfNotExists(ctx context.Context, qe QueryExecer, tableName string, mutexName string) error
- func (PostgresDriver) CreateMutexTableIfNotExists(ctx context.Context, ex Execer, tableName string) error
- func (PostgresDriver) Lock(ctx context.Context, ex Execer, tableName string, mutexName string, ...) (bool, error)
- func (PostgresDriver) Refresh(ctx context.Context, ex Execer, tableName string, mutexName string, ...) (bool, error)
- func (PostgresDriver) Unlock(ctx context.Context, ex Execer, tableName string, mutexName string, ...) (bool, error)
- type QueryExecer
- type Queryer
Constants ¶
View Source
const ( // Max length of a named mutex. MaxMutexNameLength = 256 // Max length of hostname. MaxHostnameLength = 256 // Max length of locker id. MaxLockerIdLength = 256 )
These constants hold maximum lengths for a few attributes.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Driver ¶
type Driver interface { // CreateLockTableIfNotExists creates tableName if it does not exists. CreateMutexTableIfNotExists( ctx context.Context, ex Execer, tableName string, ) error // CreateLockEntryIfNotExists creates an entry in tableName for mutexName. CreateMutexEntryIfNotExists( ctx context.Context, qe QueryExecer, tableName string, mutexName string, ) error // AcquireLock attempts to acquire the mutex identified by tableName and mutexName. It returns true // if the mutex was acquired. hostname, pid and lockerId are stored with the mutex in order to help // with lock holder identification. The mutex should be refreshed (by calling Refresh) after // refresh time elapses and will expire after expires time. Lock( ctx context.Context, ex Execer, tableName string, mutexName string, hostname string, pid int, lockerId string, refresh time.Duration, expires time.Duration, ) (bool, error) // Refresh refreshes a locked mutex by updating the row in tableName for the mutex identified by // mutexName, hostname, pid and lockerId. Refresh should be called again in refresh time. // Return true if the lock was refreshed successfully. Refresh( ctx context.Context, ex Execer, tableName string, mutexName string, hostname string, pid int, lockerId string, refresh time.Duration, expires time.Duration, ) (bool, error) // ReleaseLock releases a locked mutex by updating the row in tableName for the mutex identified by // mutexName, hostname, pid and lockerId. Return true if the mutex was unlocked successfully. Unlock( ctx context.Context, ex Execer, tableName string, mutexName string, hostname string, pid int, lockerId string, ) (bool, error) }
Driver is the interface that must be implemented by the database-based locker. All operations should fail fast (returning an error) since retry logic is handled outside of Driver.
type Execer ¶
type Execer interface {
ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
}
Execer is the contract used when executing statements against the DB.
type MysqlDriver ¶
type MysqlDriver struct{}
MysqlDriver is the mysql specific Driver implementation.
func (MysqlDriver) CreateMutexEntryIfNotExists ¶
func (MysqlDriver) CreateMutexEntryIfNotExists( ctx context.Context, qe QueryExecer, tableName string, mutexName string, ) error
func (MysqlDriver) CreateMutexTableIfNotExists ¶
type PostgresDriver ¶
type PostgresDriver struct{}
PostgresDriver is the postgres specific Driver implementation.
func (PostgresDriver) CreateMutexEntryIfNotExists ¶
func (PostgresDriver) CreateMutexEntryIfNotExists( ctx context.Context, qe QueryExecer, tableName string, mutexName string, ) error
func (PostgresDriver) CreateMutexTableIfNotExists ¶
type QueryExecer ¶
QueryExecer is both an Execer and a Queryer.
Click to show internal directories.
Click to hide internal directories.