Documentation ¶
Index ¶
- Variables
- func NewMySQLBackend(conf map[string]string, logger log.Logger) (physical.Backend, error)
- func NewMySQLClient(conf map[string]string, logger log.Logger) (*sql.DB, error)
- type MySQLBackend
- func (m *MySQLBackend) Delete(ctx context.Context, key string) error
- func (m *MySQLBackend) Get(ctx context.Context, key string) (*physical.Entry, error)
- func (m *MySQLBackend) HAEnabled() bool
- func (m *MySQLBackend) List(ctx context.Context, prefix string) ([]string, error)
- func (m *MySQLBackend) LockWith(key, value string) (physical.Lock, error)
- func (m *MySQLBackend) Put(ctx context.Context, entry *physical.Entry) error
- type MySQLHALock
- type MySQLLock
Constants ¶
This section is empty.
Variables ¶
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
Functions ¶
func NewMySQLBackend ¶
NewMySQLBackend constructs a MySQL backend using the given API client and server address and credential for accessing mysql database.
Types ¶
type MySQLBackend ¶
type MySQLBackend struct {
// contains filtered or unexported fields
}
MySQLBackend is a physical backend that stores data within MySQL database.
func (*MySQLBackend) Delete ¶
func (m *MySQLBackend) Delete(ctx context.Context, key string) error
Delete is used to permanently delete an entry
func (*MySQLBackend) HAEnabled ¶
func (m *MySQLBackend) HAEnabled() bool
func (*MySQLBackend) List ¶
List is used to list all the keys under a given prefix, up to the next prefix.
type MySQLHALock ¶
type MySQLHALock struct {
// contains filtered or unexported fields
}
MySQLHALock is a MySQL Lock implementation for the HABackend
func (*MySQLHALock) GetLeader ¶
func (i *MySQLHALock) GetLeader() (string, error)
func (*MySQLHALock) Lock ¶
func (i *MySQLHALock) Lock(stopCh <-chan struct{}) (<-chan struct{}, error)
func (*MySQLHALock) Unlock ¶
func (i *MySQLHALock) Unlock() error
type MySQLLock ¶
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.
func NewMySQLLock ¶
NewMySQLLock helper function
func (*MySQLLock) Lock ¶
Lock will try to get a lock for an indefinite amount of time based on the given key that has been requested.
func (*MySQLLock) Unlock ¶
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.