@@ -44,41 +44,48 @@ func RunRunCommand(stopCh <-chan struct{}) error {
4444 return fmt .Errorf ("mysql is not ready, err: %s" , err )
4545 }
4646
47- // deactivate read only
48- if _ , err := tb .RunQuery ("SET GLOBAL READ_ONLY = 0 " ); err != nil {
47+ // deactivate super read only
48+ if err := tb .RunQuery ("SET GLOBAL READ_ONLY = 1; SET GLOBAL SUPER_READ_ONLY = 0; " ); err != nil {
4949 return fmt .Errorf ("failed to configure master node, err: %s" , err )
5050 }
51+ glog .V (2 ).Info ("Temporary disabled SUPER_READ_ONLY..." )
5152
5253 // update orchestrator user and password if orchestrator is configured
5354 if len (tb .GetOrcUser ()) > 0 {
54- if err := tb . UpdateOrcUserPass (); err != nil {
55+ if err := configureOrchestratorUser (); err != nil {
5556 return err
5657 }
5758 }
59+ glog .V (2 ).Info ("Configured orchestrator user..." )
5860
5961 // update replication user and password
6062 if err := configureReplicationUser (); err != nil {
6163 return err
6264 }
65+ glog .V (2 ).Info ("Configured replication user..." )
6366
6467 // update metrics exporter user and password
6568 if err := configureExporterUser (); err != nil {
6669 return err
6770 }
71+ glog .V (2 ).Info ("Configured metrics exporter user..." )
6872
6973 // if it's slave set replication source (master host)
7074 if err := configTopology (); err != nil {
7175 return err
7276 }
77+ glog .V (2 ).Info ("Configured topology..." )
7378
7479 if err := markConfigurationDone (); err != nil {
7580 return err
7681 }
82+ glog .V (2 ).Info ("Flag setup as complete..." )
7783
7884 // if it's master node then make it writtable else make it read only
7985 if err := configReadOnly (); err != nil {
8086 return err
8187 }
88+ glog .V (2 ).Info ("Configured read only flag..." )
8289
8390 // start http server for readiness probe
8491 // here the server is ready to accept traffic
@@ -88,12 +95,27 @@ func RunRunCommand(stopCh <-chan struct{}) error {
8895 return startServeBackups ()
8996}
9097
98+ func configureOrchestratorUser () error {
99+ query := fmt .Sprintf (`
100+ SET @@SESSION.SQL_LOG_BIN = 0;
101+ GRANT SUPER, PROCESS, REPLICATION SLAVE, REPLICATION CLIENT, RELOAD ON *.* TO '%[1]s'@'%%' IDENTIFIED BY '%[2]s';
102+ GRANT SELECT ON meta.* TO '%[1]s'@'%%';
103+ GRANT SELECT ON mysql.slave_master_info TO '%[1]s'@'%%';
104+ ` , tb .GetOrcUser (), tb .GetOrcPass ())
105+
106+ if err := tb .RunQuery (query ); err != nil {
107+ return fmt .Errorf ("failed to configure orchestrator (user/pass/access), err: %s" , err )
108+ }
109+
110+ return nil
111+ }
112+
91113func configureReplicationUser () error {
92114 query := fmt .Sprintf (`
93115 SET @@SESSION.SQL_LOG_BIN = 0;
94116 GRANT SELECT, PROCESS, RELOAD, LOCK TABLES, REPLICATION CLIENT, REPLICATION SLAVE ON *.* TO '%s'@'%%' IDENTIFIED BY '%s';
95117 ` , tb .GetReplUser (), tb .GetReplPass ())
96- if _ , err := tb .RunQuery (query ); err != nil {
118+ if err := tb .RunQuery (query ); err != nil {
97119 return fmt .Errorf ("failed to configure replication user: %s" , err )
98120 }
99121
@@ -105,7 +127,7 @@ func configureExporterUser() error {
105127 SET @@SESSION.SQL_LOG_BIN = 0;
106128 GRANT SELECT, PROCESS, REPLICATION CLIENT ON *.* TO '%s'@'%%' IDENTIFIED BY '%s' WITH MAX_USER_CONNECTIONS 3;
107129 ` , tb .GetExporterUser (), tb .GetExporterPass ())
108- if _ , err := tb .RunQuery (query ); err != nil {
130+ if err := tb .RunQuery (query ); err != nil {
109131 return fmt .Errorf ("failed to metrics exporter user: %s" , err )
110132 }
111133
@@ -158,11 +180,11 @@ func waitForMysqlReady() error {
158180
159181 for i := 0 ; i < timeOut ; i ++ {
160182 time .Sleep (1 * time .Second )
161- if _ , err := tb .RunQuery ("SELECT 1" ); err == nil {
183+ if err := tb .RunQuery ("SELECT 1" ); err == nil {
162184 break
163185 }
164186 }
165- if _ , err := tb .RunQuery ("SELECT 1" ); err != nil {
187+ if err := tb .RunQuery ("SELECT 1" ); err != nil {
166188 glog .V (2 ).Info ("Mysql is not ready." )
167189 return err
168190 }
@@ -179,7 +201,7 @@ func configReadOnly() error {
179201 } else {
180202 query = "SET GLOBAL SUPER_READ_ONLY = 1"
181203 }
182- if _ , err := tb .RunQuery (query ); err != nil {
204+ if err := tb .RunQuery (query ); err != nil {
183205 return fmt .Errorf ("failed to set read_only config, err: %s" , err )
184206 }
185207 return nil
@@ -189,21 +211,22 @@ func configTopology() error {
189211 if tb .NodeRole () == "slave" {
190212 // slave node
191213 query := fmt .Sprintf (`
214+ STOP SLAVE;
192215 CHANGE MASTER TO MASTER_AUTO_POSITION=1,
193216 MASTER_HOST='%s',
194217 MASTER_USER='%s',
195218 MASTER_PASSWORD='%s',
196219 MASTER_CONNECT_RETRY=%d;
197220 ` , tb .GetMasterHost (), tb .GetReplUser (), tb .GetReplPass (), connRetry )
198221
199- if _ , err := tb .RunQuery (query ); err != nil {
222+ if err := tb .RunQuery (query ); err != nil {
200223 return fmt .Errorf ("failed to configure slave node, err: %s" , err )
201224 }
202225
203226 query = `
204227 START SLAVE;
205228 `
206- if _ , err := tb .RunQuery (query ); err != nil {
229+ if err := tb .RunQuery (query ); err != nil {
207230 glog .Warning ("Failed to start slave simple, err: %s, try second method." )
208231 // TODO: https://bugs.mysql.com/bug.php?id=83713
209232 query2 := `
@@ -213,7 +236,7 @@ func configTopology() error {
213236 reset slave;
214237 start slave;
215238 `
216- if _ , err := tb .RunQuery (query2 ); err != nil {
239+ if err := tb .RunQuery (query2 ); err != nil {
217240 return fmt .Errorf ("failed to start slave node, err: %s" , err )
218241 }
219242 }
@@ -237,8 +260,8 @@ func markConfigurationDone() error {
237260 COMMIT;
238261 ` , tb .ToolsDbName , tb .ToolsInitTableName , tb .GetHostname ())
239262
240- if _ , err := tb .RunQuery (query ); err != nil {
241- return fmt .Errorf ("to mark configuration done, err: %s" , err )
263+ if err := tb .RunQuery (query ); err != nil {
264+ return fmt .Errorf ("failed to mark configuration done, err: %s" , err )
242265 }
243266
244267 return nil
0 commit comments