Skip to content

Commit 302dbf0

Browse files
author
Shlomi Noach
authored
Merge pull request #63 from github/cut-over-on-test-on-replica
test-on-replica to invoke cut-over swap
2 parents 29aead6 + b8c7e04 commit 302dbf0

File tree

4 files changed

+43
-7
lines changed

4 files changed

+43
-7
lines changed

build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22
#
33
#
4-
RELEASE_VERSION="0.8.8"
4+
RELEASE_VERSION="0.8.9"
55

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

go/base/context.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ const (
3131
type CutOver int
3232

3333
const (
34-
CutOverTwoStep CutOver = 1
35-
CutOverVoluntaryLock
36-
CutOverUdfWait
34+
CutOverTwoStep CutOver = iota
35+
CutOverVoluntaryLock = iota
36+
CutOverUdfWait = iota
3737
)
3838

3939
const (

go/logic/applier.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,31 @@ func (this *Applier) SwapTablesAtomic(sessionIdChan chan int64) error {
536536
return nil
537537
}
538538

539+
func (this *Applier) RenameTablesRollback() (renameError error) {
540+
541+
query := fmt.Sprintf(`rename /* gh-ost */ table %s.%s to %s.%s`,
542+
sql.EscapeName(this.migrationContext.DatabaseName),
543+
sql.EscapeName(this.migrationContext.OriginalTableName),
544+
sql.EscapeName(this.migrationContext.DatabaseName),
545+
sql.EscapeName(this.migrationContext.GetGhostTableName()),
546+
)
547+
log.Infof("Renaming back to ghost table")
548+
if _, err := sqlutils.ExecNoPrepare(this.db, query); err != nil {
549+
renameError = err
550+
}
551+
query = fmt.Sprintf(`rename /* gh-ost */ table %s.%s to %s.%s`,
552+
sql.EscapeName(this.migrationContext.DatabaseName),
553+
sql.EscapeName(this.migrationContext.GetOldTableName()),
554+
sql.EscapeName(this.migrationContext.DatabaseName),
555+
sql.EscapeName(this.migrationContext.OriginalTableName),
556+
)
557+
log.Infof("Renaming back to original table")
558+
if _, err := sqlutils.ExecNoPrepare(this.db, query); err != nil {
559+
renameError = err
560+
}
561+
return log.Errore(renameError)
562+
}
563+
539564
// StopSlaveIOThread is applicable with --test-on-replica; it stops the IO thread, duh.
540565
// We need to keep the SQL thread active so as to complete processing received events,
541566
// and have them written to the binary log, so that we can then read them via streamer

go/logic/migrator.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -389,14 +389,25 @@ func (this *Migrator) stopWritesAndCompleteMigration() (err error) {
389389
)
390390

391391
if this.migrationContext.TestOnReplica {
392-
return this.stopWritesAndCompleteMigrationOnReplica()
392+
// return this.stopWritesAndCompleteMigrationOnReplica()
393+
394+
// With `--test-on-replica` we stop replication thread, and then proceed to use
395+
// the same cut-over phase as the master would use. That means we take locks
396+
// and swap the tables.
397+
// The difference is that we will later swap the tables back.
398+
log.Debugf("testing on replica. Stopping replication IO thread")
399+
if err := this.retryOperation(this.applier.StopSlaveNicely); err != nil {
400+
return err
401+
}
402+
// We're merly testing, we don't want to keep this state. Rollback the renames as possible
403+
defer this.applier.RenameTablesRollback()
393404
}
394-
// Running on master
405+
395406
if this.migrationContext.CutOverType == base.CutOverTwoStep {
396407
return this.stopWritesAndCompleteMigrationOnMasterQuickAndBumpy()
397408
}
398409

399-
{
410+
if this.migrationContext.CutOverType == base.CutOverVoluntaryLock {
400411
// Lock-based solution: we use low timeout and multiple attempts. But for
401412
// each failed attempt, we throttle until replication lag is back to normal
402413
if err := this.retryOperation(

0 commit comments

Comments
 (0)