File tree Expand file tree Collapse file tree 5 files changed +56
-43
lines changed Expand file tree Collapse file tree 5 files changed +56
-43
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,10 @@ import (
11
11
"regexp"
12
12
"strings"
13
13
"time"
14
+
15
+ gosql "database/sql"
16
+ "github.com/github/gh-ost/go/mysql"
17
+ "github.com/outbrain/golib/log"
14
18
)
15
19
16
20
var (
@@ -50,3 +54,25 @@ func StringContainsAll(s string, substrings ...string) bool {
50
54
}
51
55
return nonEmptyStringsFound
52
56
}
57
+
58
+ func ValidateConnection (db * gosql.DB , connectionConfig * mysql.ConnectionConfig ) (string , error ) {
59
+ query := `select @@global.port, @@global.version`
60
+ var port , extraPort int
61
+ var version string
62
+ if err := db .QueryRow (query ).Scan (& port , & version ); err != nil {
63
+ return "" , err
64
+ }
65
+ extraPortQuery := `select @@global.extra_port`
66
+ if err := db .QueryRow (extraPortQuery ).Scan (& extraPort ); err != nil {
67
+ // swallow this error. not all servers support extra_port
68
+ }
69
+
70
+ if connectionConfig .Key .Port == port || (extraPort > 0 && connectionConfig .Key .Port == extraPort ) {
71
+ log .Infof ("connection validated on %+v" , connectionConfig .Key )
72
+ return version , nil
73
+ } else if extraPort == 0 {
74
+ return "" , fmt .Errorf ("Unexpected database port reported: %+v" , port )
75
+ } else {
76
+ return "" , fmt .Errorf ("Unexpected database port reported: %+v / extra_port: %+v" , port , extraPort )
77
+ }
78
+ }
Original file line number Diff line number Diff line change @@ -53,12 +53,14 @@ func (this *Applier) InitDBConnections() (err error) {
53
53
return err
54
54
}
55
55
this .singletonDB .SetMaxOpenConns (1 )
56
- if err := this .validateConnection (this .db ); err != nil {
56
+ version , err := base .ValidateConnection (this .db , this .connectionConfig )
57
+ if err != nil {
57
58
return err
58
59
}
59
- if err := this . validateConnection (this .singletonDB ); err != nil {
60
+ if _ , err := base . ValidateConnection (this .singletonDB , this . connectionConfig ); err != nil {
60
61
return err
61
62
}
63
+ this .migrationContext .ApplierMySQLVersion = version
62
64
if err := this .validateAndReadTimeZone (); err != nil {
63
65
return err
64
66
}
@@ -74,20 +76,6 @@ func (this *Applier) InitDBConnections() (err error) {
74
76
return nil
75
77
}
76
78
77
- // validateConnection issues a simple can-connect to MySQL
78
- func (this * Applier ) validateConnection (db * gosql.DB ) error {
79
- query := `select @@global.port, @@global.version`
80
- var port int
81
- if err := db .QueryRow (query ).Scan (& port , & this .migrationContext .ApplierMySQLVersion ); err != nil {
82
- return err
83
- }
84
- if port != this .connectionConfig .Key .Port {
85
- return fmt .Errorf ("Unexpected database port reported: %+v" , port )
86
- }
87
- log .Infof ("connection validated on %+v" , this .connectionConfig .Key )
88
- return nil
89
- }
90
-
91
79
// validateAndReadTimeZone potentially reads server time-zone
92
80
func (this * Applier ) validateAndReadTimeZone () error {
93
81
query := `select @@global.time_zone`
Original file line number Diff line number Diff line change @@ -195,16 +195,10 @@ func (this *Inspector) validateConnection() error {
195
195
if len (this .connectionConfig .Password ) > mysql .MaxReplicationPasswordLength {
196
196
return fmt .Errorf ("MySQL replication length limited to 32 characters. See https://dev.mysql.com/doc/refman/5.7/en/assigning-passwords.html" )
197
197
}
198
- query := `select @@global.port, @@global.version`
199
- var port int
200
- if err := this .db .QueryRow (query ).Scan (& port , & this .migrationContext .InspectorMySQLVersion ); err != nil {
201
- return err
202
- }
203
- if port != this .connectionConfig .Key .Port {
204
- return fmt .Errorf ("Unexpected database port reported: %+v" , port )
205
- }
206
- log .Infof ("connection validated on %+v" , this .connectionConfig .Key )
207
- return nil
198
+
199
+ version , err := base .ValidateConnection (this .db , this .connectionConfig )
200
+ this .migrationContext .InspectorMySQLVersion = version
201
+ return err
208
202
}
209
203
210
204
// validateGrants verifies the user by which we're executing has necessary grants
Original file line number Diff line number Diff line change @@ -107,7 +107,7 @@ func (this *EventsStreamer) InitDBConnections() (err error) {
107
107
if this .db , _ , err = sqlutils .GetDB (EventsStreamerUri ); err != nil {
108
108
return err
109
109
}
110
- if err := this . validateConnection ( ); err != nil {
110
+ if _ , err := base . ValidateConnection ( this . db , this . connectionConfig ); err != nil {
111
111
return err
112
112
}
113
113
if err := this .readCurrentBinlogCoordinates (); err != nil {
@@ -133,20 +133,6 @@ func (this *EventsStreamer) initBinlogReader(binlogCoordinates *mysql.BinlogCoor
133
133
return nil
134
134
}
135
135
136
- // validateConnection issues a simple can-connect to MySQL
137
- func (this * EventsStreamer ) validateConnection () error {
138
- query := `select @@global.port`
139
- var port int
140
- if err := this .db .QueryRow (query ).Scan (& port ); err != nil {
141
- return err
142
- }
143
- if port != this .connectionConfig .Key .Port {
144
- return fmt .Errorf ("Unexpected database port reported: %+v" , port )
145
- }
146
- log .Infof ("connection validated on %+v" , this .connectionConfig .Key )
147
- return nil
148
- }
149
-
150
136
func (this * EventsStreamer ) GetCurrentBinlogCoordinates () * mysql.BinlogCoordinates {
151
137
return this .binlogReader .GetCurrentBinlogCoordinates ()
152
138
}
Original file line number Diff line number Diff line change @@ -29,6 +29,10 @@ verify_master_and_replica() {
29
29
echo " Cannot verify gh-ost-test-mysql-replica"
30
30
exit 1
31
31
fi
32
+ if [ " $( gh-ost-test-mysql-replica -e " select @@global.binlog_format" -ss) " != " ROW" ] ; then
33
+ echo " Expecting test replica to have binlog_format=ROW"
34
+ exit 1
35
+ fi
32
36
read replica_host replica_port <<< $( gh-ost-test-mysql-replica -e " select @@hostname, @@port" -ss)
33
37
}
34
38
@@ -42,14 +46,29 @@ echo_dot() {
42
46
echo -n " ."
43
47
}
44
48
49
+ start_replication () {
50
+ gh-ost-test-mysql-replica -e " stop slave; start slave;"
51
+ num_attempts=0
52
+ while gh-ost-test-mysql-replica -e " show slave status\G" | grep Seconds_Behind_Master | grep -q NULL ; do
53
+ (( num_attempts= num_attempts+ 1 ))
54
+ if [ $num_attempts -gt 10 ] ; then
55
+ echo
56
+ echo " ERROR replication failure"
57
+ exit 1
58
+ fi
59
+ echo_dot
60
+ sleep 1
61
+ done
62
+ }
63
+
45
64
test_single () {
46
65
local test_name
47
66
test_name=" $1 "
48
67
49
68
echo -n " Testing: $test_name "
50
69
51
70
echo_dot
52
- gh-ost-test-mysql-replica -e " stop slave; start slave; do sleep(1) "
71
+ start_replication
53
72
echo_dot
54
73
gh-ost-test-mysql-master --default-character-set=utf8mb4 test < $tests_path /$test_name /create.sql
55
74
@@ -82,7 +101,7 @@ test_single() {
82
101
--table=gh_ost_test \
83
102
--alter='engine=innodb' \
84
103
--exact-rowcount \
85
- --switch-to -rbr \
104
+ --assume -rbr \
86
105
--initially-drop-old-table \
87
106
--initially-drop-ghost-table \
88
107
--throttle-query='select timestampdiff(second, min(last_update), now()) < 5 from _gh_ost_test_ghc' \
You can’t perform that action at this time.
0 commit comments