From 2fc3c2713d5722d85547265f45242c3276764734 Mon Sep 17 00:00:00 2001 From: Alain Jobart Date: Tue, 11 Aug 2015 18:21:54 -0700 Subject: [PATCH] Now mysql port is a int32, to be consistent with other places. Also fixing all linter issues. --- config/mycnf/default-fast.cnf | 2 +- config/mycnf/default.cnf | 2 +- go/cmd/mysqlctl/mysqlctl.go | 2 +- go/cmd/mysqlctld/mysqlctld.go | 2 +- go/vt/mysqlctl/mycnf.go | 15 +++++++-------- go/vt/mysqlctl/mycnf_flag.go | 4 ++-- go/vt/mysqlctl/mycnf_gen.go | 20 ++++++++++---------- go/vt/mysqlctl/mysql_daemon.go | 10 +++++----- go/vt/mysqlctl/mysqld.go | 4 ++-- go/vt/mysqlctl/reparent.go | 2 +- go/vt/mysqlctl/replication.go | 16 ++++++++-------- go/vt/tabletmanager/agent.go | 4 ++-- go/vt/tabletmanager/agent_rpc_actions.go | 4 ++-- go/vt/wrangler/testlib/fake_tablet.go | 2 +- 14 files changed, 44 insertions(+), 45 deletions(-) diff --git a/config/mycnf/default-fast.cnf b/config/mycnf/default-fast.cnf index 87c0605194..55869078d3 100644 --- a/config/mycnf/default-fast.cnf +++ b/config/mycnf/default-fast.cnf @@ -40,7 +40,7 @@ query_cache_type = 2 read-only read_buffer_size = 1M read_rnd_buffer_size = 1M -server-id = {{.ServerId}} +server-id = {{.ServerID}} skip-name-resolve # we now need networking for replication. this is a tombstone to simpler times. #skip_networking diff --git a/config/mycnf/default.cnf b/config/mycnf/default.cnf index 11afe36cce..ce84b7cceb 100644 --- a/config/mycnf/default.cnf +++ b/config/mycnf/default.cnf @@ -40,7 +40,7 @@ query_cache_type = 2 read-only read_buffer_size = 1M read_rnd_buffer_size = 1M -server-id = {{.ServerId}} +server-id = {{.ServerID}} skip-name-resolve # we now need networking for replication. this is a tombstone to simpler times. #skip_networking diff --git a/go/cmd/mysqlctl/mysqlctl.go b/go/cmd/mysqlctl/mysqlctl.go index 1b4c9104cf..ad694a57a9 100644 --- a/go/cmd/mysqlctl/mysqlctl.go +++ b/go/cmd/mysqlctl/mysqlctl.go @@ -167,7 +167,7 @@ func main() { flag.Parse() tabletAddr = netutil.JoinHostPort("localhost", int32(*port)) - mycnf := mysqlctl.NewMycnf(uint32(*tabletUID), *mysqlPort) + mycnf := mysqlctl.NewMycnf(uint32(*tabletUID), int32(*mysqlPort)) if *mysqlSocket != "" { mycnf.SocketFile = *mysqlSocket diff --git a/go/cmd/mysqlctld/mysqlctld.go b/go/cmd/mysqlctld/mysqlctld.go index acf6973f74..1323ad4695 100644 --- a/go/cmd/mysqlctld/mysqlctld.go +++ b/go/cmd/mysqlctld/mysqlctld.go @@ -51,7 +51,7 @@ func main() { dbconfigs.RegisterFlags(flags) flag.Parse() - mycnf := mysqlctl.NewMycnf(uint32(*tabletUID), *mysqlPort) + mycnf := mysqlctl.NewMycnf(uint32(*tabletUID), int32(*mysqlPort)) if *mysqlSocket != "" { mycnf.SocketFile = *mysqlSocket } diff --git a/go/vt/mysqlctl/mycnf.go b/go/vt/mysqlctl/mycnf.go index 4d42fee8e1..007e558f0b 100644 --- a/go/vt/mysqlctl/mycnf.go +++ b/go/vt/mysqlctl/mycnf.go @@ -22,15 +22,14 @@ import ( // parameters to start mysqld. It can be used to generate standard // my.cnf files from a server id and mysql port. It can also be // populated from an existing my.cnf, or by command line parameters. -// command line parameters. type Mycnf struct { - // ServerId is the unique id for this server. + // ServerID is the unique id for this server. // Used to create a bunch of named directories. - ServerId uint32 + ServerID uint32 // MysqlPort is the port for the MySQL server running on this machine. // It is mainly used to communicate with topology server. - MysqlPort int + MysqlPort int32 // DataDir is where the table files are // (used by vt software for Clone) @@ -147,19 +146,19 @@ func ReadMycnf(cnfFile string) (mycnf *Mycnf, err error) { mycnf.mycnfMap[lval] = rval } - serverIdStr := mycnf.lookupAndCheck("server-id") - serverId, err := strconv.Atoi(serverIdStr) + serverIDStr := mycnf.lookupAndCheck("server-id") + serverID, err := strconv.Atoi(serverIDStr) if err != nil { return nil, fmt.Errorf("Failed to convert server-id %v", err) } - mycnf.ServerId = uint32(serverId) + mycnf.ServerID = uint32(serverID) portStr := mycnf.lookupAndCheck("port") port, err := strconv.Atoi(portStr) if err != nil { return nil, fmt.Errorf("Failed: failed to convert port %v", err) } - mycnf.MysqlPort = port + mycnf.MysqlPort = int32(port) mycnf.DataDir = mycnf.lookupAndCheck("datadir") mycnf.InnodbDataHomeDir = mycnf.lookupAndCheck("innodb_data_home_dir") mycnf.InnodbLogGroupHomeDir = mycnf.lookupAndCheck("innodb_log_group_home_dir") diff --git a/go/vt/mysqlctl/mycnf_flag.go b/go/vt/mysqlctl/mycnf_flag.go index c554a07403..dfa955e048 100644 --- a/go/vt/mysqlctl/mycnf_flag.go +++ b/go/vt/mysqlctl/mycnf_flag.go @@ -79,8 +79,8 @@ func NewMycnfFromFlags(uid uint32) (mycnf *Mycnf, err error) { if *flagServerID != 0 { log.Info("mycnf_server_id is specified, using command line parameters for mysql config") return &Mycnf{ - ServerId: uint32(*flagServerID), - MysqlPort: *flagMysqlPort, + ServerID: uint32(*flagServerID), + MysqlPort: int32(*flagMysqlPort), DataDir: *flagDataDir, InnodbDataHomeDir: *flagInnodbDataHomeDir, InnodbLogGroupHomeDir: *flagInnodbLogGroupHomeDir, diff --git a/go/vt/mysqlctl/mycnf_gen.go b/go/vt/mysqlctl/mycnf_gen.go index 872c210815..500dce4683 100644 --- a/go/vt/mysqlctl/mycnf_gen.go +++ b/go/vt/mysqlctl/mycnf_gen.go @@ -44,11 +44,11 @@ const ( // uid is a unique id for a particular tablet - it must be unique within the // tabletservers deployed within a keyspace, lest there be collisions on disk. // mysqldPort needs to be unique per instance per machine. -func NewMycnf(uid uint32, mysqlPort int) *Mycnf { +func NewMycnf(uid uint32, mysqlPort int32) *Mycnf { cnf := new(Mycnf) cnf.path = mycnfFile(uid) tabletDir := TabletDir(uid) - cnf.ServerId = uid + cnf.ServerID = uid cnf.MysqlPort = mysqlPort cnf.DataDir = path.Join(tabletDir, dataDir) cnf.InnodbDataHomeDir = path.Join(tabletDir, innodbDataSubdir) @@ -57,11 +57,11 @@ func NewMycnf(uid uint32, mysqlPort int) *Mycnf { cnf.ErrorLogPath = path.Join(tabletDir, "error.log") cnf.SlowLogPath = path.Join(tabletDir, "slow-query.log") cnf.RelayLogPath = path.Join(tabletDir, relayLogDir, - fmt.Sprintf("vt-%010d-relay-bin", cnf.ServerId)) + fmt.Sprintf("vt-%010d-relay-bin", cnf.ServerID)) cnf.RelayLogIndexPath = cnf.RelayLogPath + ".index" cnf.RelayLogInfoPath = path.Join(tabletDir, relayLogDir, "relay-log.info") cnf.BinLogPath = path.Join(tabletDir, binLogDir, - fmt.Sprintf("vt-%010d-bin", cnf.ServerId)) + fmt.Sprintf("vt-%010d-bin", cnf.ServerID)) cnf.MasterInfoFile = path.Join(tabletDir, "master.info") cnf.PidFile = path.Join(tabletDir, "mysql.pid") cnf.TmpDir = path.Join(tabletDir, "tmp") @@ -98,13 +98,13 @@ func (cnf *Mycnf) directoryList() []string { cnf.InnodbDataHomeDir, cnf.InnodbLogGroupHomeDir, cnf.TmpDir, - path.Join(TabletDir(cnf.ServerId), relayLogDir), - path.Join(TabletDir(cnf.ServerId), binLogDir), + path.Join(TabletDir(cnf.ServerID), relayLogDir), + path.Join(TabletDir(cnf.ServerID), binLogDir), } } // makeMycnf will join cnf files cnfPaths and substitute in the right values. -func (mycnf *Mycnf) makeMycnf(cnfFiles []string) (string, error) { +func (cnf *Mycnf) makeMycnf(cnfFiles []string) (string, error) { myTemplateSource := new(bytes.Buffer) myTemplateSource.WriteString("[mysqld]\n") for _, path := range cnfFiles { @@ -115,18 +115,18 @@ func (mycnf *Mycnf) makeMycnf(cnfFiles []string) (string, error) { myTemplateSource.WriteString("## " + path + "\n") myTemplateSource.Write(data) } - return mycnf.fillMycnfTemplate(myTemplateSource.String()) + return cnf.fillMycnfTemplate(myTemplateSource.String()) } // fillMycnfTemplate will fill in the passed in template with the values // from Mycnf -func (mycnf *Mycnf) fillMycnfTemplate(tmplSrc string) (string, error) { +func (cnf *Mycnf) fillMycnfTemplate(tmplSrc string) (string, error) { myTemplate, err := template.New("").Parse(tmplSrc) if err != nil { return "", err } mycnfData := new(bytes.Buffer) - err = myTemplate.Execute(mycnfData, mycnf) + err = myTemplate.Execute(mycnfData, cnf) if err != nil { return "", err } diff --git a/go/vt/mysqlctl/mysql_daemon.go b/go/vt/mysqlctl/mysql_daemon.go index 0ffda56481..07c4b8bbbe 100644 --- a/go/vt/mysqlctl/mysql_daemon.go +++ b/go/vt/mysqlctl/mysql_daemon.go @@ -29,7 +29,7 @@ type MysqlDaemon interface { RunMysqlUpgrade() error // GetMysqlPort returns the current port mysql is listening on. - GetMysqlPort() (int, error) + GetMysqlPort() (int32, error) // replication related methods SlaveStatus() (proto.ReplicationStatus, error) @@ -95,7 +95,7 @@ type FakeMysqlDaemon struct { // MysqlPort will be returned by GetMysqlPort(). Set to -1 to // return an error. - MysqlPort int + MysqlPort int32 // Replicating is updated when calling StartSlave / StopSlave // (it is not used at all when calling SlaveStatus, it is the @@ -220,7 +220,7 @@ func (fmd *FakeMysqlDaemon) RunMysqlUpgrade() error { } // GetMysqlPort is part of the MysqlDaemon interface -func (fmd *FakeMysqlDaemon) GetMysqlPort() (int, error) { +func (fmd *FakeMysqlDaemon) GetMysqlPort() (int32, error) { if fmd.MysqlPort == -1 { return 0, fmt.Errorf("FakeMysqlDaemon.GetMysqlPort returns an error") } @@ -325,9 +325,9 @@ func (fmd *FakeMysqlDaemon) ExecuteSuperQueryList(queryList []string) error { // intercept some queries to update our status switch query { - case SqlStartSlave: + case SQLStartSlave: fmd.Replicating = true - case SqlStopSlave: + case SQLStopSlave: fmd.Replicating = false } } diff --git a/go/vt/mysqlctl/mysqld.go b/go/vt/mysqlctl/mysqld.go index 269ce87968..94a035092c 100644 --- a/go/vt/mysqlctl/mysqld.go +++ b/go/vt/mysqlctl/mysqld.go @@ -106,8 +106,8 @@ func NewMysqld(dbaName, appName string, config *Mycnf, dba, app, repl *sqldb.Con appPool: appPool, replParams: repl, dbaMysqlStats: dbaMysqlStats, - TabletDir: TabletDir(config.ServerId), - SnapshotDir: SnapshotDir(config.ServerId), + TabletDir: TabletDir(config.ServerID), + SnapshotDir: SnapshotDir(config.ServerID), } } diff --git a/go/vt/mysqlctl/reparent.go b/go/vt/mysqlctl/reparent.go index 268d6b3c22..fd13e44a83 100644 --- a/go/vt/mysqlctl/reparent.go +++ b/go/vt/mysqlctl/reparent.go @@ -85,7 +85,7 @@ func (mysqld *Mysqld) DemoteMaster() (rp proto.ReplicationPosition, err error) { // PromoteSlave will promote a slave to be the new master. func (mysqld *Mysqld) PromoteSlave(hookExtraEnv map[string]string) (proto.ReplicationPosition, error) { // we handle replication, just stop it - cmds := []string{SqlStopSlave} + cmds := []string{SQLStopSlave} // Promote to master. flavor, err := mysqld.flavor() diff --git a/go/vt/mysqlctl/replication.go b/go/vt/mysqlctl/replication.go index a261aa888b..7638decbfd 100644 --- a/go/vt/mysqlctl/replication.go +++ b/go/vt/mysqlctl/replication.go @@ -29,11 +29,11 @@ import ( ) const ( - // SqlStartSlave is the SQl command issued to start MySQL replication - SqlStartSlave = "START SLAVE" + // SQLStartSlave is the SQl command issued to start MySQL replication + SQLStartSlave = "START SLAVE" - // SqlStopSlave is the SQl command issued to stop MySQL replication - SqlStopSlave = "STOP SLAVE" + // SQLStopSlave is the SQl command issued to stop MySQL replication + SQLStopSlave = "STOP SLAVE" ) func fillStringTemplate(tmpl string, vars interface{}) (string, error) { @@ -118,7 +118,7 @@ func WaitForSlaveStart(mysqld MysqlDaemon, slaveStartDeadline int) error { // StartSlave starts a slave on the provided MysqldDaemon func StartSlave(md MysqlDaemon, hookExtraEnv map[string]string) error { - if err := md.ExecuteSuperQueryList([]string{SqlStartSlave}); err != nil { + if err := md.ExecuteSuperQueryList([]string{SQLStartSlave}); err != nil { return err } @@ -135,11 +135,11 @@ func StopSlave(md MysqlDaemon, hookExtraEnv map[string]string) error { return err } - return md.ExecuteSuperQueryList([]string{SqlStopSlave}) + return md.ExecuteSuperQueryList([]string{SQLStopSlave}) } // GetMysqlPort returns mysql port -func (mysqld *Mysqld) GetMysqlPort() (int, error) { +func (mysqld *Mysqld) GetMysqlPort() (int32, error) { qr, err := mysqld.FetchSuperQuery("SHOW VARIABLES LIKE 'port'") if err != nil { return 0, err @@ -151,7 +151,7 @@ func (mysqld *Mysqld) GetMysqlPort() (int, error) { if err != nil { return 0, err } - return int(utemp), nil + return int32(utemp), nil } // IsReadOnly return true if the instance is read only diff --git a/go/vt/tabletmanager/agent.go b/go/vt/tabletmanager/agent.go index fcc22da0e2..3a718f0606 100644 --- a/go/vt/tabletmanager/agent.go +++ b/go/vt/tabletmanager/agent.go @@ -479,12 +479,12 @@ func (agent *ActionAgent) checkTabletMysqlPort(ctx context.Context, tablet *topo return nil } - if int32(mport) == tablet.PortMap["mysql"] { + if mport == tablet.PortMap["mysql"] { return nil } log.Warningf("MySQL port has changed from %v to %v, updating it in tablet record", tablet.PortMap["mysql"], mport) - tablet.PortMap["mysql"] = int32(mport) + tablet.PortMap["mysql"] = mport if err := topo.UpdateTablet(ctx, agent.TopoServer, tablet); err != nil { log.Warningf("Failed to update tablet record, may use old mysql port") return nil diff --git a/go/vt/tabletmanager/agent_rpc_actions.go b/go/vt/tabletmanager/agent_rpc_actions.go index 36aa12fc8a..fa379152bc 100644 --- a/go/vt/tabletmanager/agent_rpc_actions.go +++ b/go/vt/tabletmanager/agent_rpc_actions.go @@ -548,7 +548,7 @@ func (agent *ActionAgent) SetMaster(ctx context.Context, parent *pb.TabletAlias, // Create the list of commands to set the master cmds := []string{} if wasReplicating { - cmds = append(cmds, mysqlctl.SqlStopSlave) + cmds = append(cmds, mysqlctl.SQLStopSlave) } smc, err := agent.MysqlDaemon.SetMasterCommands(ti.Hostname, int(ti.PortMap["mysql"])) if err != nil { @@ -556,7 +556,7 @@ func (agent *ActionAgent) SetMaster(ctx context.Context, parent *pb.TabletAlias, } cmds = append(cmds, smc...) if shouldbeReplicating { - cmds = append(cmds, mysqlctl.SqlStartSlave) + cmds = append(cmds, mysqlctl.SQLStartSlave) } if err := agent.MysqlDaemon.ExecuteSuperQueryList(cmds); err != nil { return err diff --git a/go/vt/wrangler/testlib/fake_tablet.go b/go/vt/wrangler/testlib/fake_tablet.go index 319ee87a1a..9f4c826986 100644 --- a/go/vt/wrangler/testlib/fake_tablet.go +++ b/go/vt/wrangler/testlib/fake_tablet.go @@ -131,7 +131,7 @@ func NewFakeTablet(t *testing.T, wr *wrangler.Wrangler, cell string, uid uint32, // create a FakeMysqlDaemon with the right information by default fakeMysqlDaemon := mysqlctl.NewFakeMysqlDaemon() - fakeMysqlDaemon.MysqlPort = 3300 + int(uid) + fakeMysqlDaemon.MysqlPort = 3300 + int32(uid) return &FakeTablet{ Tablet: tablet,