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 <[email protected]>
  • Loading branch information
shlomi-noach committed Feb 28, 2024
1 parent b2291f6 commit 3581155
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

Check warning on line 1253 in go/vt/mysqlctl/mysqld.go

View check run for this annotation

Codecov / codecov/patch

go/vt/mysqlctl/mysqld.go#L1253

Added line #L1253 was not covered by tests
{
name, err := binaryPath(dir, "mysqlbinlog")
if err != nil {
return err
}
mysqlbinlogErrFile, err = os.CreateTemp("", "err-mysqlbinlog-")
if err != nil {
return err

Check warning on line 1261 in go/vt/mysqlctl/mysqld.go

View check run for this annotation

Codecov / codecov/patch

go/vt/mysqlctl/mysqld.go#L1259-L1261

Added lines #L1259 - L1261 were not covered by tests
}
defer os.Remove(mysqlbinlogErrFile.Name())

Check warning on line 1263 in go/vt/mysqlctl/mysqld.go

View check run for this annotation

Codecov / codecov/patch

go/vt/mysqlctl/mysqld.go#L1263

Added line #L1263 was not covered by tests

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())

Check warning on line 1285 in go/vt/mysqlctl/mysqld.go

View check run for this annotation

Codecov / codecov/patch

go/vt/mysqlctl/mysqld.go#L1284-L1285

Added lines #L1284 - L1285 were not covered by tests
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))

Check warning on line 1358 in go/vt/mysqlctl/mysqld.go

View check run for this annotation

Codecov / codecov/patch

go/vt/mysqlctl/mysqld.go#L1355-L1358

Added lines #L1355 - L1358 were not covered by tests
}
}
return vterrors.Wrapf(err, "mysqlbinlog command failed")
}
if err := mysqlCmd.Wait(); err != nil {
Expand Down

0 comments on commit 3581155

Please sign in to comment.