Esempio n. 1
0
func changeMasterArgs(params *mysql.ConnectionParams, status *proto.ReplicationStatus) []string {
	var args []string
	args = append(args, fmt.Sprintf("MASTER_HOST = '%s'", status.MasterHost))
	args = append(args, fmt.Sprintf("MASTER_PORT = %d", status.MasterPort))
	args = append(args, fmt.Sprintf("MASTER_USER = '******'", params.Uname))
	args = append(args, fmt.Sprintf("MASTER_PASSWORD = '******'", params.Pass))
	args = append(args, fmt.Sprintf("MASTER_CONNECT_RETRY = %d", status.MasterConnectRetry))

	if params.SslEnabled() {
		args = append(args, "MASTER_SSL = 1")
	}
	if params.SslCa != "" {
		args = append(args, fmt.Sprintf("MASTER_SSL_CA = '%s'", params.SslCa))
	}
	if params.SslCaPath != "" {
		args = append(args, fmt.Sprintf("MASTER_SSL_CAPATH = '%s'", params.SslCaPath))
	}
	if params.SslCert != "" {
		args = append(args, fmt.Sprintf("MASTER_SSL_CERT = '%s'", params.SslCert))
	}
	if params.SslKey != "" {
		args = append(args, fmt.Sprintf("MASTER_SSL_KEY = '%s'", params.SslKey))
	}
	return args
}
Esempio n. 2
0
// refreshPassword uses the CredentialServer to refresh the password
// to use.
func refreshPassword(params *mysql.ConnectionParams) error {
	user, passwd, err := GetCredentialsServer().GetPassword(params.Uname)
	switch err {
	case nil:
		params.Uname = user
		params.Pass = passwd
	case ErrUnknownUser:
	default:
		return err
	}
	return nil
}
Esempio n. 3
0
// InitConnectionParams may overwrite the socket file,
// and refresh the password to check that works.
func InitConnectionParams(cp *mysql.ConnectionParams, socketFile string) error {
	if socketFile != "" {
		cp.UnixSocket = socketFile
	}
	params := *cp
	return refreshPassword(&params)
}
Esempio n. 4
0
func NewMysqld(config *Mycnf, dba, repl *mysql.ConnectionParams) *Mysqld {
	if *dba == dbconfigs.DefaultDBConfigs.Dba {
		dba.UnixSocket = config.SocketFile
	}

	return &Mysqld{config,
		dba,
		repl,
		TabletDir(config.ServerId),
		SnapshotDir(config.ServerId),
	}
}
Esempio n. 5
0
func createLookupClient(lookupConfigFile, dbCredFile string) (*DBClient, error) {
	lookupConfigData, err := ioutil.ReadFile(lookupConfigFile)
	if err != nil {
		return nil, fmt.Errorf("Error %s in reading lookup-config-file %s", err, lookupConfigFile)
	}

	lookupClient := &DBClient{}
	lookupConfig := new(mysql.ConnectionParams)
	err = json.Unmarshal(lookupConfigData, lookupConfig)
	if err != nil {
		return nil, fmt.Errorf("error in unmarshaling lookupConfig data, err '%v'", err)
	}

	var lookupPasswd string
	if dbCredFile != "" {
		dbCredentials := make(map[string][]string)
		dbCredData, err := ioutil.ReadFile(dbCredFile)
		if err != nil {
			return nil, fmt.Errorf("Error %s in reading db-credentials-file %s", err, dbCredFile)
		}
		err = json.Unmarshal(dbCredData, &dbCredentials)
		if err != nil {
			return nil, fmt.Errorf("Error in unmarshaling db-credentials-file %s", err)
		}
		if passwd, ok := dbCredentials[lookupConfig.Uname]; ok {
			lookupPasswd = passwd[0]
		}
	}

	lookupConfig.Pass = lookupPasswd
	relog.Info("lookupConfig %v", lookupConfig)
	lookupClient.dbConfig = lookupConfig

	lookupClient.dbConn, err = lookupClient.Connect()
	if err != nil {
		return nil, fmt.Errorf("error in connecting to mysql db, err %v", err)
	}
	return lookupClient, nil
}
Esempio n. 6
0
// NewMysqld creates a Mysqld object based on the provided configuration
// and connection parameters.
// name is the base for stats exports, use 'Dba', except in tests
func NewMysqld(name string, config *Mycnf, dba, repl *mysql.ConnectionParams) *Mysqld {
	if *dba == dbconfigs.DefaultDBConfigs.Dba {
		dba.UnixSocket = config.SocketFile
	}

	// create and open the connection pool for dba access
	mysqlStats := stats.NewTimings("Mysql" + name)
	dbaPool := dbconnpool.NewConnectionPool(name+"ConnPool", *dbaPoolSize, *dbaIdleTimeout)
	dbaPool.Open(dbconnpool.DBConnectionCreator(dba, mysqlStats))

	return &Mysqld{
		config:      config,
		dba:         dba,
		dbaPool:     dbaPool,
		replParams:  repl,
		TabletDir:   TabletDir(config.ServerId),
		SnapshotDir: SnapshotDir(config.ServerId),
	}
}
Esempio n. 7
0
func NewMysqld(config *Mycnf, dba, repl mysql.ConnectionParams) *Mysqld {
	if dba == DefaultDbaParams {
		dba.UnixSocket = config.SocketFile
	}

	// the super connection is not linked to a specific database
	// (allows us to create them)
	superParams := dba
	superParams.DbName = ""
	createSuperConnection := func() (*mysql.Connection, error) {
		return mysql.Connect(superParams)
	}
	return &Mysqld{config,
		dba,
		repl,
		createSuperConnection,
		TabletDir(config.ServerId),
		SnapshotDir(config.ServerId),
	}
}