import "github.com/hashicorp/vault/physical/mysql"
var ( // This is the GlobalLockID for checking if the lock we got is still the current lock GlobalLockID int64 // ErrLockHeld is returned when another vault instance already has a lock held for the given key. ErrLockHeld = errors.New("mysql: lock already held") // ErrUnlockFailed ErrUnlockFailed = errors.New("mysql: unable to release lock, already released or not held by this session") // You were unable to update that you are the new leader in the DB ErrClaimFailed = errors.New("mysql: unable to update DB with new leader information") // Error to throw if between getting the lock and checking the ID of it we lost it. ErrSettingGlobalID = errors.New("mysql: getting global lock id failed") )
Errors specific to trying to grab a lock in MySQL
NewMySQLBackend constructs a MySQL backend using the given API client and server address and credential for accessing mysql database.
type MySQLBackend struct {
// contains filtered or unexported fields
}
MySQLBackend is a physical backend that stores data within MySQL database.
Delete is used to permanently delete an entry
Get is used to fetch an entry.
func (m *MySQLBackend) HAEnabled() bool
List is used to list all the keys under a given prefix, up to the next prefix.
LockWith is used for mutual exclusion based on the given key.
Put is used to insert or update an entry.
type MySQLHALock struct {
// contains filtered or unexported fields
}
MySQLHALock is a MySQL Lock implementation for the HABackend
func (i *MySQLHALock) GetLeader() (string, error)
func (i *MySQLHALock) Lock(stopCh <-chan struct{}) (<-chan struct{}, error)
func (i *MySQLHALock) Unlock() error
func (i *MySQLHALock) Value() (bool, string, error)
type MySQLLock struct {
// contains filtered or unexported fields
}
MySQLLock provides an easy way to grab and release mysql locks using the built in GET_LOCK function. Note that these locks are released when you lose connection to the server.
NewMySQLLock helper function
Lock will try to get a lock for an indefinite amount of time based on the given key that has been requested.
Unlock just closes the connection. This is because closing the MySQL connection is a 100% reliable way to close the lock. If you just release the lock you must do it from the same mysql connection_id that you originally created it from. This is a huge hastle and I actually couldn't find a clean way to do this although one likely does exist. Closing the connection however ensures we don't ever get into a state where we try to release the lock and it hangs it is also much less code.
Package mysql imports 22 packages (graph) and is imported by 6 packages. Updated 2020-10-13. Refresh now. Tools for package owners.