Skip to content

Commit 5af587a

Browse files
author
Shlomi Noach
authored
Merge branch 'master' into datetime-6-millis-corruption
2 parents f136123 + 2f4e226 commit 5af587a

File tree

5 files changed

+84
-16
lines changed

5 files changed

+84
-16
lines changed

doc/interactive-commands.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Both interfaces may serve at the same time. Both respond to simple text command,
1919
- `sup`: returns a brief status summary of migration progress
2020
- `coordinates`: returns recent (though not exactly up to date) binary log coordinates of the inspected server
2121
- `chunk-size=<newsize>`: modify the `chunk-size`; applies on next running copy-iteration
22+
- `dml-batch-size=<newsize>`: modify the `dml-batch-size`; applies on next applying of binary log events
2223
- `max-lag-millis=<max-lag>`: modify the maximum replication lag threshold (milliseconds, minimum value is `100`, i.e. `0.1` second)
2324
- `max-load=<max-load-thresholds>`: modify the `max-load` config; applies on next running copy-iteration
2425
- The `max-load` format must be: `some_status=<numeric-threshold>[,some_status=<numeric-threshold>...]`'
@@ -52,7 +53,7 @@ While migration is running:
5253
$ echo status | nc -U /tmp/gh-ost.test.sample_data_0.sock
5354
# Migrating `test`.`sample_data_0`; Ghost table is `test`.`_sample_data_0_gst`
5455
# Migration started at Tue Jun 07 11:45:16 +0200 2016
55-
# chunk-size: 200; max lag: 1500ms; max-load: map[Threads_connected:20]
56+
# chunk-size: 200; max lag: 1500ms; dml-batch-size: 10; max-load: map[Threads_connected:20]
5657
# Throttle additional flag file: /tmp/gh-ost.throttle
5758
# Serving on unix socket: /tmp/gh-ost.test.sample_data_0.sock
5859
# Serving on TCP port: 10001
@@ -63,7 +64,7 @@ Copy: 0/2915 0.0%; Applied: 0; Backlog: 0/100; Elapsed: 40s(copy), 41s(total); s
6364
$ echo "chunk-size=250" | nc -U /tmp/gh-ost.test.sample_data_0.sock
6465
# Migrating `test`.`sample_data_0`; Ghost table is `test`.`_sample_data_0_gst`
6566
# Migration started at Tue Jun 07 11:56:03 +0200 2016
66-
# chunk-size: 250; max lag: 1500ms; max-load: map[Threads_connected:20]
67+
# chunk-size: 250; max lag: 1500ms; dml-batch-size: 10; max-load: map[Threads_connected:20]
6768
# Throttle additional flag file: /tmp/gh-ost.throttle
6869
# Serving on unix socket: /tmp/gh-ost.test.sample_data_0.sock
6970
# Serving on TCP port: 10001

go/base/context.go

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ const (
4646
)
4747

4848
const (
49-
HTTPStatusOK = 200
50-
maxBatchSize = 1000
49+
HTTPStatusOK = 200
50+
MaxEventsBatchSize = 1000
5151
)
5252

5353
var (
@@ -243,9 +243,18 @@ func GetMigrationContext() *MigrationContext {
243243
return context
244244
}
245245

246+
func getSafeTableName(baseName string, suffix string) string {
247+
name := fmt.Sprintf("_%s_%s", baseName, suffix)
248+
if len(name) <= mysql.MaxTableNameLength {
249+
return name
250+
}
251+
extraCharacters := len(name) - mysql.MaxTableNameLength
252+
return fmt.Sprintf("_%s_%s", baseName[0:len(baseName)-extraCharacters], suffix)
253+
}
254+
246255
// GetGhostTableName generates the name of ghost table, based on original table name
247256
func (this *MigrationContext) GetGhostTableName() string {
248-
return fmt.Sprintf("_%s_gho", this.OriginalTableName)
257+
return getSafeTableName(this.OriginalTableName, "gho")
249258
}
250259

251260
// GetOldTableName generates the name of the "old" table, into which the original table is renamed.
@@ -255,14 +264,14 @@ func (this *MigrationContext) GetOldTableName() string {
255264
timestamp := fmt.Sprintf("%d%02d%02d%02d%02d%02d",
256265
t.Year(), t.Month(), t.Day(),
257266
t.Hour(), t.Minute(), t.Second())
258-
return fmt.Sprintf("_%s_%s_del", this.OriginalTableName, timestamp)
267+
return getSafeTableName(this.OriginalTableName, fmt.Sprintf("%s_del", timestamp))
259268
}
260-
return fmt.Sprintf("_%s_del", this.OriginalTableName)
269+
return getSafeTableName(this.OriginalTableName, "del")
261270
}
262271

263272
// GetChangelogTableName generates the name of changelog table, based on original table name
264273
func (this *MigrationContext) GetChangelogTableName() string {
265-
return fmt.Sprintf("_%s_ghc", this.OriginalTableName)
274+
return getSafeTableName(this.OriginalTableName, "ghc")
266275
}
267276

