@@ -100,7 +100,7 @@ func (this *Applier) InitDBConnections() (err error) {
100100 if err := this .validateAndReadGlobalVariables (); err != nil {
101101 return err
102102 }
103- if ! this .migrationContext .AliyunRDS && ! this .migrationContext .GoogleCloudPlatform && ! this .migrationContext .AzureMySQL {
103+ if ! this .migrationContext .AliyunRDS && ! this .migrationContext .GoogleCloudPlatform && ! this .migrationContext .AzureMySQL && ! this . migrationContext . OceanBase {
104104 if impliedKey , err := mysql .GetInstanceKey (this .db ); err != nil {
105105 return err
106106 } else {
@@ -714,24 +714,28 @@ func (this *Applier) ApplyIterationInsertQuery() (chunkSize int64, rowsAffected
714714 return chunkSize , rowsAffected , duration , nil
715715}
716716
717- // LockOriginalTable places a write lock on the original table
718- func (this * Applier ) LockOriginalTable () error {
719- query := fmt .Sprintf (`lock /* gh-ost */ tables %s.%s write` ,
720- sql .EscapeName (this .migrationContext .DatabaseName ),
721- sql .EscapeName (this .migrationContext .OriginalTableName ),
722- )
723- this .migrationContext .Log .Infof ("Locking %s.%s" ,
724- sql .EscapeName (this .migrationContext .DatabaseName ),
725- sql .EscapeName (this .migrationContext .OriginalTableName ),
726- )
717+ // lockTable places a write lock on the specific table
718+ func (this * Applier ) lockTable (databaseName , tableName string ) error {
719+ query := fmt .Sprintf (`lock /* gh-ost */ tables %s.%s write` , databaseName , tableName )
720+ this .migrationContext .Log .Infof ("Locking %s.%s" , databaseName , tableName )
727721 this .migrationContext .LockTablesStartTime = time .Now ()
728722 if _ , err := sqlutils .ExecNoPrepare (this .singletonDB , query ); err != nil {
729723 return err
730724 }
731- this .migrationContext .Log .Infof ("Table locked" )
725+ this .migrationContext .Log .Infof ("Table %s.%s locked" , databaseName , tableName )
732726 return nil
733727}
734728
729+ // LockOriginalTable places a write lock on the original table
730+ func (this * Applier ) LockOriginalTable () error {
731+ return this .lockTable (this .migrationContext .DatabaseName , this .migrationContext .OriginalTableName )
732+ }
733+
734+ // LockGhostTable places a write lock on the ghost table
735+ func (this * Applier ) LockGhostTable () error {
736+ return this .lockTable (this .migrationContext .DatabaseName , this .migrationContext .GetGhostTableName ())
737+ }
738+
735739// UnlockTables makes tea. No wait, it unlocks tables.
736740func (this * Applier ) UnlockTables () error {
737741 query := `unlock /* gh-ost */ tables`
@@ -1033,7 +1037,7 @@ func (this *Applier) AtomicCutOverMagicLock(sessionIdChan chan int64, tableLocke
10331037
10341038 tableLockTimeoutSeconds := this .migrationContext .CutOverLockTimeoutSeconds * 2
10351039 this .migrationContext .Log .Infof ("Setting LOCK timeout as %d seconds" , tableLockTimeoutSeconds )
1036- query = fmt .Sprintf (`set /* gh-ost */ session lock_wait_timeout: =%d` , tableLockTimeoutSeconds )
1040+ query = fmt .Sprintf (`set /* gh-ost */ session lock_wait_timeout=%d` , tableLockTimeoutSeconds )
10371041 if _ , err := tx .Exec (query ); err != nil {
10381042 tableLocked <- err
10391043 return err
@@ -1108,25 +1112,31 @@ func (this *Applier) AtomicCutOverMagicLock(sessionIdChan chan int64, tableLocke
11081112 return nil
11091113}
11101114
1111- // AtomicCutoverRename
1112- func (this * Applier ) AtomicCutoverRename (sessionIdChan chan int64 , tablesRenamed chan <- error ) error {
1113- tx , err := this .db .Begin ()
1115+ func (this * Applier ) atomicCutoverRename (db * gosql.DB , sessionIdChan chan int64 , tablesRenamed chan <- error ) error {
1116+ tx , err := db .Begin ()
11141117 if err != nil {
11151118 return err
11161119 }
11171120 defer func () {
11181121 tx .Rollback ()
1119- sessionIdChan <- - 1
1120- tablesRenamed <- fmt .Errorf ("Unexpected error in AtomicCutoverRename(), injected to release blocking channel reads" )
1122+ if sessionIdChan != nil {
1123+ sessionIdChan <- - 1
1124+ }
1125+ if tablesRenamed != nil {
1126+ tablesRenamed <- fmt .Errorf ("Unexpected error in AtomicCutoverRename(), injected to release blocking channel reads" )
1127+ }
11211128 }()
1122- var sessionId int64
1123- if err := tx .QueryRow (`select /* gh-ost */ connection_id()` ).Scan (& sessionId ); err != nil {
1124- return err
1129+
1130+ if sessionIdChan != nil {
1131+ var sessionId int64
1132+ if err := tx .QueryRow (`select /* gh-ost */ connection_id()` ).Scan (& sessionId ); err != nil {
1133+ return err
1134+ }
1135+ sessionIdChan <- sessionId
11251136 }
1126- sessionIdChan <- sessionId
11271137
11281138 this .migrationContext .Log .Infof ("Setting RENAME timeout as %d seconds" , this .migrationContext .CutOverLockTimeoutSeconds )
1129- query := fmt .Sprintf (`set /* gh-ost */ session lock_wait_timeout: =%d` , this .migrationContext .CutOverLockTimeoutSeconds )
1139+ query := fmt .Sprintf (`set /* gh-ost */ session lock_wait_timeout=%d` , this .migrationContext .CutOverLockTimeoutSeconds )
11301140 if _ , err := tx .Exec (query ); err != nil {
11311141 return err
11321142 }
@@ -1143,14 +1153,28 @@ func (this *Applier) AtomicCutoverRename(sessionIdChan chan int64, tablesRenamed
11431153 )
11441154 this .migrationContext .Log .Infof ("Issuing and expecting this to block: %s" , query )
11451155 if _ , err := tx .Exec (query ); err != nil {
1146- tablesRenamed <- err
1156+ if tablesRenamed != nil {
1157+ tablesRenamed <- err
1158+ }
11471159 return this .migrationContext .Log .Errore (err )
11481160 }
1149- tablesRenamed <- nil
1161+ if tablesRenamed != nil {
1162+ tablesRenamed <- nil
1163+ }
11501164 this .migrationContext .Log .Infof ("Tables renamed" )
11511165 return nil
11521166}
11531167
1168+ // AtomicCutoverRename renames tables for atomic cut over in non lock session
1169+ func (this * Applier ) AtomicCutoverRename (sessionIdChan chan int64 , tablesRenamed chan <- error ) error {
1170+ return this .atomicCutoverRename (this .db , sessionIdChan , tablesRenamed )
1171+ }
1172+
1173+ // AtomicCutoverRenameWithLock renames tables for atomic cut over in the lock session
1174+ func (this * Applier ) AtomicCutoverRenameWithLock () error {
1175+ return this .atomicCutoverRename (this .singletonDB , nil , nil )
1176+ }
1177+
11541178func (this * Applier ) ShowStatusVariable (variableName string ) (result int64 , err error ) {
11551179 query := fmt .Sprintf (`show /* gh-ost */ global status like '%s'` , variableName )
11561180 if err := this .db .QueryRow (query ).Scan (& variableName , & result ); err != nil {
0 commit comments