@@ -192,6 +192,33 @@ func (srv *Server) onServerCommand(command string, writer *bufio.Writer) (err er
192192 return srv .migrationContext .Log .Errore (err )
193193}
194194
195+ // commandArgMatchesMigration reports whether a table-name argument supplied with
196+ // an interactive command refers to this migration. The argument is optional and
197+ // acts as a courtesy safety check, so an operator who is connected to the wrong
198+ // gh-ost socket is rejected. In standard mode it must equal the single migrated
199+ // table; in move-tables mode it may be any one of the migrated tables.
200+ func (srv * Server ) commandArgMatchesMigration (arg string ) bool {
201+ if srv .migrationContext .IsMoveTablesMode () {
202+ for _ , tableName := range srv .migrationContext .MoveTables .TableNames {
203+ if arg == tableName {
204+ return true
205+ }
206+ }
207+ return false
208+ }
209+ return arg == srv .migrationContext .OriginalTableName
210+ }
211+
212+ // migrationTargetDescription returns a human-readable description of the migrated
213+ // table(s), used in interactive-command messages. In move-tables mode it is the
214+ // comma-joined list of migrated tables; otherwise the single table name.
215+ func (srv * Server ) migrationTargetDescription () string {
216+ if srv .migrationContext .IsMoveTablesMode () {
217+ return strings .Join (srv .migrationContext .MoveTables .TableNames , "," )
218+ }
219+ return srv .migrationContext .OriginalTableName
220+ }
221+
195222// applyServerCommand parses and executes commands by user
196223func (srv * Server ) applyServerCommand (command string , writer * bufio.Writer ) (printStatusRule PrintStatusRule , err error ) {
197224 tokens := strings .SplitN (command , "=" , 2 )
@@ -387,9 +414,9 @@ help # This message
387414 }
388415 case "throttle" , "pause" , "suspend" :
389416 {
390- if arg != "" && arg != srv .migrationContext . OriginalTableName {
417+ if arg != "" && ! srv .commandArgMatchesMigration ( arg ) {
391418 // User explicitly provided table name. This is a courtesy protection mechanism
392- err := fmt .Errorf ("user commanded 'throttle' on %s, but migrated table is %s; ignoring request" , arg , srv .migrationContext . OriginalTableName )
419+ err := fmt .Errorf ("user commanded 'throttle' on %s, but migrated table is %s; ignoring request" , arg , srv .migrationTargetDescription () )
393420 return NoPrintStatusRule , err
394421 }
395422 atomic .StoreInt64 (& srv .migrationContext .ThrottleCommandedByUser , 1 )
@@ -398,9 +425,9 @@ help # This message
398425 }
399426 case "no-throttle" , "unthrottle" , "resume" , "continue" :
400427 {
401- if arg != "" && arg != srv .migrationContext . OriginalTableName {
428+ if arg != "" && ! srv .commandArgMatchesMigration ( arg ) {
402429 // User explicitly provided table name. This is a courtesy protection mechanism
403- err := fmt .Errorf ("user commanded 'no-throttle' on %s, but migrated table is %s; ignoring request" , arg , srv .migrationContext . OriginalTableName )
430+ err := fmt .Errorf ("user commanded 'no-throttle' on %s, but migrated table is %s; ignoring request" , arg , srv .migrationTargetDescription () )
404431 return NoPrintStatusRule , err
405432 }
406433 atomic .StoreInt64 (& srv .migrationContext .ThrottleCommandedByUser , 0 )
@@ -425,9 +452,9 @@ help # This message
425452 err := fmt .Errorf ("user commanded 'unpostpone' without specifying table name, but --force-named-cut-over is set" )
426453 return NoPrintStatusRule , err
427454 }
428- if arg != "" && arg != srv .migrationContext . OriginalTableName {
455+ if arg != "" && ! srv .commandArgMatchesMigration ( arg ) {
429456 // User explicitly provided table name. This is a courtesy protection mechanism
430- err := fmt .Errorf ("user commanded 'unpostpone' on %s, but migrated table is %s; ignoring request" , arg , srv .migrationContext . OriginalTableName )
457+ err := fmt .Errorf ("user commanded 'unpostpone' on %s, but migrated table is %s; ignoring request" , arg , srv .migrationTargetDescription () )
431458 return NoPrintStatusRule , err
432459 }
433460 if atomic .LoadInt64 (& srv .migrationContext .IsPostponingCutOver ) > 0 {
@@ -444,9 +471,9 @@ help # This message
444471 err := fmt .Errorf ("user commanded 'panic' without specifying table name, but --force-named-panic is set" )
445472 return NoPrintStatusRule , err
446473 }
447- if arg != "" && arg != srv .migrationContext . OriginalTableName {
474+ if arg != "" && ! srv .commandArgMatchesMigration ( arg ) {
448475 // User explicitly provided table name. This is a courtesy protection mechanism
449- err := fmt .Errorf ("user commanded 'panic' on %s, but migrated table is %s; ignoring request" , arg , srv .migrationContext . OriginalTableName )
476+ err := fmt .Errorf ("user commanded 'panic' on %s, but migrated table is %s; ignoring request" , arg , srv .migrationTargetDescription () )
450477 return NoPrintStatusRule , err
451478 }
452479 err := fmt .Errorf ("user commanded 'panic'. The migration will be aborted without cleanup. Please drop the gh-ost tables before trying again" )
0 commit comments