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

[release-19.0 backport] Mysqld: capture mysqlbinlog std error output (#15278) #15379

Merged
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
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 @@
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 @@
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 @@
}
// 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
Loading