Skip to content

Commit

Permalink
missing file
Browse files Browse the repository at this point in the history
Signed-off-by: Tim Vaillancourt <[email protected]>
  • Loading branch information
timvaillancourt committed Jan 15, 2024
1 parent 83f0cc1 commit 1b158a4
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions go/mysql/server_info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
Copyright 2023 GitHub Inc.
See https://github.com/github/gh-ost/blob/master/LICENSE
*/

package mysql

import gosql "database/sql"

// ServerInfo represents the online config of a MySQL server.
type ServerInfo struct {
Version string
VersionComment string
Hostname string
Port gosql.NullInt64
BinlogFormat string
BinlogRowImage string
LogBin bool
LogSlaveUpdates bool
SQLMode string
TimeZone string

// @@global.extra_port is Percona/MariaDB-only
ExtraPort gosql.NullInt64
}

// GetServerInfo returns a ServerInfo struct representing
// the online config of a MySQL server.
func GetServerInfo(db *gosql.DB) (*ServerInfo, error) {
var info ServerInfo
query := `select /* gh-ost */ @@global.version, @@global.version_comment, @@global.hostname,
@@global.port, @@global.binlog_format, @@global.binlog_row_image, @@global.log_bin,
@@global.log_slave_updates, @@global.sql_mode, @@global.time_zone`
if err := db.QueryRow(query).Scan(&info.Version, &info.VersionComment, &info.Hostname,
&info.Port, &info.BinlogFormat, &info.BinlogRowImage, &info.LogBin,
&info.LogSlaveUpdates, &info.SQLMode, &info.TimeZone,
); err != nil {
return nil, err
}

extraPortQuery := `select @@global.extra_port`
// swallow possible error. not all servers support extra_port
_ = db.QueryRow(extraPortQuery).Scan(&info.ExtraPort)

return &info, nil
}

0 comments on commit 1b158a4

Please sign in to comment.