Skip to content

Commit 185da16

Browse files
author
Shlomi Noach
authored
Merge pull request #363 from github/interactive-command-question
Interactive commands, question argument for querying staus
2 parents 3150726 + 6ecf7cc commit 185da16

4 files changed

Lines changed: 51 additions & 5 deletions

File tree

doc/interactive-commands.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ Both interfaces may serve at the same time. Both respond to simple text command,
2626
- The `critical-load` format must be: `some_status=<numeric-threshold>[,some_status=<numeric-threshold>...]`'
2727
- For example: `Threads_running=1000,threads_connected=5000`, and you would then write/echo `critical-load=Threads_running=1000,threads_connected=5000` to the socket.
2828
- `nice-ratio=<ratio>`: change _nice_ ratio: 0 for aggressive (not nice, not sleeping), positive integer `n`:
29-
- For any `1ms` spent copying rows, spend `n*1ms` units of time sleeping.
30-
- Examples: assume a single rows chunk copy takes `100ms` to complete.
31-
- `nice-ratio=0.5` will cause `gh-ost` to sleep for `50ms` immediately following.
29+
- For any `1ms` spent copying rows, spend `n*1ms` units of time sleeping.
30+
- Examples: assume a single rows chunk copy takes `100ms` to complete.
31+
- `nice-ratio=0.5` will cause `gh-ost` to sleep for `50ms` immediately following.
3232
- `nice-ratio=1` will cause `gh-ost` to sleep for `100ms`, effectively doubling runtime
3333
- value of `2` will effectively triple the runtime; etc.
3434
- `throttle-query`: change throttle query
@@ -38,6 +38,10 @@ Both interfaces may serve at the same time. Both respond to simple text command,
3838
- `unpostpone`: at a time where `gh-ost` is postponing the [cut-over](cut-over.md) phase, instruct `gh-ost` to stop postponing and proceed immediately to cut-over.
3939
- `panic`: immediately panic and abort operation
4040

41+
### Querying for data
42+
43+
For commands that accept an argumetn as value, pass `?` (question mark) to _get_ current value rather than _set_ a new one.
44+
4145
### Examples
4246

4347
While migration is running:
@@ -63,6 +67,11 @@ $ echo "chunk-size=250" | nc -U /tmp/gh-ost.test.sample_data_0.sock
6367
# Serving on TCP port: 10001
6468
```
6569

70+
```shell
71+
$ echo "chunk-size=?" | nc -U /tmp/gh-ost.test.sample_data_0.sock
72+
250
73+
```
74+
6675
```shell
6776
$ echo throttle | nc -U /tmp/gh-ost.test.sample_data_0.sock
6877

