Skip to content

Commit 690b1e1

Browse files
artemvovkmeiji163
andauthored
fix: use cut-over-lock-timeout for instant DDL (#1468)
* fix: use cut-over-lock-timeout for instant DDL Addresses #1386 by reusing the cut-over-lock-timeout from the cutover code. The lock wait timeout in the original code is actually set to double the setting, so we keep that consistent. * add new usage to the arg description * Rename variable `query` to `lockTimeoutQuery` --------- Co-authored-by: meiji163 <meiji163@github.com>
1 parent 4b0ac90 commit 690b1e1

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

Diff for: go/cmd/gh-ost/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func main() {
107107
chunkSize := flag.Int64("chunk-size", 1000, "amount of rows to handle in each iteration (allowed range: 10-100,000)")
108108
dmlBatchSize := flag.Int64("dml-batch-size", 10, "batch size for DML events to apply in a single transaction (range 1-100)")
109109
defaultRetries := flag.Int64("default-retries", 60, "Default number of retries for various operations before panicking")
110-
cutOverLockTimeoutSeconds := flag.Int64("cut-over-lock-timeout-seconds", 3, "Max number of seconds to hold locks on tables while attempting to cut-over (retry attempted when lock exceeds timeout)")
110+
cutOverLockTimeoutSeconds := flag.Int64("cut-over-lock-timeout-seconds", 3, "Max number of seconds to hold locks on tables while attempting to cut-over (retry attempted when lock exceeds timeout) or attempting instant DDL")
111111
niceRatio := flag.Float64("nice-ratio", 0, "force being 'nice', imply sleep time per chunk time; range: [0.0..100.0]. Example values: 0 is aggressive. 1: for every 1ms spent copying rows, sleep additional 1ms (effectively doubling runtime); 0.7: for every 10ms spend in a rowcopy chunk, spend 7ms sleeping immediately after")
112112

113113
maxLagMillis := flag.Int64("max-lag-millis", 1500, "replication lag at which to throttle operation")

Diff for: go/logic/applier.go

+9
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,15 @@ func (this *Applier) ValidateOrDropExistingTables() error {
255255
func (this *Applier) AttemptInstantDDL() error {
256256
query := this.generateInstantDDLQuery()
257257
this.migrationContext.Log.Infof("INSTANT DDL query is: %s", query)
258+
259+
// Reuse cut-over-lock-timeout from regular migration process to reduce risk
260+
// in situations where there may be long-running transactions.
261+
tableLockTimeoutSeconds := this.migrationContext.CutOverLockTimeoutSeconds * 2
262+
this.migrationContext.Log.Infof("Setting LOCK timeout as %d seconds", tableLockTimeoutSeconds)
263+
lockTimeoutQuery := fmt.Sprintf(`set /* gh-ost */ session lock_wait_timeout:=%d`, tableLockTimeoutSeconds)
264+
if _, err := this.db.Exec(lockTimeoutQuery); err != nil {
265+
return err
266+
}
258267
// We don't need a trx, because for instant DDL the SQL mode doesn't matter.
259268
_, err := this.db.Exec(query)
260269
return err

0 commit comments

Comments
 (0)