Merge pull request #23 from github/cnf-file
initial support for config file
This commit is contained in:
commit
bd741371d0
@ -15,6 +15,8 @@ import (
|
|||||||
|
|
||||||
"github.com/github/gh-osc/go/mysql"
|
"github.com/github/gh-osc/go/mysql"
|
||||||
"github.com/github/gh-osc/go/sql"
|
"github.com/github/gh-osc/go/sql"
|
||||||
|
|
||||||
|
"gopkg.in/gcfg.v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
// RowsEstimateMethod is the type of row number estimation
|
// RowsEstimateMethod is the type of row number estimation
|
||||||
@ -41,6 +43,8 @@ type MigrationContext struct {
|
|||||||
AllowedRunningOnMaster bool
|
AllowedRunningOnMaster bool
|
||||||
SwitchToRowBinlogFormat bool
|
SwitchToRowBinlogFormat bool
|
||||||
|
|
||||||
|
ConfigFile string
|
||||||
|
|
||||||
ChunkSize int64
|
ChunkSize int64
|
||||||
MaxLagMillisecondsThrottleThreshold int64
|
MaxLagMillisecondsThrottleThreshold int64
|
||||||
ReplictionLagQuery string
|
ReplictionLagQuery string
|
||||||
@ -224,3 +228,32 @@ func (this *MigrationContext) ReadMaxLoad(maxLoadList string) error {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *MigrationContext) ReadConfigFile() error {
|
||||||
|
if this.ConfigFile == "" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
conf := struct {
|
||||||
|
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
|
||||||
|
}
|
||||||
|
if this.InspectorConnectionConfig.User == "" {
|
||||||
|
this.InspectorConnectionConfig.User = conf.Client.User
|
||||||
|
}
|
||||||
|
if this.InspectorConnectionConfig.Password == "" {
|
||||||
|
this.InspectorConnectionConfig.Password = conf.Client.Password
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
@ -23,6 +23,7 @@ func main() {
|
|||||||
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.InspectorConnectionConfig.User, "user", "root", "MySQL user")
|
||||||
flag.StringVar(&migrationContext.InspectorConnectionConfig.Password, "password", "", "MySQL password")
|
flag.StringVar(&migrationContext.InspectorConnectionConfig.Password, "password", "", "MySQL password")
|
||||||
|
flag.StringVar(&migrationContext.ConfigFile, "conf", "", "Config file")
|
||||||
|
|
||||||
flag.StringVar(&migrationContext.DatabaseName, "database", "", "database name (mandatory)")
|
flag.StringVar(&migrationContext.DatabaseName, "database", "", "database name (mandatory)")
|
||||||
flag.StringVar(&migrationContext.OriginalTableName, "table", "", "table name (mandatory)")
|
flag.StringVar(&migrationContext.OriginalTableName, "table", "", "table name (mandatory)")
|
||||||
@ -93,6 +94,9 @@ func main() {
|
|||||||
if migrationContext.QuickAndBumpySwapTables && migrationContext.TestOnReplica {
|
if migrationContext.QuickAndBumpySwapTables && migrationContext.TestOnReplica {
|
||||||
log.Fatalf("--quick-and-bumpy-swap-tables and --test-on-replica are mutually exclusive (the former implies migrating on master)")
|
log.Fatalf("--quick-and-bumpy-swap-tables and --test-on-replica are mutually exclusive (the former implies migrating on master)")
|
||||||
}
|
}
|
||||||
|
if err := migrationContext.ReadConfigFile(); err != nil {
|
||||||
|
log.Fatale(err)
|
||||||
|
}
|
||||||
if err := migrationContext.ThrottleControlReplicaKeys.ReadCommaDelimitedList(*throttleControlReplicas); err != nil {
|
if err := migrationContext.ThrottleControlReplicaKeys.ReadCommaDelimitedList(*throttleControlReplicas); err != nil {
|
||||||
log.Fatale(err)
|
log.Fatale(err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user