Skip to content

Commit d21bd3f

Browse files
author
Shlomi Noach
authored
Merge pull request #349 from cypiszzz/master
Add possibility to set serverId as gh-ost option
2 parents d13049b + 2bfc672 commit d21bd3f

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

go/base/context.go

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

127128
Hostname string
128129
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: 2 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")

0 commit comments

Comments
 (0)