vault: github.com/hashicorp/vault/physical/mysql Index | Files

package mysql

import "github.com/hashicorp/vault/physical/mysql"

Index

Package Files

mysql.go

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

func NewMySQLBackend Uses

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 Uses

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

type MySQLBackend Uses

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

MySQLBackend is a physical backend that stores data within MySQL database.

func (*MySQLBackend) Delete Uses

func (m *MySQLBackend) Delete(ctx context.Context, key string) error

Delete is used to permanently delete an entry

func (*MySQLBackend) Get Uses

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

Get is used to fetch an entry.

func (*MySQLBackend) HAEnabled Uses

func (m *MySQLBackend) HAEnabled() bool

func (*MySQLBackend) List Uses

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 Uses

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

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

func (*MySQLBackend) Put Uses

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

Put is used to insert or update an entry.

type MySQLHALock Uses

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

MySQLHALock is a MySQL Lock implementation for the HABackend

func (*MySQLHALock) GetLeader Uses

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

func (*MySQLHALock) Lock Uses

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

func (*MySQLHALock) Unlock Uses

func (i *MySQLHALock) Unlock() error

func (*MySQLHALock) Value Uses

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

type MySQLLock Uses

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 Uses

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

NewMySQLLock helper function

func (*MySQLLock) Lock Uses

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 Uses

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.

Package mysql imports 20 packages (graph) and is imported by 3 packages. Updated 2019-04-28. Refresh now. Tools for package owners.