df27c5b76f
Both Percona and Maria allow MySQL to be configured to listen on an extra port when their thread pool is enable. * https://www.percona.com/doc/percona-server/5.7/performance/threadpool.html * https://mariadb.com/kb/en/the-mariadb-library/thread-pool-in-mariadb-51-53/ This is valuable because if the table has a lot of traffic (read or write load), gh-ost can end up starving the thread pool as incomming connections are immediately blocked. By using gh-ost on the extra port, MySQL locking will still behave the same, but MySQL will keep a dedicated thread for each gh-ost connection. When doing this, it's important to inspect the extra-max-connections variable. Both Percona and Maria default to 1, so gh-ost may easily exceed with its threads. An example local run using this ``` $ mysql -S /tmp/mysql_sandbox20393.sock -e "select @@global.port, @@global.extra_port" +---------------+---------------------+ | @@global.port | @@global.extra_port | +---------------+---------------------+ | 20393 | 30393 | +---------------+---------------------+ ./bin/gh-ost \ --initially-drop-ghost-table \ --initially-drop-old-table \ --assume-rbr \ --port="20395" \ --assume-master-host="127.0.0.1:30393" \ --max-load=Threads_running=25 \ --critical-load=Threads_running=1000 \ --chunk-size=1000 \ --max-lag-millis=1500 \ --user="gh-ost" \ --password="gh-ost" \ --database="test" \ --table="mytable" \ --verbose \ --alter="ADD mynewcol decimal(11,2) DEFAULT 0.0 NOT NULL" \ --exact-rowcount \ --concurrent-rowcount \ --default-retries=120 \ --panic-flag-file=/tmp/ghost.panic.flag \ --postpone-cut-over-flag-file=/tmp/ghost.postpone.flag \ --execute ```
79 lines
2.0 KiB
Go
79 lines
2.0 KiB
Go
/*
|
|
Copyright 2016 GitHub Inc.
|
|
See https://github.com/github/gh-ost/blob/master/LICENSE
|
|
*/
|
|
|
|
package base
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"regexp"
|
|
"strings"
|
|
"time"
|
|
|
|
gosql "database/sql"
|
|
"github.com/github/gh-ost/go/mysql"
|
|
"github.com/outbrain/golib/log"
|
|
)
|
|
|
|
var (
|
|
prettifyDurationRegexp = regexp.MustCompile("([.][0-9]+)")
|
|
)
|
|
|
|
func PrettifyDurationOutput(d time.Duration) string {
|
|
if d < time.Second {
|
|
return "0s"
|
|
}
|
|
result := fmt.Sprintf("%s", d)
|
|
result = prettifyDurationRegexp.ReplaceAllString(result, "")
|
|
return result
|
|
}
|
|
|
|
func FileExists(fileName string) bool {
|
|
if _, err := os.Stat(fileName); err == nil {
|
|
return true
|
|
}
|
|
return false
|
|
}
|
|
|
|
// StringContainsAll returns true if `s` contains all non empty given `substrings`
|
|
// The function returns `false` if no non-empty arguments are given.
|
|
func StringContainsAll(s string, substrings ...string) bool {
|
|
nonEmptyStringsFound := false
|
|
for _, substring := range substrings {
|
|
if substring == "" {
|
|
continue
|
|
}
|
|
if strings.Contains(s, substring) {
|
|
nonEmptyStringsFound = true
|
|
} else {
|
|
// Immediate failure
|
|
return false
|
|
}
|
|
}
|
|
return nonEmptyStringsFound
|
|
}
|
|
|
|
func ValidateConnection(db *gosql.DB, connectionConfig *mysql.ConnectionConfig) (string, error) {
|
|
query := `select @@global.port, @@global.version`
|
|
var port, extraPort int
|
|
var version string
|
|
if err := db.QueryRow(query).Scan(&port, &version); err != nil {
|
|
return "", err
|
|
}
|
|
extraPortQuery := `select @@global.extra_port`
|
|
if err := db.QueryRow(extraPortQuery).Scan(&extraPort); err != nil {
|
|
// swallow this error. not all servers support extra_port
|
|
}
|
|
|
|
if connectionConfig.Key.Port == port || (extraPort > 0 && connectionConfig.Key.Port == extraPort) {
|
|
log.Infof("connection validated on %+v", connectionConfig.Key)
|
|
return version, nil
|
|
} else if extraPort == 0 {
|
|
return "", fmt.Errorf("Unexpected database port reported: %+v", port)
|
|
} else {
|
|
return "", fmt.Errorf("Unexpected database port reported: %+v / extra_port: %+v", port, extraPort)
|
|
}
|
|
}
|