Skip to content

Commit

Permalink
Merge pull request #75 from github/dynamic-throttle-control-replicas
Browse files Browse the repository at this point in the history
supporting interactive command throttle-control-replicas
  • Loading branch information
Shlomi Noach authored Jun 20, 2016
2 parents 94c8812 + 2c8121c commit 0200cc9
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 13 deletions.
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
#
#
RELEASE_VERSION="0.9.5"
RELEASE_VERSION="0.9.6"

buildpath=/tmp/gh-ost
target=gh-ost
Expand Down
9 changes: 7 additions & 2 deletions doc/interactive-commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,16 @@ 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 status summary of migration progress and configuration
- `throttle`: force migration suspend
- `no-throttle`: cancel forced suspension (though other throttling reasons may still apply)
replication lag on to determine throttling
- `chunk-size=<newsize>`: modify the `chunk-size`; applies on next running copy-iteration
- `max-load=<max-load-thresholds>`: modify the `max-load` config; applies on next running copy-iteration
The `max-load` format must be: `some_status=<numeric-threshold>[,some_status=<numeric-threshold>...]`. For example: `Threads_running=50,threads_connected=1000`, and you would then write/echo `max-load=Threads_running=50,threads_connected=1000` to the socket.
- `critical-load=<load>`: change critical load setting (exceeding given thresholds causes panic and abort)
- `throttle-query`: change throttle query
- `throttle-control-replicas`: change list of throttle-control replicas, these are replicas `gh-ost` will cehck
- `throttle`: force migration suspend
- `no-throttle`: cancel forced suspension (though other throttling reasons may still apply)
- `panic`: immediately panic and abort operation

### Examples

Expand Down
25 changes: 25 additions & 0 deletions go/base/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ func (this *MigrationContext) GetGhostTableName() string {

// GetOldTableName generates the name of the "old" table, into which the original table is renamed.
func (this *MigrationContext) GetOldTableName() string {
// if this.TestOnReplica {
// return fmt.Sprintf("_%s_tst", this.OriginalTableName)
// }
return fmt.Sprintf("_%s_old", this.OriginalTableName)
}

Expand Down Expand Up @@ -361,6 +364,28 @@ func (this *MigrationContext) ReadCriticalLoad(criticalLoadList string) error {
return nil
}

func (this *MigrationContext) GetThrottleControlReplicaKeys() *mysql.InstanceKeyMap {
this.throttleMutex.Lock()
defer this.throttleMutex.Unlock()

keys := mysql.NewInstanceKeyMap()
keys.AddKeys(this.ThrottleControlReplicaKeys.GetInstanceKeys())
return keys
}

func (this *MigrationContext) ReadThrottleControlReplicaKeys(throttleControlReplicas string) error {
keys := mysql.NewInstanceKeyMap()
if err := keys.ReadCommaDelimitedList(throttleControlReplicas); err != nil {
return err
}

this.throttleMutex.Lock()
defer this.throttleMutex.Unlock()

this.ThrottleControlReplicaKeys = keys
return nil
}

// ApplyCredentials sorts out the credentials between the config file and the CLI flags
func (this *MigrationContext) ApplyCredentials() {
this.configMutex.Lock()
Expand Down
2 changes: 1 addition & 1 deletion go/cmd/gh-ost/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func main() {
if err := migrationContext.ReadConfigFile(); err != nil {
log.Fatale(err)
}
if err := migrationContext.ThrottleControlReplicaKeys.ReadCommaDelimitedList(*throttleControlReplicas); err != nil {
if err := migrationContext.ReadThrottleControlReplicaKeys(*throttleControlReplicas); err != nil {
log.Fatale(err)
}
if err := migrationContext.ReadMaxLoad(*maxLoad); err != nil {
Expand Down
28 changes: 19 additions & 9 deletions go/logic/migrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -659,15 +659,16 @@ func (this *Migrator) onServerCommand(command string, writer *bufio.Writer) (err
case "help":
{
fmt.Fprintln(writer, `available commands:
status # Print a status message
chunk-size=<newsize> # Set a new chunk-size
critical-load=<load> # Set a new set of max-load thresholds
max-load=<load> # Set a new set of max-load thresholds
throttle-query=<query> # Set a new throttle-query
throttle # Force throttling
no-throttle # End forced throttling (other throttling may still apply)
panic # panic and quit without cleanup
help # This message
status # Print a status message
chunk-size=<newsize> # Set a new chunk-size
critical-load=<load> # Set a new set of max-load thresholds
max-load=<load> # Set a new set of max-load thresholds
throttle-query=<query> # Set a new throttle-query
throttle-control-replicas=<replicas> #
throttle # Force throttling
no-throttle # End forced throttling (other throttling may still apply)
panic # panic and quit without cleanup
help # This message
`)
}
case "info", "status":
Expand Down Expand Up @@ -703,6 +704,15 @@ help # This message
this.migrationContext.SetThrottleQuery(arg)
this.printStatus(ForcePrintStatusAndHint, writer)
}
case "throttle-control-replicas":
{
if err := this.migrationContext.ReadThrottleControlReplicaKeys(arg); err != nil {
fmt.Fprintf(writer, "%s\n", err.Error())
return log.Errore(err)
}
fmt.Fprintf(writer, "%s\n", this.migrationContext.GetThrottleControlReplicaKeys().ToCommaDelimitedList())
this.printStatus(ForcePrintStatusAndHint, writer)
}
case "throttle", "pause", "suspend":
{
atomic.StoreInt64(&this.migrationContext.ThrottleCommandedByUser, 1)
Expand Down

0 comments on commit 0200cc9

Please sign in to comment.