Skip to content

Commit 6824447

Browse files
author
Shlomi Noach
authored
Merge pull request #90 from github/control-lock-wait-timeout
supporting --cut-over-lock-timeout-seconds
2 parents 44b43ef + 8217536 commit 6824447

File tree

4 files changed

+27
-11
lines changed

4 files changed

+27
-11
lines changed

build.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22
#
33
#
4-
RELEASE_VERSION="0.9.9"
4+
RELEASE_VERSION="1.0.1"
55

66
buildpath=/tmp/gh-ost
77
target=gh-ost

go/base/context.go

+14-2
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ type MigrationContext struct {
6969
maxLoad LoadMap
7070
criticalLoad LoadMap
7171
PostponeCutOverFlagFile string
72-
SwapTablesTimeoutSeconds int64
72+
CutOverLockTimeoutSeconds int64
7373
PanicFlagFile string
7474

7575
ServeSocketFile string
@@ -149,7 +149,7 @@ func newMigrationContext() *MigrationContext {
149149
InspectorConnectionConfig: mysql.NewConnectionConfig(),
150150
ApplierConnectionConfig: mysql.NewConnectionConfig(),
151151
MaxLagMillisecondsThrottleThreshold: 1000,
152-
SwapTablesTimeoutSeconds: 3,
152+
CutOverLockTimeoutSeconds: 3,
153153
maxLoad: NewLoadMap(),
154154
criticalLoad: NewLoadMap(),
155155
throttleMutex: &sync.Mutex{},
@@ -210,13 +210,25 @@ func (this *MigrationContext) HasMigrationRange() bool {
210210
return this.MigrationRangeMinValues != nil && this.MigrationRangeMaxValues != nil
211211
}
212212

213+
func (this *MigrationContext) SetCutOverLockTimeoutSeconds(timeoutSeconds int64) error {
214+
if timeoutSeconds < 1 {
215+
return fmt.Errorf("Minimal timeout is 1sec. Timeout remains at %d", this.CutOverLockTimeoutSeconds)
216+
}
217+
if timeoutSeconds > 10 {
218+
return fmt.Errorf("Maximal timeout is 10sec. Timeout remains at %d", this.CutOverLockTimeoutSeconds)
219+
}
220+
this.CutOverLockTimeoutSeconds = timeoutSeconds
221+
return nil
222+
}
223+
213224
func (this *MigrationContext) SetDefaultNumRetries(retries int64) {
214225
this.throttleMutex.Lock()
215226
defer this.throttleMutex.Unlock()
216227
if retries > 0 {
217228
this.defaultNumRetries = retries
218229
}
219230
}
231+
220232
func (this *MigrationContext) MaxRetries() int64 {
221233
this.throttleMutex.Lock()
222234
defer this.throttleMutex.Unlock()

go/cmd/gh-ost/main.go

+4
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ func main() {
7171
flag.BoolVar(&migrationContext.SwitchToRowBinlogFormat, "switch-to-rbr", false, "let this tool automatically switch binary log format to 'ROW' on the replica, if needed. The format will NOT be switched back. I'm too scared to do that, and wish to protect you if you happen to execute another migration while this one is running")
7272
chunkSize := flag.Int64("chunk-size", 1000, "amount of rows to handle in each iteration (allowed range: 100-100,000)")
7373
defaultRetries := flag.Int64("default-retries", 60, "Default number of retries for various operations before panicking")
74+
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)")
7475
flag.Int64Var(&migrationContext.NiceRatio, "nice-ratio", 0, "force being 'nice', imply sleep time per chunk time. Example values: 0 is aggressive. 3: for every ms spend in a rowcopy chunk, spend 3ms sleeping immediately after")
7576

7677
flag.Int64Var(&migrationContext.MaxLagMillisecondsThrottleThreshold, "max-lag-millis", 1500, "replication lag at which to throttle operation")
@@ -172,6 +173,9 @@ func main() {
172173
migrationContext.SetChunkSize(*chunkSize)
173174
migrationContext.SetDefaultNumRetries(*defaultRetries)
174175
migrationContext.ApplyCredentials()
176+
if err := migrationContext.SetCutOverLockTimeoutSeconds(*cutOverLockTimeoutSeconds); err != nil {
177+
log.Errore(err)
178+
}
175179

176180
log.Infof("starting gh-ost %+v", AppVersion)
177181
acceptSignals(migrationContext)

go/logic/applier.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ func (this *Applier) LockOriginalTableAndWait(sessionIdChan chan int64, tableLoc
632632
return err
633633
}
634634

635-
tableLockTimeoutSeconds := this.migrationContext.SwapTablesTimeoutSeconds * 2
635+
tableLockTimeoutSeconds := this.migrationContext.CutOverLockTimeoutSeconds * 2
636636
log.Infof("Setting LOCK timeout as %d seconds", tableLockTimeoutSeconds)
637637
query = fmt.Sprintf(`set session lock_wait_timeout:=%d`, tableLockTimeoutSeconds)
638638
if _, err := tx.Exec(query); err != nil {
@@ -690,8 +690,8 @@ func (this *Applier) RenameOriginalTable(sessionIdChan chan int64, originalTable
690690
}
691691
sessionIdChan <- sessionId
692692

693-
log.Infof("Setting RENAME timeout as %d seconds", this.migrationContext.SwapTablesTimeoutSeconds)
694-
query := fmt.Sprintf(`set session lock_wait_timeout:=%d`, this.migrationContext.SwapTablesTimeoutSeconds)
693+
log.Infof("Setting RENAME timeout as %d seconds", this.migrationContext.CutOverLockTimeoutSeconds)
694+
query := fmt.Sprintf(`set session lock_wait_timeout:=%d`, this.migrationContext.CutOverLockTimeoutSeconds)
695695
if _, err := tx.Exec(query); err != nil {
696696
return err
697697
}
@@ -725,8 +725,8 @@ func (this *Applier) RenameGhostTable(sessionIdChan chan int64, ghostTableRename
725725
}
726726
sessionIdChan <- sessionId
727727

728-
log.Infof("Setting RENAME timeout as %d seconds", this.migrationContext.SwapTablesTimeoutSeconds)
729-
query := fmt.Sprintf(`set session lock_wait_timeout:=%d`, this.migrationContext.SwapTablesTimeoutSeconds)
728+
log.Infof("Setting RENAME timeout as %d seconds", this.migrationContext.CutOverLockTimeoutSeconds)
729+
query := fmt.Sprintf(`set session lock_wait_timeout:=%d`, this.migrationContext.CutOverLockTimeoutSeconds)
730730
if _, err := tx.Exec(query); err != nil {
731731
return err
732732
}
@@ -861,7 +861,7 @@ func (this *Applier) AtomicCutOverMagicLock(sessionIdChan chan int64, tableLocke
861861
return err
862862
}
863863

864-
tableLockTimeoutSeconds := this.migrationContext.SwapTablesTimeoutSeconds * 2
864+
tableLockTimeoutSeconds := this.migrationContext.CutOverLockTimeoutSeconds * 2
865865
log.Infof("Setting LOCK timeout as %d seconds", tableLockTimeoutSeconds)
866866
query = fmt.Sprintf(`set session lock_wait_timeout:=%d`, tableLockTimeoutSeconds)
867867
if _, err := tx.Exec(query); err != nil {
@@ -948,8 +948,8 @@ func (this *Applier) AtomicCutoverRename(sessionIdChan chan int64, tablesRenamed
948948
}
949949
sessionIdChan <- sessionId
950950

951-
log.Infof("Setting RENAME timeout as %d seconds", this.migrationContext.SwapTablesTimeoutSeconds)
952-
query := fmt.Sprintf(`set session lock_wait_timeout:=%d`, this.migrationContext.SwapTablesTimeoutSeconds)
951+
log.Infof("Setting RENAME timeout as %d seconds", this.migrationContext.CutOverLockTimeoutSeconds)
952+
query := fmt.Sprintf(`set session lock_wait_timeout:=%d`, this.migrationContext.CutOverLockTimeoutSeconds)
953953
if _, err := tx.Exec(query); err != nil {
954954
return err
955955
}

0 commit comments

Comments
 (0)