268277
// GetVoluntaryLockName returns a name of a voluntary lock to be used throughout
@@ -442,8 +451,8 @@ func (this *MigrationContext) SetDMLBatchSize(batchSize int64) {
442451
if batchSize < 1 {
443452
batchSize = 1
444453
}
445-
if batchSize > maxBatchSize {
446-
batchSize = maxBatchSize
454+
if batchSize > MaxEventsBatchSize {
455+
batchSize = MaxEventsBatchSize
447456
}
448457
atomic.StoreInt64(&this.DMLBatchSize, batchSize)
449458
}

go/base/context_test.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
Copyright 2016 GitHub Inc.
3+
See https://github.com/github/gh-ost/blob/master/LICENSE
4+
*/
5+
6+
package base
7+
8+
import (
9+
"testing"
10+
"time"
11+
12+
"github.com/outbrain/golib/log"
13+
test "github.com/outbrain/golib/tests"
14+
)
15+
16+
func init() {
17+
log.SetLevel(log.ERROR)
18+
}
19+
20+
func TestGetTableNames(t *testing.T) {
21+
context = newMigrationContext()
22+
{
23+
context.OriginalTableName = "some_table"
24+
test.S(t).ExpectEquals(context.GetOldTableName(), "_some_table_del")
25+
test.S(t).ExpectEquals(context.GetGhostTableName(), "_some_table_gho")
26+
test.S(t).ExpectEquals(context.GetChangelogTableName(), "_some_table_ghc")
27+
}
28+
{
29+
context.OriginalTableName = "a123456789012345678901234567890123456789012345678901234567890"
30+
test.S(t).ExpectEquals(context.GetOldTableName(), "_a1234567890123456789012345678901234567890123456789012345678_del")
31+
test.S(t).ExpectEquals(context.GetGhostTableName(), "_a1234567890123456789012345678901234567890123456789012345678_gho")
32+
test.S(t).ExpectEquals(context.GetChangelogTableName(), "_a1234567890123456789012345678901234567890123456789012345678_ghc")
33+
}
34+
{
35+
context.OriginalTableName = "a123456789012345678901234567890123456789012345678901234567890123"
36+
oldTableName := context.GetOldTableName()
37+
test.S(t).ExpectEquals(oldTableName, "_a1234567890123456789012345678901234567890123456789012345678_del")
38+
}
39+
{
40+
context.OriginalTableName = "a123456789012345678901234567890123456789012345678901234567890123"
41+
context.TimestampOldTable = true
42+
longForm := "Jan 2, 2006 at 3:04pm (MST)"
43+
context.StartTime, _ = time.Parse(longForm, "Feb 3, 2013 at 7:54pm (PST)")
44+
oldTableName := context.GetOldTableName()
45+
test.S(t).ExpectEquals(oldTableName, "_a1234567890123456789012345678901234567890123_20130203195400_del")
46+
}
47+
}

go/logic/migrator.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,6 @@ func newApplyEventStructByDML(dmlEvent *binlog.BinlogDMLEvent) *applyEventStruct
5252
return result
5353
}
5454

55-
const (
56-
applyEventsQueueBuffer = 100
57-
)
58-
5955
type PrintStatusRule int
6056

6157
const (
@@ -101,7 +97,7 @@ func NewMigrator() *Migrator {
10197
allEventsUpToLockProcessed: make(chan string),
10298

10399
copyRowsQueue: make(chan tableWriteFunc),
104-
applyEventsQueue: make(chan *applyEventStruct, applyEventsQueueBuffer),
100+
applyEventsQueue: make(chan *applyEventStruct, base.MaxEventsBatchSize),
105101
handledChangelogStates: make(map[string]bool),
106102
}
107103
return migrator
@@ -767,9 +763,10 @@ func (this *Migrator) printMigrationStatusHint(writers ...io.Writer) {
767763
))
768764
maxLoad := this.migrationContext.GetMaxLoad()
769765
criticalLoad := this.migrationContext.GetCriticalLoad()
770-
fmt.Fprintln(w, fmt.Sprintf("# chunk-size: %+v; max-lag-millis: %+vms; max-load: %s; critical-load: %s; nice-ratio: %f",
766+
fmt.Fprintln(w, fmt.Sprintf("# chunk-size: %+v; max-lag-millis: %+vms; dml-batch-size: %+v; max-load: %s; critical-load: %s; nice-ratio: %f",
771767
atomic.LoadInt64(&this.migrationContext.ChunkSize),
772768
atomic.LoadInt64(&this.migrationContext.MaxLagMillisecondsThrottleThreshold),
769+
atomic.LoadInt64(&this.migrationContext.DMLBatchSize),
773770
maxLoad.String(),
774771
criticalLoad.String(),
775772
this.migrationContext.GetNiceRatio(),

go/logic/server.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ status # Print a detailed status message
146146
sup # Print a short status message
147147
coordinates # Print the currently inspected coordinates
148148
chunk-size=<newsize> # Set a new chunk-size
149+
dml-batch-size=<newsize> # Set a new dml-batch-size
149150
nice-ratio=<ratio> # Set a new nice-ratio, immediate sleep after each row-copy operation, float (examples: 0 is agrressive, 0.7 adds 70% runtime, 1.0 doubles runtime, 2.0 triples runtime, ...)
150151
critical-load=<load> # Set a new set of max-load thresholds
151152
max-lag-millis=<max-lag> # Set a new replication lag threshold
@@ -187,6 +188,19 @@ help # This message
187188
return ForcePrintStatusAndHintRule, nil
188189
}
189190
}
191+
case "dml-batch-size":
192+
{
193+
if argIsQuestion {
194+
fmt.Fprintf(writer, "%+v\n", atomic.LoadInt64(&this.migrationContext.DMLBatchSize))
195+
return NoPrintStatusRule, nil
196+
}
197+
if dmlBatchSize, err := strconv.Atoi(arg); err != nil {
198+
return NoPrintStatusRule, err
199+
} else {
200+
this.migrationContext.SetDMLBatchSize(int64(dmlBatchSize))
201+
return ForcePrintStatusAndHintRule, nil
202+
}
203+
}
190204
case "max-lag-millis":
191205
{
192206
if argIsQuestion {

0 commit comments

Comments
 (0)