Skip to content

Support custom MySQL dial network#9

Merged
rebelice merged 2 commits into
mainfrom
codex/support-ssh-dialer
May 12, 2026
Merged

Support custom MySQL dial network#9
rebelice merged 2 commits into
mainfrom
codex/support-ssh-dialer

Conversation

@rebelice
Copy link
Copy Markdown

@rebelice rebelice commented May 12, 2026

Summary

  • Add optional custom connection hooks to mysql.ConnectionConfig so embedded callers can route gh-ost through a caller-managed SSH tunnel.
  • Support Network for go-sql-driver/mysql DSNs instead of always generating @tcp(host:port).
  • Support Dialer for go-mysql-org/go-mysql binlog streamer connections, which do not use database/sql DSNs.
  • Preserve both custom hooks when duplicating connection configs, so inspector, applier, streamer, and replica/throttle connections continue to use the same dial path.
  • Add unit coverage for custom-network DSN generation and duplication behavior.

Usage

Callers that need to route gh-ost connections through an SSH tunnel can register a custom dialer with go-sql-driver/mysql, then assign the registered network name and a go-mysql dialer to the gh-ost connection config:

network := "mysql-tcp-" + uuid.NewString()[:8]
mysql.RegisterDialContext(network, func(ctx context.Context, addr string) (net.Conn, error) {
    return sshClient.Dial("tcp", addr)
})
defer mysql.DeregisterDialContext(network)

dbConfig := migrationContext.InspectorConnectionConfig
dbConfig.Network = network
dbConfig.Dialer = func(ctx context.Context, network, addr string) (net.Conn, error) {
    return sshClient.Dial(network, addr)
}

After this, gh-ost SQL connections build DSNs like:

user:password@mysql-tcp-12345678(db.internal:3306)/dbname?...

This follows the extension model provided by go-sql-driver/mysql: callers register a custom network via RegisterDialContext, then use that network in the DSN as network(address). gh-ost2 also needs the explicit Dialer because binlog streaming uses go-mysql-org/go-mysql, not database/sql.

With this approach, gh-ost2 remains responsible for connection configuration, while the embedding application owns SSH authentication, secret handling, host-key policy, lifecycle, and cleanup.

Test Plan

  • go test ./go/mysql ./go/binlog ./go/base
  • git diff --check

Note: I also tried go test ./go/..., but the full suite did not exit in this local environment, so this PR validates the changed packages plus adjacent pure unit packages.

@rebelice rebelice merged commit ca2794d into main May 12, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants