Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new command line flag: postpone-shutdown-flag-file, new server command; 'state' #7

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions doc/command-line-flags.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@ Indicate a file name, such that the final [cut-over](cut-over.md) step does not
When this flag is set, `gh-ost` expects the file to exist on startup, or else tries to create it. `gh-ost` exits with error if the file does not exist and `gh-ost` is unable to create it.
With this flag set, the migration will cut-over upon deletion of the file or upon `cut-over` [interactive command](interactive-commands.md).

### postpone-shutdown-flag-file

If indicated file exists, and assuming execution is successful, `gh-ost` will wait after cut-over, and after running the success hooks, instead of exiting. This can be useful in state based environments where we may wish to ask `gh-ost` wat the state of the migration is, as opposed to assuming it reports the state via hooks. This gives a controller/operator the chance to communicate to `gh-ost` and confirm that the migration is successful. See also the `state` server command.

### replica-server-id

Defaults to 99999. If you run multiple migrations then you must provide a different, unique `--replica-server-id` for each `gh-ost` process.
Expand Down
1 change: 1 addition & 0 deletions doc/interactive-commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Both interfaces may serve at the same time. Both respond to simple text command,
- `help`: shows a brief list of available commands
- `status`: returns a detailed status summary of migration progress and configuration
- `sup`: returns a brief status summary of migration progress
- `state`: returns `Running` or `Complete`. For the latter, see `--postpone-shutdown-flag-file`
- `coordinates`: returns recent (though not exactly up to date) binary log coordinates of the inspected server
- `chunk-size=<newsize>`: modify the `chunk-size`; applies on next running copy-iteration
- `dml-batch-size=<newsize>`: modify the `dml-batch-size`; applies on next applying of binary log events
Expand Down
16 changes: 16 additions & 0 deletions go/base/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ const (

type CutOver int

type MigrationState string

const (
MigrationStateRunning MigrationState = "Running"
MigrationStateComplete MigrationState = "Complete"
MigrationStateFailed MigrationState = "Failed"
)

const (
CutOverAtomic CutOver = iota
CutOverTwoStep
Expand Down Expand Up @@ -129,6 +137,7 @@ type MigrationContext struct {
CriticalLoadIntervalMilliseconds int64
CriticalLoadHibernateSeconds int64
PostponeCutOverFlagFile string
PostponeShutdownFlagFile string
CutOverLockTimeoutSeconds int64
CutOverExponentialBackoff bool
ExponentialBackoffMaxInterval int64
Expand Down Expand Up @@ -729,6 +738,13 @@ func (this *MigrationContext) AddThrottleControlReplicaKey(key mysql.InstanceKey
return nil
}

func (this *MigrationContext) GetMigrationState() MigrationState {
if atomic.LoadInt64(&this.CutOverCompleteFlag) > 0 {
return MigrationStateComplete
}
return MigrationStateRunning
}

// ApplyCredentials sorts out the credentials between the config file and the CLI flags
func (this *MigrationContext) ApplyCredentials() {
this.configMutex.Lock()
Expand Down
1 change: 1 addition & 0 deletions go/cmd/gh-ost/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ func main() {
flag.StringVar(&migrationContext.ThrottleFlagFile, "throttle-flag-file", "", "operation pauses when this file exists; hint: use a file that is specific to the table being altered")
flag.StringVar(&migrationContext.ThrottleAdditionalFlagFile, "throttle-additional-flag-file", "/tmp/gh-ost.throttle", "operation pauses when this file exists; hint: keep default, use for throttling multiple gh-ost operations")
flag.StringVar(&migrationContext.PostponeCutOverFlagFile, "postpone-cut-over-flag-file", "", "while this file exists, migration will postpone the final stage of swapping tables, and will keep on syncing the ghost table. Cut-over/swapping would be ready to perform the moment the file is deleted.")
flag.StringVar(&migrationContext.PostponeShutdownFlagFile, "postpone-shutdown-flag-file", "", "while this file exists gh-ost will not terminate. This does not postpone cut-over. Use case: be able to advertise that migration is complete.")
flag.StringVar(&migrationContext.PanicFlagFile, "panic-flag-file", "", "when this file is created, gh-ost will immediately terminate, without cleanup")

flag.BoolVar(&migrationContext.DropServeSocket, "initially-drop-socket-file", false, "Should gh-ost forcibly delete an existing socket file. Be careful: this might drop the socket file of a running migration!")
Expand Down
12 changes: 12 additions & 0 deletions go/logic/migrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,18 @@ func (this *Migrator) Migrate() (err error) {
if err := this.hooksExecutor.onSuccess(); err != nil {
return err
}
this.sleepWhileTrue(
func() (bool, error) {
if this.migrationContext.PostponeShutdownFlagFile == "" {
return false, nil
}
if base.FileExists(this.migrationContext.PostponeShutdownFlagFile) {
// Postpone file defined and exists!
return true, nil
}
return false, nil
},
)
this.migrationContext.Log.Infof("Done migrating %s.%s", sql.EscapeName(this.migrationContext.DatabaseName), sql.EscapeName(this.migrationContext.OriginalTableName))
return nil
}
Expand Down
6 changes: 6 additions & 0 deletions go/logic/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ func (this *Server) applyServerCommand(command string, writer *bufio.Writer) (pr
fmt.Fprint(writer, `available commands:
status # Print a detailed status message
sup # Print a short status message
state # Print Running|Complete
coordinates # Print the currently inspected coordinates
chunk-size=<newsize> # Set a new chunk-size
dml-batch-size=<newsize> # Set a new dml-batch-size
Expand All @@ -169,6 +170,11 @@ help # This message
return ForcePrintStatusOnlyRule, nil
case "info", "status":
return ForcePrintStatusAndHintRule, nil
case "state":
{
fmt.Fprintf(writer, "%+v\n", this.migrationContext.GetMigrationState())
return NoPrintStatusRule, nil
}
case "coordinates":
{
if argIsQuestion || arg == "" {
Expand Down