Commit 8946fab9 authored by Szabolcs Gyurko's avatar Szabolcs Gyurko
Browse files

Added new CLI control options

parent 69a3719b
......@@ -33,6 +33,10 @@ var (
stdoutMutex sync.Mutex
processWaitGroup sync.WaitGroup
databases []string
singleThreaded *bool
perDBConcurrency *bool
maxIdleConnections *int
maxConnectionLifetime *int
)
// Prints out usage help
......@@ -313,8 +317,12 @@ func openDatabase(connectionString string) (*sql.DB, error) {
if err != nil {
return nil, err
}
db.SetMaxIdleConns(0)
db.SetConnMaxLifetime(time.Second * 3600)
if maxIdleConnections != nil && *maxIdleConnections != -1 {
db.SetMaxIdleConns(*maxIdleConnections)
}
if maxConnectionLifetime != nil && *maxConnectionLifetime != -1 {
db.SetConnMaxLifetime(time.Duration(*maxConnectionLifetime) * time.Second)
}
err = db.Ping()
if err != nil {
......@@ -355,6 +363,11 @@ func dumpDatabase(database string, tables []string, username, password, host *st
// Start the sender and receiver
go dumpTable(*username + ":" + *password + "@tcp(" + *host+")/" + database, database, tables[t], channels[t])
go processOutput(channels[t])
if singleThreaded != nil && *singleThreaded {
// Wait for the concurrent dumps to complete (which is one table atm.)
processWaitGroup.Wait()
}
}
}
}
......@@ -392,6 +405,10 @@ func main() {
username := flag.String("u", "", "MySQL username")
password := flag.String("p", "", "MySQL password")
host := flag.String("h", "localhost", "MySQL host")
singleThreaded = flag.Bool("s", false, "No concurrency, process everything sequentially")
perDBConcurrency = flag.Bool("c", false, "Fully concurrent execution across DBs (if false all table dumps will be concurrent within a DB, but DBs are processed sequentially)")
maxIdleConnections = flag.Int("i", -1, "Max MySQL idle connections (-1 means default by the driver)")
maxConnectionLifetime = flag.Int("l", -1, "Max MySQL connection lifetime in seconds (-1 means default by driver)")
flag.Parse()
if *username == "" && *password == "" {
......@@ -446,12 +463,17 @@ func main() {
for i := range databases {
if anonimyser.IsValidDatabase(databases[i]) {
dumpDatabase(databases[i], tables, username, password, host)
}
if perDBConcurrency != nil && *perDBConcurrency {
// Wait for the concurrent dumps to complete
processWaitGroup.Wait()
}
}
// Wait for the concurrent dumps to complete
processWaitGroup.Wait()
// MySQL specific stuff to restore key checks and alike
fmt.Println("/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;")
fmt.Println("/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment