mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
SQLStore: Enable migration locking by default (#84983)
* Introduce new configuration for migration locking * Remove feature toggle * Fix test and turn it into an integration * Fix docs
This commit is contained in:
committed by
GitHub
parent
980b9a62c6
commit
33b653534e
@@ -39,6 +39,7 @@ type DatabaseConfig struct {
|
||||
WALEnabled bool
|
||||
UrlQueryParams map[string][]string
|
||||
SkipMigrations bool
|
||||
MigrationLock bool
|
||||
MigrationLockAttemptTimeout int
|
||||
LogQueries bool
|
||||
// SQLite only
|
||||
@@ -113,6 +114,7 @@ func (dbCfg *DatabaseConfig) readConfig(cfg *setting.Cfg) error {
|
||||
dbCfg.CacheMode = sec.Key("cache_mode").MustString("private")
|
||||
dbCfg.WALEnabled = sec.Key("wal").MustBool(false)
|
||||
dbCfg.SkipMigrations = sec.Key("skip_migrations").MustBool()
|
||||
dbCfg.MigrationLock = sec.Key("migration_locking").MustBool(true)
|
||||
dbCfg.MigrationLockAttemptTimeout = sec.Key("locking_attempt_timeout_sec").MustInt()
|
||||
|
||||
dbCfg.QueryRetries = sec.Key("query_retries").MustInt()
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/go-sql-driver/mysql"
|
||||
"github.com/golang-migrate/migrate/v4/database"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"gopkg.in/ini.v1"
|
||||
@@ -69,7 +70,11 @@ func TestMigrations(t *testing.T) {
|
||||
checkStepsAndDatabaseMatch(t, mg, expectedMigrations)
|
||||
}
|
||||
|
||||
func TestMigrationLock(t *testing.T) {
|
||||
func TestIntegrationMigrationLock(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("skipping integration test")
|
||||
}
|
||||
|
||||
dbType := sqlutil.GetTestDBType()
|
||||
if dbType == SQLite {
|
||||
t.Skip()
|
||||
@@ -96,9 +101,12 @@ func TestMigrationLock(t *testing.T) {
|
||||
sess.Close()
|
||||
})
|
||||
|
||||
key, err := database.GenerateAdvisoryLockId("test")
|
||||
require.NoError(t, err)
|
||||
|
||||
cfg := LockCfg{
|
||||
Session: sess,
|
||||
Key: "test",
|
||||
Key: key,
|
||||
}
|
||||
|
||||
t.Run("obtaining lock should succeed", func(t *testing.T) {
|
||||
@@ -143,7 +151,7 @@ func TestMigrationLock(t *testing.T) {
|
||||
err = dialect.Lock(cfg)
|
||||
require.NoError(t, err)
|
||||
|
||||
err = d2.Lock(LockCfg{Session: sess2})
|
||||
err = d2.Lock(LockCfg{Session: sess2, Key: key})
|
||||
require.Error(t, err)
|
||||
assert.ErrorIs(t, err, ErrLockDB)
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ func ProvideService(cfg *setting.Cfg,
|
||||
}
|
||||
s.features = features
|
||||
|
||||
if err := s.Migrate(features.IsEnabledGlobally(featuremgmt.FlagMigrationLocking)); err != nil {
|
||||
if err := s.Migrate(s.dbCfg.MigrationLock); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user