Help us shape the future of Go! Take the 2026 Go Developer Survey

mysql

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 18, 2019 License: MPL-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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 infromation")
	// Error to thow if inbetween 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

func NewMySQLBackend(conf map[string]string, logger log.Logger) (physical.Backend, error)

NewMySQLBackend constructs a MySQL backend using the given API client and server address and credential for accessing mysql database.

func NewMySQLClient added in v0.11.0

func NewMySQLClient(conf map[string]string, logger log.Logger) (*sql.DB, error)

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) Get

func (m *MySQLBackend) Get(ctx context.Context, key string) (*physical.Entry, error)

Get is used to fetch an entry.

func (*MySQLBackend) HAEnabled added in v0.11.0

func (m *MySQLBackend) HAEnabled() bool

func (*MySQLBackend) List

func (m *MySQLBackend) List(ctx context.Context, prefix string) ([]string, error)

List is used to list all the keys under a given prefix, up to the next prefix.

func (*MySQLBackend) LockWith added in v0.11.0

func (m *MySQLBackend) LockWith(key, value string) (physical.Lock, error)

LockWith is used for mutual exclusion based on the given key.

func (*MySQLBackend) Put

func (m *MySQLBackend) Put(ctx context.Context, entry *physical.Entry) error

Put is used to insert or update an entry.

type MySQLHALock added in v0.11.0

type MySQLHALock struct {
	// contains filtered or unexported fields
}

MySQLHALock is a MySQL Lock implementation for the HABackend

func (*MySQLHALock) GetLeader added in v0.11.0

func (i *MySQLHALock) GetLeader() (string, error)

func (*MySQLHALock) Lock added in v0.11.0

func (i *MySQLHALock) Lock(stopCh <-chan struct{}) (<-chan struct{}, error)

func (*MySQLHALock) Unlock added in v0.11.0

func (i *MySQLHALock) Unlock() error

func (*MySQLHALock) Value added in v0.11.0

func (i *MySQLHALock) Value() (bool, string, error)

type MySQLLock added in v0.11.0

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 added in v0.11.0

func NewMySQLLock(in *MySQLBackend, l log.Logger, key, value string) (*MySQLLock, error)

NewMySQLLock helper function

func (*MySQLLock) Lock added in v0.11.0

func (i *MySQLLock) Lock() error

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 added in v0.11.0

func (i *MySQLLock) Unlock() error

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL