Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions go/logic/applier.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,16 +308,15 @@ func (this *Applier) AttemptInstantDDL() error {
return retryOnLockWaitTimeout(func() error {
_, err := this.db.Exec(query)
return err
}, this.migrationContext.Log)
}, this.migrationContext.MaxRetries(), this.migrationContext.Log)
}

// retryOnLockWaitTimeout retries the given operation on MySQL lock wait timeout
// (errno 1205). Non-timeout errors return immediately. This is used for instant
// DDL attempts where the operation may be blocked by a long-running transaction.
func retryOnLockWaitTimeout(operation func() error, logger base.Logger) error {
const maxRetries = 5
func retryOnLockWaitTimeout(operation func() error, maxRetries int64, logger base.Logger) error {
Comment thread
meiji163 marked this conversation as resolved.
var err error
for i := 0; i < maxRetries; i++ {
for i := int64(0); i < maxRetries; i++ {
if i != 0 {
logger.Infof("Retrying after lock wait timeout (attempt %d/%d)", i+1, maxRetries)
RetrySleepFn(time.Duration(i) * 5 * time.Second)
Expand Down
10 changes: 5 additions & 5 deletions go/logic/applier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ func TestRetryOnLockWaitTimeout(t *testing.T) {
err := retryOnLockWaitTimeout(func() error {
calls++
return nil
}, logger)
}, int64(5), logger)
require.NoError(t, err)
require.Equal(t, 1, calls)
})
Expand All @@ -229,7 +229,7 @@ func TestRetryOnLockWaitTimeout(t *testing.T) {
return lockWaitTimeoutErr
}
return nil
}, logger)
}, int64(5), logger)
require.NoError(t, err)
require.Equal(t, 3, calls)
})
Expand All @@ -239,7 +239,7 @@ func TestRetryOnLockWaitTimeout(t *testing.T) {
err := retryOnLockWaitTimeout(func() error {
calls++
return nonRetryableErr
}, logger)
}, int64(5), logger)
require.ErrorIs(t, err, nonRetryableErr)
require.Equal(t, 1, calls)
})
Expand All @@ -250,7 +250,7 @@ func TestRetryOnLockWaitTimeout(t *testing.T) {
err := retryOnLockWaitTimeout(func() error {
calls++
return genericErr
}, logger)
}, int64(5), logger)
require.ErrorIs(t, err, genericErr)
require.Equal(t, 1, calls)
})
Expand All @@ -260,7 +260,7 @@ func TestRetryOnLockWaitTimeout(t *testing.T) {
err := retryOnLockWaitTimeout(func() error {
calls++
return lockWaitTimeoutErr
}, logger)
}, int64(5), logger)
require.ErrorIs(t, err, lockWaitTimeoutErr)
require.Equal(t, 5, calls)
})
Expand Down
Loading