Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mysqlctld: allow setting flags / env vars for mysqld #5730

Merged
merged 2 commits into from
Jan 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ require (
github.com/mattn/go-runewidth v0.0.1 // indirect
github.com/minio/minio-go v0.0.0-20190131015406-c8a261de75c1
github.com/mitchellh/go-testing-interface v1.0.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.1 // indirect
github.com/olekukonko/tablewriter v0.0.0-20160115111002-cca8bbc07984
github.com/opentracing-contrib/go-grpc v0.0.0-20180928155321-4b5a12d3ff02
github.com/opentracing/opentracing-go v1.1.0
Expand Down
76 changes: 48 additions & 28 deletions go/vt/mysqlctl/mysqld.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,18 +267,6 @@ func (mysqld *Mysqld) RunMysqlUpgrade() error {
return nil
}

// Find mysql_upgrade. If not there, we do nothing.
vtMysqlRoot, err := vtenv.VtMysqlRoot()
if err != nil {
log.Warningf("VT_MYSQL_ROOT not set, skipping mysql_upgrade step: %v", err)
return nil
}
name, err := binaryPath(vtMysqlRoot, "mysql_upgrade")
if err != nil {
log.Warningf("mysql_upgrade binary not present, skipping it: %v", err)
return nil
}

// Since we started mysql with --skip-grant-tables, we should
// be able to run mysql_upgrade without any valid user or
// password. However, mysql_upgrade executes a 'flush
Expand All @@ -303,11 +291,26 @@ func (mysqld *Mysqld) RunMysqlUpgrade() error {
"--defaults-file=" + defaultsFile,
"--force", // Don't complain if it's already been upgraded.
}
cmd := exec.Command(name, args...)
libPath := fmt.Sprintf("LD_LIBRARY_PATH=%s/lib/mysql", vtMysqlRoot)
cmd.Env = []string{libPath}
out, err := cmd.CombinedOutput()
log.Infof("mysql_upgrade output: %s", out)

// Find mysql_upgrade. If not there, we do nothing.
vtMysqlRoot, err := vtenv.VtMysqlRoot()
if err != nil {
log.Warningf("VT_MYSQL_ROOT not set, skipping mysql_upgrade step: %v", err)
return nil
}
name, err := binaryPath(vtMysqlRoot, "mysql_upgrade")
if err != nil {
log.Warningf("mysql_upgrade binary not present, skipping it: %v", err)
return nil
}

env, err := buildLdPaths()
if err != nil {
log.Warningf("skipping mysql_upgrade step: %v", err)
return nil
}

_, _, err = execCmd(name, args, env, "", nil)
return err
}

Expand Down Expand Up @@ -367,15 +370,17 @@ func (mysqld *Mysqld) startNoWait(ctx context.Context, cnf *Mycnf, mysqldArgs ..
if err != nil {
return err
}
arg := []string{
args := []string{
"--defaults-file=" + cnf.path,
"--basedir=" + mysqlBaseDir,
}
arg = append(arg, mysqldArgs...)
libPath := fmt.Sprintf("LD_LIBRARY_PATH=%s/lib/mysql", vtMysqlRoot)
env := []string{libPath}
args = append(args, mysqldArgs...)
env, err := buildLdPaths()
if err != nil {
return err
}

cmd := exec.Command(name, arg...)
cmd := exec.Command(name, args...)
cmd.Dir = vtMysqlRoot
cmd.Env = env
log.Infof("%v %#v", ts, cmd)
Expand Down Expand Up @@ -541,13 +546,13 @@ func (mysqld *Mysqld) Shutdown(ctx context.Context, cnf *Mycnf, waitForMysqld bo
"--wait=10",
"shutdown",
}
env := []string{
os.ExpandEnv("LD_LIBRARY_PATH=$VT_MYSQL_ROOT/lib/mysql"),
}
_, _, err = execCmd(name, args, env, dir, nil)
env, err := buildLdPaths()
if err != nil {
return err
}
if _, _, err = execCmd(name, args, env, dir, nil); err != nil {
return err
}
default:
// hook failed, we report error
return fmt.Errorf("mysqld_shutdown hook failed: %v", hr.String())
Expand Down Expand Up @@ -1027,8 +1032,9 @@ func (mysqld *Mysqld) executeMysqlScript(connParams *mysql.ConnParams, sql io.Re
"--defaults-extra-file=" + cnf,
"--batch",
}
env := []string{
"LD_LIBRARY_PATH=" + path.Join(dir, "lib/mysql"),
env, err := buildLdPaths()
if err != nil {
return err
}
_, _, err = execCmd(name, args, env, dir, sql)
if err != nil {
Expand Down Expand Up @@ -1115,3 +1121,17 @@ func (mysqld *Mysqld) OnTerm(f func()) {
defer mysqld.mutex.Unlock()
mysqld.onTermFuncs = append(mysqld.onTermFuncs, f)
}

func buildLdPaths() ([]string, error) {
vtMysqlRoot, err := vtenv.VtMysqlRoot()
if err != nil {
return []string{}, err
}

ldPaths := []string{
fmt.Sprintf("LD_LIBRARY_PATH=%s/lib/mysql", vtMysqlRoot),
os.ExpandEnv("LD_PRELOAD=$LD_PRELOAD"),
}

return ldPaths, nil
}
5 changes: 3 additions & 2 deletions misc/git/commit-msg.signoff
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ echo "Alternatively, you can acknowledge your signoff and continue below:"
echo
echo " ${signoff}"
echo
read -r -p "Do you want to add the above signoff and continue? [y/N] "
echo -n "Do you want to add the above signoff and continue? [y/N] "
read reply

if [[ "${REPLY,,}" != "y" ]]; then
if [[ "${reply}" != "y" ]]; then
exit 1
fi

Expand Down