Merge pull request #38 from github/credentials-config-cli
This closes #25
This commit is contained in:
commit
55e463350b
2
build.sh
2
build.sh
@ -1,7 +1,7 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
RELEASE_VERSION="0.7.2"
|
RELEASE_VERSION="0.7.3"
|
||||||
|
|
||||||
buildpath=/tmp/gh-ost
|
buildpath=/tmp/gh-ost
|
||||||
target=gh-ost
|
target=gh-ost
|
||||||
|
@ -43,7 +43,11 @@ type MigrationContext struct {
|
|||||||
AllowedRunningOnMaster bool
|
AllowedRunningOnMaster bool
|
||||||
SwitchToRowBinlogFormat bool
|
SwitchToRowBinlogFormat bool
|
||||||
|
|
||||||
ConfigFile string
|
config ContextConfig
|
||||||
|
configMutex *sync.Mutex
|
||||||
|
ConfigFile string
|
||||||
|
CliUser string
|
||||||
|
CliPassword string
|
||||||
|
|
||||||
ChunkSize int64
|
ChunkSize int64
|
||||||
MaxLagMillisecondsThrottleThreshold int64
|
MaxLagMillisecondsThrottleThreshold int64
|
||||||
@ -96,6 +100,19 @@ type MigrationContext struct {
|
|||||||
CanStopStreaming func() bool
|
CanStopStreaming func() bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ContextConfig struct {
|
||||||
|
Client struct {
|
||||||
|
User string
|
||||||
|
Password string
|
||||||
|
}
|
||||||
|
Osc struct {
|
||||||
|
Chunk_Size int64
|
||||||
|
Max_Lag_Millis int64
|
||||||
|
Replication_Lag_Query string
|
||||||
|
Max_Load string
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var context *MigrationContext
|
var context *MigrationContext
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -112,6 +129,7 @@ func newMigrationContext() *MigrationContext {
|
|||||||
MaxLoad: make(map[string]int64),
|
MaxLoad: make(map[string]int64),
|
||||||
throttleMutex: &sync.Mutex{},
|
throttleMutex: &sync.Mutex{},
|
||||||
ThrottleControlReplicaKeys: mysql.NewInstanceKeyMap(),
|
ThrottleControlReplicaKeys: mysql.NewInstanceKeyMap(),
|
||||||
|
configMutex: &sync.Mutex{},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -210,6 +228,8 @@ func (this *MigrationContext) IsThrottled() (bool, string) {
|
|||||||
return this.isThrottled, this.throttleReason
|
return this.isThrottled, this.throttleReason
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ReadMaxLoad parses the `--max-load` flag, which is in multiple key-value format,
|
||||||
|
// such as: 'Threads_running=100,Threads_connected=500'
|
||||||
func (this *MigrationContext) ReadMaxLoad(maxLoadList string) error {
|
func (this *MigrationContext) ReadMaxLoad(maxLoadList string) error {
|
||||||
if maxLoadList == "" {
|
if maxLoadList == "" {
|
||||||
return nil
|
return nil
|
||||||
@ -232,31 +252,37 @@ func (this *MigrationContext) ReadMaxLoad(maxLoadList string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ApplyCredentials sorts out the credentials between the config file and the CLI flags
|
||||||
|
func (this *MigrationContext) ApplyCredentials() {
|
||||||
|
this.configMutex.Lock()
|
||||||
|
defer this.configMutex.Unlock()
|
||||||
|
|
||||||
|
if this.config.Client.User != "" {
|
||||||
|
this.InspectorConnectionConfig.User = this.config.Client.User
|
||||||
|
}
|
||||||
|
if this.CliUser != "" {
|
||||||
|
// Override
|
||||||
|
this.InspectorConnectionConfig.User = this.CliUser
|
||||||
|
}
|
||||||
|
if this.config.Client.Password != "" {
|
||||||
|
this.InspectorConnectionConfig.Password = this.config.Client.Password
|
||||||
|
}
|
||||||
|
if this.CliPassword != "" {
|
||||||
|
// Override
|
||||||
|
this.InspectorConnectionConfig.Password = this.CliPassword
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ReadConfigFile attempts to read the config file, if it exists
|
||||||
func (this *MigrationContext) ReadConfigFile() error {
|
func (this *MigrationContext) ReadConfigFile() error {
|
||||||
|
this.configMutex.Lock()
|
||||||
|
defer this.configMutex.Unlock()
|
||||||
|
|
||||||
if this.ConfigFile == "" {
|
if this.ConfigFile == "" {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
conf := struct {
|
if err := gcfg.ReadFileInto(&this.config, this.ConfigFile); err != nil {
|
||||||
Client struct {
|
|
||||||
User string
|
|
||||||
Password string
|
|
||||||
}
|
|
||||||
Osc struct {
|
|
||||||
Chunk_Size int64
|
|
||||||
Max_Lag_Millis int64
|
|
||||||
Replication_Lag_Query string
|
|
||||||
Max_Load string
|
|
||||||
}
|
|
||||||
}{}
|
|
||||||
if err := gcfg.ReadFileInto(&conf, this.ConfigFile); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if this.InspectorConnectionConfig.User == "" {
|
|
||||||
this.InspectorConnectionConfig.User = conf.Client.User
|
|
||||||
}
|
|
||||||
if this.InspectorConnectionConfig.Password == "" {
|
|
||||||
this.InspectorConnectionConfig.Password = conf.Client.Password
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -23,8 +23,8 @@ func main() {
|
|||||||
|
|
||||||
flag.StringVar(&migrationContext.InspectorConnectionConfig.Key.Hostname, "host", "127.0.0.1", "MySQL hostname (preferably a replica, not the master)")
|
flag.StringVar(&migrationContext.InspectorConnectionConfig.Key.Hostname, "host", "127.0.0.1", "MySQL hostname (preferably a replica, not the master)")
|
||||||
flag.IntVar(&migrationContext.InspectorConnectionConfig.Key.Port, "port", 3306, "MySQL port (preferably a replica, not the master)")
|
flag.IntVar(&migrationContext.InspectorConnectionConfig.Key.Port, "port", 3306, "MySQL port (preferably a replica, not the master)")
|
||||||
flag.StringVar(&migrationContext.InspectorConnectionConfig.User, "user", "root", "MySQL user")
|
flag.StringVar(&migrationContext.CliUser, "user", "", "MySQL user")
|
||||||
flag.StringVar(&migrationContext.InspectorConnectionConfig.Password, "password", "", "MySQL password")
|
flag.StringVar(&migrationContext.CliPassword, "password", "", "MySQL password")
|
||||||
flag.StringVar(&migrationContext.ConfigFile, "conf", "", "Config file")
|
flag.StringVar(&migrationContext.ConfigFile, "conf", "", "Config file")
|
||||||
|
|
||||||
flag.StringVar(&migrationContext.DatabaseName, "database", "", "database name (mandatory)")
|
flag.StringVar(&migrationContext.DatabaseName, "database", "", "database name (mandatory)")
|
||||||
@ -118,6 +118,7 @@ func main() {
|
|||||||
if err := migrationContext.ReadMaxLoad(*maxLoad); err != nil {
|
if err := migrationContext.ReadMaxLoad(*maxLoad); err != nil {
|
||||||
log.Fatale(err)
|
log.Fatale(err)
|
||||||
}
|
}
|
||||||
|
migrationContext.ApplyCredentials()
|
||||||
|
|
||||||
log.Infof("starting gh-ost %+v", AppVersion)
|
log.Infof("starting gh-ost %+v", AppVersion)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user