revert GenerateAdvisoryLockID
This commit is contained in:
@@ -149,7 +149,7 @@ func (c *CockroachDb) Close() error {
|
||||
func (c *CockroachDb) Lock() error {
|
||||
return database.CasRestoreOnErr(&c.isLocked, false, true, database.ErrLocked, func() (err error) {
|
||||
return crdb.ExecuteTx(context.Background(), c.db, nil, func(tx *sql.Tx) (err error) {
|
||||
aid, err := database.GenerateAdvisoryLockID(c.config.DatabaseName)
|
||||
aid, err := database.GenerateAdvisoryLockId(c.config.DatabaseName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -185,7 +185,7 @@ func (c *CockroachDb) Lock() error {
|
||||
// See: https://github.com/cockroachdb/cockroach/issues/13546
|
||||
func (c *CockroachDb) Unlock() error {
|
||||
return database.CasRestoreOnErr(&c.isLocked, true, false, database.ErrNotLocked, func() (err error) {
|
||||
aid, err := database.GenerateAdvisoryLockID(c.config.DatabaseName)
|
||||
aid, err := database.GenerateAdvisoryLockId(c.config.DatabaseName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -287,7 +287,7 @@ func (m *Mysql) Lock() error {
|
||||
if m.config.NoLock {
|
||||
return nil
|
||||
}
|
||||
aid, err := database.GenerateAdvisoryLockID(
|
||||
aid, err := database.GenerateAdvisoryLockId(
|
||||
fmt.Sprintf("%s:%s", m.config.DatabaseName, m.config.MigrationsTable))
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -313,7 +313,7 @@ func (m *Mysql) Unlock() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
aid, err := database.GenerateAdvisoryLockID(
|
||||
aid, err := database.GenerateAdvisoryLockId(
|
||||
fmt.Sprintf("%s:%s", m.config.DatabaseName, m.config.MigrationsTable))
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
+4
-4
@@ -274,7 +274,7 @@ func (p *Postgres) Unlock() error {
|
||||
|
||||
// https://www.postgresql.org/docs/9.6/static/explicit-locking.html#ADVISORY-LOCKS
|
||||
func (p *Postgres) applyAdvisoryLock() error {
|
||||
aid, err := database.GenerateAdvisoryLockID(p.config.DatabaseName, p.config.migrationsSchemaName, p.config.migrationsTableName)
|
||||
aid, err := database.GenerateAdvisoryLockId(p.config.DatabaseName, p.config.migrationsSchemaName, p.config.migrationsTableName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -299,7 +299,7 @@ func (p *Postgres) applyTableLock() error {
|
||||
}
|
||||
}()
|
||||
|
||||
aid, err := database.GenerateAdvisoryLockID(p.config.DatabaseName)
|
||||
aid, err := database.GenerateAdvisoryLockId(p.config.DatabaseName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -331,7 +331,7 @@ func (p *Postgres) applyTableLock() error {
|
||||
}
|
||||
|
||||
func (p *Postgres) releaseAdvisoryLock() error {
|
||||
aid, err := database.GenerateAdvisoryLockID(p.config.DatabaseName, p.config.migrationsSchemaName, p.config.migrationsTableName)
|
||||
aid, err := database.GenerateAdvisoryLockId(p.config.DatabaseName, p.config.migrationsSchemaName, p.config.migrationsTableName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -345,7 +345,7 @@ func (p *Postgres) releaseAdvisoryLock() error {
|
||||
}
|
||||
|
||||
func (p *Postgres) releaseTableLock() error {
|
||||
aid, err := database.GenerateAdvisoryLockID(p.config.DatabaseName)
|
||||
aid, err := database.GenerateAdvisoryLockId(p.config.DatabaseName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -220,7 +220,7 @@ func (p *Postgres) Close() error {
|
||||
// https://www.postgresql.org/docs/9.6/static/explicit-locking.html#ADVISORY-LOCKS
|
||||
func (p *Postgres) Lock() error {
|
||||
return database.CasRestoreOnErr(&p.isLocked, false, true, database.ErrLocked, func() error {
|
||||
aid, err := database.GenerateAdvisoryLockID(p.config.DatabaseName, p.config.migrationsSchemaName, p.config.migrationsTableName)
|
||||
aid, err := database.GenerateAdvisoryLockId(p.config.DatabaseName, p.config.migrationsSchemaName, p.config.migrationsTableName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -236,7 +236,7 @@ func (p *Postgres) Lock() error {
|
||||
|
||||
func (p *Postgres) Unlock() error {
|
||||
return database.CasRestoreOnErr(&p.isLocked, true, false, database.ErrNotLocked, func() error {
|
||||
aid, err := database.GenerateAdvisoryLockID(p.config.DatabaseName, p.config.migrationsSchemaName, p.config.migrationsTableName)
|
||||
aid, err := database.GenerateAdvisoryLockId(p.config.DatabaseName, p.config.migrationsSchemaName, p.config.migrationsTableName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -232,7 +232,7 @@ func (p *Postgres) Close() error {
|
||||
// https://www.postgresql.org/docs/9.6/static/explicit-locking.html#ADVISORY-LOCKS
|
||||
func (p *Postgres) Lock() error {
|
||||
return database.CasRestoreOnErr(&p.isLocked, false, true, database.ErrLocked, func() error {
|
||||
aid, err := database.GenerateAdvisoryLockID(p.config.DatabaseName, p.config.migrationsSchemaName, p.config.migrationsTableName)
|
||||
aid, err := database.GenerateAdvisoryLockId(p.config.DatabaseName, p.config.migrationsSchemaName, p.config.migrationsTableName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -249,7 +249,7 @@ func (p *Postgres) Lock() error {
|
||||
|
||||
func (p *Postgres) Unlock() error {
|
||||
return database.CasRestoreOnErr(&p.isLocked, true, false, database.ErrNotLocked, func() error {
|
||||
aid, err := database.GenerateAdvisoryLockID(p.config.DatabaseName, p.config.migrationsSchemaName, p.config.migrationsTableName)
|
||||
aid, err := database.GenerateAdvisoryLockId(p.config.DatabaseName, p.config.migrationsSchemaName, p.config.migrationsTableName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -192,7 +192,7 @@ func (ss *SQLServer) Close() error {
|
||||
// Lock creates an advisory local on the database to prevent multiple migrations from running at the same time.
|
||||
func (ss *SQLServer) Lock() error {
|
||||
return database.CasRestoreOnErr(&ss.isLocked, false, true, database.ErrLocked, func() error {
|
||||
aid, err := database.GenerateAdvisoryLockID(ss.config.DatabaseName, ss.config.SchemaName)
|
||||
aid, err := database.GenerateAdvisoryLockId(ss.config.DatabaseName, ss.config.SchemaName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -222,7 +222,7 @@ func (ss *SQLServer) Lock() error {
|
||||
// Unlock froms the migration lock from the database
|
||||
func (ss *SQLServer) Unlock() error {
|
||||
return database.CasRestoreOnErr(&ss.isLocked, true, false, database.ErrNotLocked, func() error {
|
||||
aid, err := database.GenerateAdvisoryLockID(ss.config.DatabaseName, ss.config.SchemaName)
|
||||
aid, err := database.GenerateAdvisoryLockId(ss.config.DatabaseName, ss.config.SchemaName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
+2
-2
@@ -9,8 +9,8 @@ import (
|
||||
|
||||
const advisoryLockIDSalt uint = 1486364155
|
||||
|
||||
// GenerateAdvisoryLockID inspired by rails migrations, see https://goo.gl/8o9bCT
|
||||
func GenerateAdvisoryLockID(databaseName string, additionalNames ...string) (string, error) {
|
||||
// GenerateAdvisoryLockId inspired by rails migrations, see https://goo.gl/8o9bCT
|
||||
func GenerateAdvisoryLockId(databaseName string, additionalNames ...string) (string, error) { // nolint: golint
|
||||
if len(additionalNames) > 0 {
|
||||
databaseName = strings.Join(append(additionalNames, databaseName), "\x00")
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestGenerateAdvisoryLockID(t *testing.T) {
|
||||
func TestGenerateAdvisoryLockId(t *testing.T) {
|
||||
testcases := []struct {
|
||||
dbname string
|
||||
additional []string
|
||||
@@ -35,7 +35,7 @@ func TestGenerateAdvisoryLockID(t *testing.T) {
|
||||
|
||||
for _, tc := range testcases {
|
||||
t.Run(tc.dbname, func(t *testing.T) {
|
||||
if id, err := GenerateAdvisoryLockID(tc.dbname, tc.additional...); err == nil {
|
||||
if id, err := GenerateAdvisoryLockId(tc.dbname, tc.additional...); err == nil {
|
||||
if id != tc.expectedID {
|
||||
t.Error("Generated incorrect ID:", id, "!=", tc.expectedID)
|
||||
}
|
||||
|
||||
@@ -194,7 +194,7 @@ func (c *YugabyteDB) Close() error {
|
||||
func (c *YugabyteDB) Lock() error {
|
||||
return database.CasRestoreOnErr(&c.isLocked, false, true, database.ErrLocked, func() (err error) {
|
||||
return c.doTxWithRetry(context.Background(), &sql.TxOptions{Isolation: sql.LevelSerializable}, func(tx *sql.Tx) (err error) {
|
||||
aid, err := database.GenerateAdvisoryLockID(c.config.DatabaseName)
|
||||
aid, err := database.GenerateAdvisoryLockId(c.config.DatabaseName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -230,7 +230,7 @@ func (c *YugabyteDB) Lock() error {
|
||||
// See: https://github.com/yugabyte/yugabyte-db/issues/3642
|
||||
func (c *YugabyteDB) Unlock() error {
|
||||
return database.CasRestoreOnErr(&c.isLocked, true, false, database.ErrNotLocked, func() (err error) {
|
||||
aid, err := database.GenerateAdvisoryLockID(c.config.DatabaseName)
|
||||
aid, err := database.GenerateAdvisoryLockId(c.config.DatabaseName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user