Skip to content

Commit 9177f75

Browse files
author
Shlomi Noach
authored
Merge branch 'master' into heartbeat-control-replicas-unified
2 parents 3bf64d8 + 6bcf515 commit 9177f75

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

go/base/context.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ type MigrationContext struct {
122122
InitiallyDropOldTable bool
123123
InitiallyDropGhostTable bool
124124
CutOverType CutOver
125+
ReplicaServerId uint
125126

126127
Hostname string
127128
AssumeMasterHostname string

go/binlog/gomysql_reader.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"fmt"
1010
"sync"
1111

12+
"github.com/github/gh-ost/go/base"
1213
"github.com/github/gh-ost/go/mysql"
1314
"github.com/github/gh-ost/go/sql"
1415

@@ -17,17 +18,14 @@ import (
1718
"github.com/siddontang/go-mysql/replication"
1819
)
1920

20-
const (
21-
serverId = 99999
22-
)
23-
2421
type GoMySQLReader struct {
2522
connectionConfig *mysql.ConnectionConfig
2623
binlogSyncer *replication.BinlogSyncer
2724
binlogStreamer *replication.BinlogStreamer
2825
currentCoordinates mysql.BinlogCoordinates
2926
currentCoordinatesMutex *sync.Mutex
3027
LastAppliedRowsEventHint mysql.BinlogCoordinates
28+
MigrationContext *base.MigrationContext
3129
}
3230

3331
func NewGoMySQLReader(connectionConfig *mysql.ConnectionConfig) (binlogReader *GoMySQLReader, err error) {
@@ -37,7 +35,10 @@ func NewGoMySQLReader(connectionConfig *mysql.ConnectionConfig) (binlogReader *G
3735
currentCoordinatesMutex: &sync.Mutex{},
3836
binlogSyncer: nil,
3937
binlogStreamer: nil,
38+
MigrationContext: base.GetMigrationContext(),
4039
}
40+
41+
serverId := uint32(binlogReader.MigrationContext.ReplicaServerId)
4142
binlogReader.binlogSyncer = replication.NewBinlogSyncer(serverId, "mysql")
4243

4344
return binlogReader, err

go/cmd/gh-ost/main.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ func main() {
104104
flag.StringVar(&migrationContext.HooksPath, "hooks-path", "", "directory where hook files are found (default: empty, ie. hooks disabled). Hook files found on this path, and conforming to hook naming conventions will be executed")
105105
flag.StringVar(&migrationContext.HooksHintMessage, "hooks-hint", "", "arbitrary message to be injected to hooks via GH_OST_HOOKS_HINT, for your convenience")
106106

107+
flag.UintVar(&migrationContext.ReplicaServerId, "replica-server-id", 99999, "server id used by gh-ost process. Default: 99999")
108+
107109
maxLoad := flag.String("max-load", "", "Comma delimited status-name=threshold. e.g: 'Threads_running=100,Threads_connected=500'. When status exceeds threshold, app throttles writes")
108110
criticalLoad := flag.String("critical-load", "", "Comma delimited status-name=threshold, same format as --max-load. When status exceeds threshold, app panics and quits")
109111
flag.Int64Var(&migrationContext.CriticalLoadIntervalMilliseconds, "critical-load-interval-millis", 0, "When 0, migration immediately bails out upon meeting critical-load. When non-zero, a second check is done after given interval, and migration only bails out if 2nd check still meets critical load")
@@ -113,8 +115,13 @@ func main() {
113115
stack := flag.Bool("stack", false, "add stack trace upon error")
114116
help := flag.Bool("help", false, "Display usage")
115117
version := flag.Bool("version", false, "Print version & exit")
118+
checkFlag := flag.Bool("check-flag", false, "Check if another flag exists/supported. This allows for cross-version scripting. Exits with 0 when all additional provided flags exist, nonzero otherwise. You must provide (dummy) values for flags that require a value. Example: gh-ost --check-flag --cut-over-lock-timeout-seconds --nice-ratio 0")
119+
116120
flag.Parse()
117121

122+
if *checkFlag {
123+
return
124+
}
118125
if *help {
119126
fmt.Fprintf(os.Stderr, "Usage of gh-ost:\n")
120127
flag.PrintDefaults()

0 commit comments

Comments
 (0)