From e19177bf9d4fc0b63841088e2d868c2e10076901 Mon Sep 17 00:00:00 2001 From: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com> Date: Tue, 5 Mar 2024 16:38:21 +0200 Subject: [PATCH] [release-19.0 backport] Mysqld: capture mysqlbinlog std error output (#15278) (#15379) --- go/vt/mysqlctl/mysqld.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/go/vt/mysqlctl/mysqld.go b/go/vt/mysqlctl/mysqld.go index 6de6425925e..f19cc681df7 100644 --- a/go/vt/mysqlctl/mysqld.go +++ b/go/vt/mysqlctl/mysqld.go @@ -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, @@ -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 @@ -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 {