Skip to content

Commit ac4c538

Browse files
pr suggestions
Signed-off-by: Tim Vaillancourt <[email protected]>
1 parent d0b0a85 commit ac4c538

File tree

3 files changed

+19
-43
lines changed

3 files changed

+19
-43
lines changed

go/base/context.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ type MigrationContext struct {
135135
CriticalLoadHibernateSeconds int64
136136
PostponeCutOverFlagFile string
137137
CutOverLockTimeoutSeconds int64
138-
CutOverIdleTimeoutSeconds int64
139138
CutOverExponentialBackoff bool
140139
ExponentialBackoffMaxInterval int64
141140
ForceNamedCutOverCommand bool
@@ -278,7 +277,6 @@ func NewMigrationContext() *MigrationContext {
278277
ApplierConnectionConfig: mysql.NewConnectionConfig(),
279278
MaxLagMillisecondsThrottleThreshold: 1500,
280279
CutOverLockTimeoutSeconds: 3,
281-
CutOverIdleTimeoutSeconds: 6,
282280
DMLBatchSize: 10,
283281
etaNanoseonds: ETAUnknown,
284282
maxLoad: NewLoadMap(),

go/cmd/gh-ost/main.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ func main() {
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")
110110
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)")
111-
flag.Int64Var(&migrationContext.CutOverIdleTimeoutSeconds, "cut-over-idle-timeout-seconds", *cutOverLockTimeoutSeconds*2, "the idle timeout in seconds for the cut-over operation. The MySQL session performing the cut-over uses this as a wait_timeout.")
112111
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")
113112

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

go/logic/applier.go

Lines changed: 19 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -937,40 +937,14 @@ func (this *Applier) CreateAtomicCutOverSentryTable() error {
937937
return nil
938938
}
939939

940-
// WaitForAtomicCutOverRename waits for the cut-over RENAME operation while periodically
941-
// pinging the applier connection to avoid the connection becoming idle.
942-
func (this *Applier) WaitForAtomicCutOverRename(tx *gosql.Tx, okToUnlockTable <-chan bool) {
943-
ticker := time.NewTicker(time.Millisecond * 500)
944-
defer ticker.Stop()
945-
for {
946-
select {
947-
case <-okToUnlockTable:
948-
this.migrationContext.Log.Infof("Will now proceed to drop magic table and unlock tables")
949-
return
950-
case <-ticker.C:
951-
// keep connection alive as we wait for the RENAME.
952-
if _, err := tx.Exec(`select /* gh-ost */ 1`); err != nil {
953-
this.migrationContext.Log.Errorf("Failed to ping applier connection: %v", err)
954-
}
955-
}
956-
}
957-
}
958-
959940
// InitAtomicCutOverIdleTimeout sets the cut-over session wait_timeout, returning a func() to rollback
960941
// to the original wait_timeout and an error, if any.
961-
func (this *Applier) InitAtomicCutOverIdleTimeout(tx *gosql.Tx) (restoreTimeoutFunc func(), err error) {
962-
this.migrationContext.Log.Infof("Setting cut-over idle timeout as %d seconds", this.migrationContext.CutOverIdleTimeoutSeconds)
963-
query := fmt.Sprintf(`set /* gh-ost */ session wait_timeout:=%d`, this.migrationContext.CutOverIdleTimeoutSeconds)
964-
_, err = tx.Exec(query)
965-
return func() {
966-
this.migrationContext.Log.Infof("Restoring applier idle timeout as %d seconds", this.migrationContext.ApplierWaitTimeout)
967-
query = fmt.Sprintf(`set /* gh-ost */ session wait_timeout:=%d`, this.migrationContext.ApplierWaitTimeout)
968-
if _, err := sqlutils.ExecNoPrepare(this.db, query); err != nil {
969-
this.migrationContext.Log.Errorf("Failed to restore applier wait_timeout to %d seconds: %v",
970-
this.migrationContext.ApplierWaitTimeout, err,
971-
)
972-
}
973-
}, err
942+
func (this *Applier) InitAtomicCutOverIdleTimeout(tx *gosql.Tx) error {
943+
cutOverIdleTimeoutSeconds := this.migrationContext.CutOverLockTimeoutSeconds * 2
944+
this.migrationContext.Log.Infof("Setting cut-over idle timeout as %d seconds", cutOverIdleTimeoutSeconds)
945+
query := fmt.Sprintf(`set /* gh-ost */ session wait_timeout:=%d`, cutOverIdleTimeoutSeconds)
946+
_, err := tx.Exec(query)
947+
return err
974948
}
975949

976950
// AtomicCutOverMagicLock
@@ -1013,13 +987,17 @@ func (this *Applier) AtomicCutOverMagicLock(sessionIdChan chan int64, tableLocke
1013987
return err
1014988
}
1015989

1016-
if this.migrationContext.CutOverIdleTimeoutSeconds >= 1 {
1017-
restoreIdleTimeoutFunc, err := this.InitAtomicCutOverIdleTimeout(tx)
1018-
if err != nil {
1019-
tableLocked <- err
1020-
return err
1021-
}
1022-
defer restoreIdleTimeoutFunc()
990+
defer func() {
991+
if _, err := sqlutils.ExecNoPrepare(this.db, query); err != nil {
992+
this.migrationContext.Log.Errorf("Failed to restore applier wait_timeout to %d seconds: %v",
993+
this.migrationContext.ApplierWaitTimeout, err,
994+
)
995+
}
996+
}()
997+
998+
if err := this.InitAtomicCutOverIdleTimeout(tx); err != nil {
999+
tableLocked <- err
1000+
return err
10231001
}
10241002

10251003
if err := this.CreateAtomicCutOverSentryTable(); err != nil {
@@ -1052,7 +1030,8 @@ func (this *Applier) AtomicCutOverMagicLock(sessionIdChan chan int64, tableLocke
10521030

10531031
// The cut-over phase will proceed to apply remaining backlog onto ghost table,
10541032
// and issue RENAME. We wait here until told to proceed.
1055-
this.WaitForAtomicCutOverRename(tx, okToUnlockTable)
1033+
<-okToUnlockTable
1034+
this.migrationContext.Log.Infof("Will now proceed to drop magic table and unlock tables")
10561035

10571036
// The magic table is here because we locked it. And we are the only ones allowed to drop it.
10581037
// And in fact, we will:

0 commit comments

Comments
 (0)