MCPcopy
hub / github.com/github/gh-ost / ValidateConnection

Function ValidateConnection

go/base/utils.go:64–104  ·  view source on GitHub ↗
(db *gosql.DB, connectionConfig *mysql.ConnectionConfig, migrationContext *MigrationContext, name string)

Source from the content-addressed store, hash-verified

62}
63
64func ValidateConnection(db *gosql.DB, connectionConfig *mysql.ConnectionConfig, migrationContext *MigrationContext, name string) (string, error) {
65 versionQuery := `select @@global.version`
66
67 var version string
68 if err := db.QueryRow(versionQuery).Scan(&version); err != nil {
69 return "", err
70 }
71
72 if migrationContext.SkipPortValidation {
73 return version, nil
74 }
75
76 var extraPort int
77
78 extraPortQuery := `select @@global.extra_port`
79 if err := db.QueryRow(extraPortQuery).Scan(&extraPort); err != nil { //nolint:staticcheck
80 // swallow this error. not all servers support extra_port
81 }
82
83 // AliyunRDS set users port to "NULL", replace it by gh-ost param
84 // GCP set users port to "NULL", replace it by gh-ost param
85 // Azure MySQL set users port to a different value by design, replace it by gh-ost para
86 var port int
87 if migrationContext.AliyunRDS || migrationContext.GoogleCloudPlatform || migrationContext.AzureMySQL {
88 port = connectionConfig.Key.Port
89 } else {
90 portQuery := `select @@global.port`
91 if err := db.QueryRow(portQuery).Scan(&port); err != nil {
92 return "", err
93 }
94 }
95
96 if connectionConfig.Key.Port == port || (extraPort > 0 && connectionConfig.Key.Port == extraPort) {
97 migrationContext.Log.Infof("%s connection validated on %+v", name, connectionConfig.Key)
98 return version, nil
99 } else if extraPort == 0 {
100 return "", fmt.Errorf("unexpected database port reported: %+v", port)
101 } else {
102 return "", fmt.Errorf("unexpected database port reported: %+v / extra_port: %+v", port, extraPort)
103 }
104}

Callers 3

validateConnectionMethod · 0.92
InitDBConnectionsMethod · 0.92
InitDBConnectionsMethod · 0.92

Calls 2

InfofMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…