Skip to content

Commit

Permalink
[release-19.0 backport] Mysqld: capture mysqlbinlog std error output (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
shlomi-noach authored Mar 5, 2024
1 parent da09dc8 commit e19177b
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 e19177b

Please sign in to comment.