Add ha_enabled for mysql backend (#5122)

* Slight cleanup around mysql ha lock implementation

* Removes some duplication around lock table naming
* Escapes lock table name with backticks to handle weird characters
* Lock table defaults to regular table name + "_lock"
* Drop lock table after tests run

* Add `ha_enabled` option for mysql storage

It defaults to false, and we gate a few things like creating the lock
table and preparing lock related statements on it
This commit is contained in:
brianvans
2018-08-16 11:03:16 -07:00
committed by Brian Kassouf
parent c3e733623e
commit 801eddf5f8
3 changed files with 71 additions and 49 deletions

View File

@@ -47,7 +47,7 @@ func TestMySQLBackend(t *testing.T) {
defer func() {
mysql := b.(*MySQLBackend)
_, err := mysql.client.Exec("DROP TABLE " + mysql.dbTable)
_, err := mysql.client.Exec("DROP TABLE IF EXISTS " + mysql.dbTable + " ," + mysql.dbLockTable)
if err != nil {
t.Fatalf("Failed to drop table: %v", err)
}
@@ -80,11 +80,12 @@ func TestMySQLHABackend(t *testing.T) {
logger := logging.NewVaultLogger(log.Debug)
b, err := NewMySQLBackend(map[string]string{
"address": address,
"database": database,
"table": table,
"username": username,
"password": password,
"address": address,
"database": database,
"table": table,
"username": username,
"password": password,
"ha_enabled": "true",
}, logger)
if err != nil {
@@ -93,7 +94,7 @@ func TestMySQLHABackend(t *testing.T) {
defer func() {
mysql := b.(*MySQLBackend)
_, err := mysql.client.Exec("DROP TABLE " + mysql.dbTable)
_, err := mysql.client.Exec("DROP TABLE IF EXISTS " + mysql.dbTable + " ," + mysql.dbLockTable)
if err != nil {
t.Fatalf("Failed to drop table: %v", err)
}