@@ -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 {
@@ -723,24 +723,28 @@ func (this *Applier) ApplyIterationInsertQuery() (chunkSize int64, rowsAffected
723
723
return chunkSize , rowsAffected , duration , nil
724
724
}
725
725
726
- // LockOriginalTable places a write lock on the original table
727
- func (this * Applier ) LockOriginalTable () error {
728
- query := fmt .Sprintf (`lock /* gh-ost */ tables %s.%s write` ,
729
- sql .EscapeName (this .migrationContext .DatabaseName ),
730
- sql .EscapeName (this .migrationContext .OriginalTableName ),
731
- )
732
- this .migrationContext .Log .Infof ("Locking %s.%s" ,
733
- sql .EscapeName (this .migrationContext .DatabaseName ),
734
- sql .EscapeName (this .migrationContext .OriginalTableName ),
735
- )
726
+ // lockTable places a write lock on the specific table
727
+ func (this * Applier ) lockTable (databaseName , tableName string ) error {
728
+ query := fmt .Sprintf (`lock /* gh-ost */ tables %s.%s write` , databaseName , tableName )
729
+ this .migrationContext .Log .Infof ("Locking %s.%s" , databaseName , tableName )
736
730
this .migrationContext .LockTablesStartTime = time .Now ()
737
731
if _ , err := sqlutils .ExecNoPrepare (this .singletonDB , query ); err != nil {
738
732
return err
739
733
}
740
- this .migrationContext .Log .Infof ("Table locked" )
734
+ this .migrationContext .Log .Infof ("Table %s.%s locked" , databaseName , tableName )
741
735
return nil
742
736
}
743
737
738
+ // LockOriginalTable places a write lock on the original table
739
+ func (this * Applier ) LockOriginalTable () error {
740
+ return this .lockTable (this .migrationContext .DatabaseName , this .migrationContext .OriginalTableName )
741
+ }
742
+
743
+ // LockGhostTable places a write lock on the ghost table
744
+ func (this * Applier ) LockGhostTable () error {
745
+ return this .lockTable (this .migrationContext .DatabaseName , this .migrationContext .GetGhostTableName ())
746
+ }
747
+
744
748
// UnlockTables makes tea. No wait, it unlocks tables.
745
749
func (this * Applier ) UnlockTables () error {
746
750
query := `unlock /* gh-ost */ tables`
@@ -1046,7 +1050,7 @@ func (this *Applier) AtomicCutOverMagicLock(sessionIdChan chan int64, tableLocke
1046
1050
1047
1051
tableLockTimeoutSeconds := this .migrationContext .CutOverLockTimeoutSeconds * 2
1048
1052
this .migrationContext .Log .Infof ("Setting LOCK timeout as %d seconds" , tableLockTimeoutSeconds )
1049
- query = fmt .Sprintf (`set /* gh-ost */ session lock_wait_timeout: =%d` , tableLockTimeoutSeconds )
1053
+ query = fmt .Sprintf (`set /* gh-ost */ session lock_wait_timeout=%d` , tableLockTimeoutSeconds )
1050
1054
if _ , err := tx .Exec (query ); err != nil {
1051
1055
tableLocked <- err
1052
1056
return err
@@ -1121,25 +1125,31 @@ func (this *Applier) AtomicCutOverMagicLock(sessionIdChan chan int64, tableLocke
1121
1125
return nil
1122
1126
}
1123
1127
1124
- // AtomicCutoverRename
1125
- func (this * Applier ) AtomicCutoverRename (sessionIdChan chan int64 , tablesRenamed chan <- error ) error {
1126
- tx , err := this .db .Begin ()
1128
+ func (this * Applier ) atomicCutoverRename (db * gosql.DB , sessionIdChan chan int64 , tablesRenamed chan <- error ) error {
1129
+ tx , err := db .Begin ()
1127
1130
if err != nil {
1128
1131
return err
1129
1132
}
1130
1133
defer func () {
1131
1134
tx .Rollback ()
1132
- sessionIdChan <- - 1
1133
- tablesRenamed <- fmt .Errorf ("Unexpected error in AtomicCutoverRename(), injected to release blocking channel reads" )
1135
+ if sessionIdChan != nil {
1136
+ sessionIdChan <- - 1
1137
+ }
1138
+ if tablesRenamed != nil {
1139
+ tablesRenamed <- fmt .Errorf ("Unexpected error in AtomicCutoverRename(), injected to release blocking channel reads" )
1140
+ }
1134
1141
}()
1135
- var sessionId int64
1136
- if err := tx .QueryRow (`select /* gh-ost */ connection_id()` ).Scan (& sessionId ); err != nil {
1137
- return err
1142
+
1143
+ if sessionIdChan != nil {
1144
+ var sessionId int64
1145
+ if err := tx .QueryRow (`select /* gh-ost */ connection_id()` ).Scan (& sessionId ); err != nil {
1146
+ return err
1147
+ }
1148
+ sessionIdChan <- sessionId
1138
1149
}
1139
- sessionIdChan <- sessionId
1140
1150
1141
1151
this .migrationContext .Log .Infof ("Setting RENAME timeout as %d seconds" , this .migrationContext .CutOverLockTimeoutSeconds )
1142
- query := fmt .Sprintf (`set /* gh-ost */ session lock_wait_timeout: =%d` , this .migrationContext .CutOverLockTimeoutSeconds )
1152
+ query := fmt .Sprintf (`set /* gh-ost */ session lock_wait_timeout=%d` , this .migrationContext .CutOverLockTimeoutSeconds )
1143
1153
if _ , err := tx .Exec (query ); err != nil {
1144
1154
return err
1145
1155
}
@@ -1156,14 +1166,28 @@ func (this *Applier) AtomicCutoverRename(sessionIdChan chan int64, tablesRenamed
1156
1166
)
1157
1167
this .migrationContext .Log .Infof ("Issuing and expecting this to block: %s" , query )
1158
1168
if _ , err := tx .Exec (query ); err != nil {
1159
- tablesRenamed <- err
1169
+ if tablesRenamed != nil {
1170
+ tablesRenamed <- err
1171
+ }
1160
1172
return this .migrationContext .Log .Errore (err )
1161
1173
}
1162
- tablesRenamed <- nil
1174
+ if tablesRenamed != nil {
1175
+ tablesRenamed <- nil
1176
+ }
1163
1177
this .migrationContext .Log .Infof ("Tables renamed" )
1164
1178
return nil
1165
1179
}
1166
1180
1181
+ // AtomicCutoverRename renames tables for atomic cut over in non lock session
1182
+ func (this * Applier ) AtomicCutoverRename (sessionIdChan chan int64 , tablesRenamed chan <- error ) error {
1183
+ return this .atomicCutoverRename (this .db , sessionIdChan , tablesRenamed )
1184
+ }
1185
+
1186
+ // AtomicCutoverRenameWithLock renames tables for atomic cut over in the lock session
1187
+ func (this * Applier ) AtomicCutoverRenameWithLock () error {
1188
+ return this .atomicCutoverRename (this .singletonDB , nil , nil )
1189
+ }
1190
+
1167
1191
func (this * Applier ) ShowStatusVariable (variableName string ) (result int64 , err error ) {
1168
1192
query := fmt .Sprintf (`show /* gh-ost */ global status like '%s'` , variableName )
1169
1193
if err := this .db .QueryRow (query ).Scan (& variableName , & result ); err != nil {
0 commit comments