This section is empty.


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


    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

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


      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

            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

              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

                  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

                    func (*MySQLHALock) Value

                    func (i *MySQLHALock) Value() (bool, string, 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

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

                        NewMySQLLock helper function

                        func (*MySQLLock) Lock

                        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

                          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.

                            Source Files