Skip to content

Commit

Permalink
Merge pull request #295 from HemeraOne/master
Browse files Browse the repository at this point in the history
Fix implementation of SHOW SLAVE HOSTS for different mysql versions
  • Loading branch information
shuhaowu authored Jul 8, 2021
2 parents e605f11 + 94150c5 commit 459b862
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion binlog_streamer.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,8 +455,23 @@ func idsOnServer(db *sql.DB) ([]uint32, error) {
for rows.Next() {
var server_id uint32
var host, port, master_id, slave_uuid sqlorig.NullString
var columns []string

err = rows.Scan(&server_id, &host, &port, &master_id, &slave_uuid)
columns, err = rows.Columns()


// SHOW SLAVE HOSTS has a different return value for different implementations
// i.e MySQL/Percona have 5 columns as it includes slave_uuid for MariaDB slave_uuid is omitted
// since all other values are not used check for the amount of columns and gather only what is possible
if err != nil {
return nil, fmt.Errorf("could not get columns from slave hosts: %v", err)
} else if len(columns) == 5 {
err = rows.Scan(&server_id, &host, &port, &master_id, &slave_uuid)
} else if len(columns) == 4 {
err = rows.Scan(&server_id, &host, &port, &master_id)
} else {
return nil, fmt.Errorf("could not scan SHOW SLAVE HOSTS row, err: unknown result set with %d columns: %v", len(columns), columns)
}
if err != nil {
return nil, fmt.Errorf("could not scan SHOW SLAVE HOSTS row, err: %s", err.Error())
}
Expand Down

0 comments on commit 459b862

Please sign in to comment.