Skip to content

Commit

Permalink
Mysqld: capture mysqlbinlog std error output (#15278)
Browse files Browse the repository at this point in the history
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
  • Loading branch information
shlomi-noach committed Feb 19, 2024
1 parent 54c6dfc commit f38dab3
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion go/vt/mysqlctl/mysqld.go
Original file line number Diff line number Diff line change
Expand Up @@ -1250,11 +1250,18 @@ func (mysqld *Mysqld) ApplyBinlogFile(ctx context.Context, req *mysqlctlpb.Apply
if err != nil {
return err
}
var mysqlbinlogErrFile *os.File
{
name, err := binaryPath(dir, "mysqlbinlog")
if err != nil {
return err
}
mysqlbinlogErrFile, err = os.CreateTemp("", "err-mysqlbinlog-")
if err != nil {
return err
}
defer os.Remove(mysqlbinlogErrFile.Name())

args := []string{}
if gtids := req.BinlogRestorePosition; gtids != "" {
args = append(args,
Expand All @@ -1274,7 +1281,8 @@ func (mysqld *Mysqld) ApplyBinlogFile(ctx context.Context, req *mysqlctlpb.Apply
mysqlbinlogCmd = exec.Command(name, args...)
mysqlbinlogCmd.Dir = dir
mysqlbinlogCmd.Env = env
log.Infof("ApplyBinlogFile: running mysqlbinlog command: %#v", mysqlbinlogCmd)
mysqlbinlogCmd.Stderr = mysqlbinlogErrFile
log.Infof("ApplyBinlogFile: running mysqlbinlog command: %#v with errfile=%v", mysqlbinlogCmd, mysqlbinlogErrFile.Name())
pipe, err = mysqlbinlogCmd.StdoutPipe() // to be piped into mysql
if err != nil {
return err
Expand Down Expand Up @@ -1344,6 +1352,12 @@ func (mysqld *Mysqld) ApplyBinlogFile(ctx context.Context, req *mysqlctlpb.Apply
}
// Wait for both to complete:
if err := mysqlbinlogCmd.Wait(); err != nil {
if mysqlbinlogErrFile != nil {
errFileContent, _ := os.ReadFile(mysqlbinlogErrFile.Name())
if len(errFileContent) > 0 {
err = vterrors.Wrapf(err, "with error output: %s", string(errFileContent))
}
}
return vterrors.Wrapf(err, "mysqlbinlog command failed")
}
if err := mysqlCmd.Wait(); err != nil {
Expand Down

0 comments on commit f38dab3

Please sign in to comment.