Skip to content

Commit 2c0aa36

Browse files
author
Shlomi Noach
authored
Merge pull request #695 from github/named-panic
Adding --force-named-panic option
2 parents 0e36857 + 766040d commit 2c0aa36

File tree

4 files changed

+29
-0
lines changed

4 files changed

+29
-0
lines changed

doc/command-line-flags.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,14 @@ While the ongoing estimated number of rows is still heuristic, it's almost exact
111111

112112
Without this parameter, migration is a _noop_: testing table creation and validity of migration, but not touching data.
113113

114+
### force-named-cut-over
115+
116+
If given, a `cut-over` command must name the migrated table, or else ignored.
117+
118+
### force-named-panic
119+
120+
If given, a `panic` command must name the migrated table, or else ignored.
121+
114122
### force-table-names
115123

116124
Table name prefix to be used on the temporary tables.

go/base/context.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ type MigrationContext struct {
128128
CutOverExponentialBackoff bool
129129
ExponentialBackoffMaxInterval int64
130130
ForceNamedCutOverCommand bool
131+
ForceNamedPanicCommand bool
131132
PanicFlagFile string
132133
HooksPath string
133134
HooksHintMessage string

go/cmd/gh-ost/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ func main() {
8888
flag.BoolVar(&migrationContext.TimestampOldTable, "timestamp-old-table", false, "Use a timestamp in old table name. This makes old table names unique and non conflicting cross migrations")
8989
cutOver := flag.String("cut-over", "atomic", "choose cut-over type (default|atomic, two-step)")
9090
flag.BoolVar(&migrationContext.ForceNamedCutOverCommand, "force-named-cut-over", false, "When true, the 'unpostpone|cut-over' interactive command must name the migrated table")
91+
flag.BoolVar(&migrationContext.ForceNamedPanicCommand, "force-named-panic", false, "When true, the 'panic' interactive command must name the migrated table")
9192

9293
flag.BoolVar(&migrationContext.SwitchToRowBinlogFormat, "switch-to-rbr", false, "let this tool automatically switch binary log format to 'ROW' on the replica, if needed. The format will NOT be switched back. I'm too scared to do that, and wish to protect you if you happen to execute another migration while this one is running")
9394
flag.BoolVar(&migrationContext.AssumeRBR, "assume-rbr", false, "set to 'true' when you know for certain your server uses 'ROW' binlog_format. gh-ost is unable to tell, event after reading binlog_format, whether the replication process does indeed use 'ROW', and restarts replication to be certain RBR setting is applied. Such operation requires SUPER privileges which you might not have. Setting this flag avoids restarting replication and you can proceed to use gh-ost without SUPER privileges")

go/logic/server.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,12 +292,22 @@ help # This message
292292
}
293293
case "throttle", "pause", "suspend":
294294
{
295+
if arg != "" && arg != this.migrationContext.OriginalTableName {
296+
// User explicitly provided table name. This is a courtesy protection mechanism
297+
err := fmt.Errorf("User commanded 'throttle' on %s, but migrated table is %s; ignoring request.", arg, this.migrationContext.OriginalTableName)
298+
return NoPrintStatusRule, err
299+
}
295300
atomic.StoreInt64(&this.migrationContext.ThrottleCommandedByUser, 1)
296301
fmt.Fprintf(writer, throttleHint)
297302
return ForcePrintStatusAndHintRule, nil
298303
}
299304
case "no-throttle", "unthrottle", "resume", "continue":
300305
{
306+
if arg != "" && arg != this.migrationContext.OriginalTableName {
307+
// User explicitly provided table name. This is a courtesy protection mechanism
308+
err := fmt.Errorf("User commanded 'no-throttle' on %s, but migrated table is %s; ignoring request.", arg, this.migrationContext.OriginalTableName)
309+
return NoPrintStatusRule, err
310+
}
301311
atomic.StoreInt64(&this.migrationContext.ThrottleCommandedByUser, 0)
302312
return ForcePrintStatusAndHintRule, nil
303313
}
@@ -322,6 +332,15 @@ help # This message
322332
}
323333
case "panic":
324334
{
335+
if arg == "" && this.migrationContext.ForceNamedPanicCommand {
336+
err := fmt.Errorf("User commanded 'panic' without specifying table name, but --force-named-panic is set")
337+
return NoPrintStatusRule, err
338+
}
339+
if arg != "" && arg != this.migrationContext.OriginalTableName {
340+
// User explicitly provided table name. This is a courtesy protection mechanism
341+
err := fmt.Errorf("User commanded 'panic' on %s, but migrated table is %s; ignoring request.", arg, this.migrationContext.OriginalTableName)
342+
return NoPrintStatusRule, err
343+
}
325344
err := fmt.Errorf("User commanded 'panic'. I will now panic, without cleanup. PANIC!")
326345
this.migrationContext.PanicAbort <- err
327346
return NoPrintStatusRule, err

0 commit comments

Comments
 (0)