go/logic/migrator.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,12 @@ func (this *Migrator) printMigrationStatusHint(writers ...io.Writer) {
761761
throttleQuery,
762762
))
763763
}
764+
if throttleControlReplicaKeys := this.migrationContext.GetThrottleControlReplicaKeys(); throttleControlReplicaKeys.Len() > 0 {
765+
fmt.Fprintln(w, fmt.Sprintf("# throttle-control-replicas count: %+v",
766+
throttleControlReplicaKeys.Len(),
767+
))
768+
}
769+
764770
if this.migrationContext.PostponeCutOverFlagFile != "" {
765771
setIndicator := ""
766772
if base.FileExists(this.migrationContext.PostponeCutOverFlagFile) {

go/logic/server.go

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ func (this *Server) applyServerCommand(command string, writer *bufio.Writer) (pr
126126
if len(tokens) > 1 {
127127
arg = strings.TrimSpace(tokens[1])
128128
}
129-
129+
argIsQuestion := (arg == "?")
130130
throttleHint := "# Note: you may only throttle for as long as your binary logs are not purged\n"
131131

132132
if err := this.hooksExecutor.onInteractiveCommand(command); err != nil {
@@ -152,6 +152,7 @@ no-throttle # End forced throttling (other throttling m
152152
unpostpone # Bail out a cut-over postpone; proceed to cut-over
153153
panic # panic and quit without cleanup
154154
help # This message
155+
- use '?' (question mark) as argument to get info rather than set. e.g. "max-load=?" will just print out current max-load.
155156
`)
156157
}
157158
case "sup":
@@ -160,6 +161,10 @@ help # This message
160161
return ForcePrintStatusAndHintRule, nil
161162
case "chunk-size":
162163
{
164+
if argIsQuestion {
165+
fmt.Fprintf(writer, "%+v\n", atomic.LoadInt64(&this.migrationContext.ChunkSize))
166+
return NoPrintStatusRule, nil
167+
}
163168
if chunkSize, err := strconv.Atoi(arg); err != nil {
164169
return NoPrintStatusRule, err
165170
} else {
@@ -169,6 +174,10 @@ help # This message
169174
}
170175
case "max-lag-millis":
171176
{
177+
if argIsQuestion {
178+
fmt.Fprintf(writer, "%+v\n", atomic.LoadInt64(&this.migrationContext.MaxLagMillisecondsThrottleThreshold))
179+
return NoPrintStatusRule, nil
180+
}
172181
if maxLagMillis, err := strconv.Atoi(arg); err != nil {
173182
return NoPrintStatusRule, err
174183
} else {
@@ -182,6 +191,10 @@ help # This message
182191
}
183192
case "nice-ratio":
184193
{
194+
if argIsQuestion {
195+
fmt.Fprintf(writer, "%+v\n", this.migrationContext.GetNiceRatio())
196+
return NoPrintStatusRule, nil
197+
}
185198
if niceRatio, err := strconv.ParseFloat(arg, 64); err != nil {
186199
return NoPrintStatusRule, err
187200
} else {
@@ -191,26 +204,44 @@ help # This message
191204
}
192205
case "max-load":
193206
{
207+
if argIsQuestion {
208+
maxLoad := this.migrationContext.GetMaxLoad()
209+
fmt.Fprintf(writer, "%s\n", maxLoad.String())
210+
return NoPrintStatusRule, nil
211+
}
194212
if err := this.migrationContext.ReadMaxLoad(arg); err != nil {
195213
return NoPrintStatusRule, err
196214
}
197215
return ForcePrintStatusAndHintRule, nil
198216
}
199217
case "critical-load":
200218
{
219+
if argIsQuestion {
220+
criticalLoad := this.migrationContext.GetCriticalLoad()
221+
fmt.Fprintf(writer, "%s\n", criticalLoad.String())
222+
return NoPrintStatusRule, nil
223+
}
201224
if err := this.migrationContext.ReadCriticalLoad(arg); err != nil {
202225
return NoPrintStatusRule, err
203226
}
204227
return ForcePrintStatusAndHintRule, nil
205228
}
206229
case "throttle-query":
207230
{
231+
if argIsQuestion {
232+
fmt.Fprintf(writer, "%+v\n", this.migrationContext.GetThrottleQuery())
233+
return NoPrintStatusRule, nil
234+
}
208235
this.migrationContext.SetThrottleQuery(arg)
209236
fmt.Fprintf(writer, throttleHint)
210237
return ForcePrintStatusAndHintRule, nil
211238
}
212239
case "throttle-control-replicas":
213240
{
241+
if argIsQuestion {
242+
fmt.Fprintf(writer, "%s\n", this.migrationContext.GetThrottleControlReplicaKeys().ToCommaDelimitedList())
243+
return NoPrintStatusRule, nil
244+
}
214245
if err := this.migrationContext.ReadThrottleControlReplicaKeys(arg); err != nil {
215246
return NoPrintStatusRule, err
216247
}

localtests/test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ test_single() {
8888
--throttle-query='select timestampdiff(second, min(last_update), now()) < 5 from _gh_ost_test_ghc' \
8989
--serve-socket-file=/tmp/gh-ost.test.sock \
9090
--initially-drop-socket-file \
91-
--postpone-cut-over-flag-file="" \
91+
--postpone-cut-over-flag-file=/tmp/gh-ost.test.postpone.flag \
9292
--test-on-replica \
9393
--default-retries=1 \
9494
--verbose \

0 commit comments

Comments
 (0)