@@ -100,7 +100,7 @@ func (this *Applier) InitDBConnections() (err error) {
100
100
if err := this .validateAndReadGlobalVariables (); err != nil {
101
101
return err
102
102
}
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 {
104
104
if impliedKey , err := mysql .GetInstanceKey (this .db ); err != nil {
105
105
return err
106
106
} else {
@@ -773,24 +773,28 @@ func (this *Applier) ApplyIterationInsertQuery() (chunkSize int64, rowsAffected
773
773
return chunkSize , rowsAffected , duration , nil
774
774
}
775
775
776
- // LockOriginalTable places a write lock on the original table
777
- func (this * Applier ) LockOriginalTable () error {
778
- query := fmt .Sprintf (`lock /* gh-ost */ tables %s.%s write` ,
779
- sql .EscapeName (this .migrationContext .DatabaseName ),
780
- sql .EscapeName (this .migrationContext .OriginalTableName ),
781
- )
782
- this .migrationContext .Log .Infof ("Locking %s.%s" ,
783
- sql .EscapeName (this .migrationContext .DatabaseName ),
784
- sql .EscapeName (this .migrationContext .OriginalTableName ),
785
- )
776
+ // lockTable places a write lock on the specific table
777
+ func (this * Applier ) lockTable (databaseName , tableName string ) error {
778
+ query := fmt .Sprintf (`lock /* gh-ost */ tables %s.%s write` , databaseName , tableName )
779
+ this .migrationContext .Log .Infof ("Locking %s.%s" , databaseName , tableName )
786
780
this .migrationContext .LockTablesStartTime = time .Now ()
787
781
if _ , err := sqlutils .ExecNoPrepare (this .singletonDB , query ); err != nil {
788
782
return err
789
783
}
790
- this .migrationContext .Log .Infof ("Table locked" )
784
+ this .migrationContext .Log .Infof ("Table %s.%s locked" , databaseName , tableName )
791
785
return nil
792
786
}
793
787
788
+ // LockOriginalTable places a write lock on the original table
789
+ func (this * Applier ) LockOriginalTable () error {
790
+ return this .lockTable (this .migrationContext .DatabaseName , this .migrationContext .OriginalTableName )
791
+ }
792
+
793
+ // LockGhostTable places a write lock on the ghost table
794
+ func (this * Applier ) LockGhostTable () error {
795
+ return this .lockTable (this .migrationContext .DatabaseName , this .migrationContext .GetGhostTableName ())
796
+ }
797
+
794
798
// UnlockTables makes tea. No wait, it unlocks tables.
795
799
func (this * Applier ) UnlockTables () error {
796
800
query := `unlock /* gh-ost */ tables`
@@ -1096,7 +1100,7 @@ func (this *Applier) AtomicCutOverMagicLock(sessionIdChan chan int64, tableLocke
1096
1100
1097
1101
tableLockTimeoutSeconds := this .migrationContext .CutOverLockTimeoutSeconds * 2
1098
1102
this .migrationContext .Log .Infof ("Setting LOCK timeout as %d seconds" , tableLockTimeoutSeconds )
1099
- query = fmt .Sprintf (`set /* gh-ost */ session lock_wait_timeout: =%d` , tableLockTimeoutSeconds )
1103
+ query = fmt .Sprintf (`set /* gh-ost */ session lock_wait_timeout=%d` , tableLockTimeoutSeconds )
1100
1104
if _ , err := tx .Exec (query ); err != nil {
1101
1105
tableLocked <- err
1102
1106
return err
@@ -1171,25 +1175,31 @@ func (this *Applier) AtomicCutOverMagicLock(sessionIdChan chan int64, tableLocke
1171
1175
return nil
1172
1176
}
1173
1177
1174
- // AtomicCutoverRename
1175
- func (this * Applier ) AtomicCutoverRename (sessionIdChan chan int64 , tablesRenamed chan <- error ) error {
1176
- tx , err := this .db .Begin ()
1178
+ func (this * Applier ) atomicCutoverRename (db * gosql.DB , sessionIdChan chan int64 , tablesRenamed chan <- error ) error {
1179
+ tx , err := db .Begin ()
1177
1180
if err != nil {
1178
1181
return err
1179
1182
}
1180
1183
defer func () {
1181
1184
tx .Rollback ()
1182
- sessionIdChan <- - 1
1183
- tablesRenamed <- fmt .Errorf ("Unexpected error in AtomicCutoverRename(), injected to release blocking channel reads" )
1185
+ if sessionIdChan != nil {
1186
+ sessionIdChan <- - 1
1187
+ }
1188
+ if tablesRenamed != nil {
1189
+ tablesRenamed <- fmt .Errorf ("Unexpected error in AtomicCutoverRename(), injected to release blocking channel reads" )
1190
+ }
1184
1191
}()
1185
- var sessionId int64
1186
- if err := tx .QueryRow (`select /* gh-ost */ connection_id()` ).Scan (& sessionId ); err != nil {
1187
- return err
1192
+
1193
+ if sessionIdChan != nil {
1194
+ var sessionId int64
1195
+ if err := tx .QueryRow (`select /* gh-ost */ connection_id()` ).Scan (& sessionId ); err != nil {
1196
+ return err
1197
+ }
1198
+ sessionIdChan <- sessionId
1188
1199
}
1189
- sessionIdChan <- sessionId
1190
1200
1191
1201
this .migrationContext .Log .Infof ("Setting RENAME timeout as %d seconds" , this .migrationContext .CutOverLockTimeoutSeconds )
1192
- query := fmt .Sprintf (`set /* gh-ost */ session lock_wait_timeout: =%d` , this .migrationContext .CutOverLockTimeoutSeconds )
1202
+ query := fmt .Sprintf (`set /* gh-ost */ session lock_wait_timeout=%d` , this .migrationContext .CutOverLockTimeoutSeconds )
1193
1203
if _ , err := tx .Exec (query ); err != nil {
1194
1204
return err
1195
1205
}
@@ -1206,14 +1216,28 @@ func (this *Applier) AtomicCutoverRename(sessionIdChan chan int64, tablesRenamed
1206
1216
)
1207
1217
this .migrationContext .Log .Infof ("Issuing and expecting this to block: %s" , query )
1208
1218
if _ , err := tx .Exec (query ); err != nil {
1209
- tablesRenamed <- err
1219
+ if tablesRenamed != nil {
1220
+ tablesRenamed <- err
1221
+ }
1210
1222
return this .migrationContext .Log .Errore (err )
1211
1223
}
1212
- tablesRenamed <- nil
1224
+ if tablesRenamed != nil {
1225
+ tablesRenamed <- nil
1226
+ }
1213
1227
this .migrationContext .Log .Infof ("Tables renamed" )
1214
1228
return nil
1215
1229
}
1216
1230
1231
+ // AtomicCutoverRename renames tables for atomic cut over in non lock session
1232
+ func (this * Applier ) AtomicCutoverRename (sessionIdChan chan int64 , tablesRenamed chan <- error ) error {
1233
+ return this .atomicCutoverRename (this .db , sessionIdChan , tablesRenamed )
1234
+ }
1235
+
1236
+ // AtomicCutoverRenameWithLock renames tables for atomic cut over in the lock session
1237
+ func (this * Applier ) AtomicCutoverRenameWithLock () error {
1238
+ return this .atomicCutoverRename (this .singletonDB , nil , nil )
1239
+ }
1240
+
1217
1241
func (this * Applier ) ShowStatusVariable (variableName string ) (result int64 , err error ) {
1218
1242
query := fmt .Sprintf (`show /* gh-ost */ global status like '%s'` , variableName )
1219
1243
if err := this .db .QueryRow (query ).Scan (& variableName , & result ); err != nil {
0 commit comments