Now mysql port is a int32, to be consistent with other places.

Also fixing all linter issues.
This commit is contained in:
Alain Jobart 2015-08-11 18:21:54 -07:00
Родитель a8762c733c
Коммит 2fc3c2713d
14 изменённых файлов: 44 добавлений и 45 удалений

Просмотреть файл

@ -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

Просмотреть файл

@ -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

Просмотреть файл

@ -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

Просмотреть файл

@ -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
}

Просмотреть файл

@ -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")

Просмотреть файл

@ -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,

Просмотреть файл

@ -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
}

Просмотреть файл

@ -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
}
}

Просмотреть файл

@ -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),
}
}

Просмотреть файл

@ -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()

Просмотреть файл

@ -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

Просмотреть файл

@ -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

Просмотреть файл

@ -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

Просмотреть файл

@ -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,