diff --git a/go.mod b/go.mod index 8790f55267b..ce41186d11b 100644 --- a/go.mod +++ b/go.mod @@ -95,6 +95,7 @@ require ( github.com/aws/aws-sdk-go-v2/feature/s3/transfermanager v0.1.15 github.com/aws/aws-sdk-go-v2/service/s3 v1.99.0 github.com/aws/smithy-go v1.24.3 + github.com/block/mysql v0.0.0-20260906201522-a3178f8dca69 github.com/bndr/gotabulate v1.1.2 github.com/brianvoe/gofakeit/v7 v7.14.1 github.com/dustin/go-humanize v1.0.1 @@ -121,7 +122,7 @@ require ( ) require ( - filippo.io/edwards25519 v1.1.1 // indirect + filippo.io/edwards25519 v1.2.0 // indirect github.com/DataDog/datadog-agent/comp/core/tagger/origindetection v0.77.3 // indirect github.com/DataDog/datadog-agent/pkg/opentelemetry-mapping-go/otlp/attributes v0.77.3 // indirect github.com/DataDog/datadog-agent/pkg/proto v0.77.3 // indirect diff --git a/go.sum b/go.sum index c7ac3a916e3..9b46bc801d8 100644 --- a/go.sum +++ b/go.sum @@ -22,8 +22,8 @@ cloud.google.com/go/storage v1.62.1 h1:Os0G3XbUbjZumkpDUf2Y0rLoXJTCF1kU2kWUujKYX cloud.google.com/go/storage v1.62.1/go.mod h1:cpYz/kRVZ+UQAF1uHeea10/9ewcRbxGoGNKsS9daSXA= cloud.google.com/go/trace v1.13.0 h1:RfqsqPOiSCG8ql50UZt5F65KrVa1zbY9mJrO7xvZfbE= cloud.google.com/go/trace v1.13.0/go.mod h1:r+bdAn16dKLSV1G2D5v3e58IlQlizfxWrUfjx7kM7X0= -filippo.io/edwards25519 v1.1.1 h1:YpjwWWlNmGIDyXOn8zLzqiD+9TyIlPhGFG96P39uBpw= -filippo.io/edwards25519 v1.1.1/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= +filippo.io/edwards25519 v1.2.0 h1:crnVqOiS4jqYleHd9vaKZ+HKtHfllngJIiOpNpoJsjo= +filippo.io/edwards25519 v1.2.0/go.mod h1:xzAOLCNug/yB62zG1bQ8uziwrIqIuxhctzJT18Q77mc= github.com/AdaLogics/go-fuzz-headers v0.0.0-20240806141605-e8a1dd7889d6 h1:He8afgbRMd7mFxO99hRNu+6tazq8nFF9lIwo9JFroBk= github.com/AdaLogics/go-fuzz-headers v0.0.0-20240806141605-e8a1dd7889d6/go.mod h1:8o94RPi1/7XTJvwPpRSzSUedZrtlirdB3r9Z20bi2f8= github.com/Azure/azure-pipeline-go v0.2.3 h1:7U9HBg1JFK3jHl5qmo4CTZKFTVgMwdFHMVtCdfBE21U= @@ -156,6 +156,8 @@ github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/bitfield/gotestdox v0.2.2 h1:x6RcPAbBbErKLnapz1QeAlf3ospg8efBsedU93CDsnE= github.com/bitfield/gotestdox v0.2.2/go.mod h1:D+gwtS0urjBrzguAkTM2wodsTQYFHdpx8eqRJ3N+9pY= +github.com/block/mysql v0.0.0-20260906201522-a3178f8dca69 h1:rCWVZKT5PdrdfosvMavnnfUBAdtaM3iepvADt5pMSJI= +github.com/block/mysql v0.0.0-20260906201522-a3178f8dca69/go.mod h1:KEo73lbxXs9cFlq+x3Z35UqGg3MTxAPfjDOR/ob/iik= github.com/bndr/gotabulate v1.1.2 h1:yC9izuZEphojb9r+KYL4W9IJKO/ceIO8HDwxMA24U4c= github.com/bndr/gotabulate v1.1.2/go.mod h1:0+8yUgaPTtLRTjf49E8oju7ojpU11YmXyvq1LbPAb3U= github.com/brianvoe/gofakeit/v7 v7.14.1 h1:a7fe3fonbj0cW3wgl5VwIKfZtiH9C3cLnwcIXWT7sow= diff --git a/go/vt/topo/mysqltopo/main_test.go b/go/vt/topo/mysqltopo/main_test.go index b90efc1708f..3b6d9f8ed6f 100644 --- a/go/vt/topo/mysqltopo/main_test.go +++ b/go/vt/topo/mysqltopo/main_test.go @@ -26,7 +26,7 @@ import ( "path" "testing" - "github.com/go-sql-driver/mysql" + "github.com/block/mysql" "github.com/stretchr/testify/require" "go.uber.org/goleak" @@ -125,7 +125,7 @@ func createTestServer(t *testing.T, schemaName string) (*Server, string, func()) schemaName = generateRandomSchemaName() } cfg.DBName = "" // to create schema - baseDB, err := sql.Open("mysql", cfg.FormatDSN()) + baseDB, err := sql.Open(driverName, cfg.FormatDSN()) require.NoError(t, err) _, err = baseDB.Exec(fmt.Sprintf("CREATE DATABASE IF NOT EXISTS `%s`", schemaName)) diff --git a/go/vt/topo/mysqltopo/notification.go b/go/vt/topo/mysqltopo/notification.go index cb266be50eb..cbd3821fc9a 100644 --- a/go/vt/topo/mysqltopo/notification.go +++ b/go/vt/topo/mysqltopo/notification.go @@ -29,7 +29,7 @@ import ( "sync/atomic" "time" - mysqldriver "github.com/go-sql-driver/mysql" + mysqldriver "github.com/block/mysql" "vitess.io/vitess/go/mysql" "vitess.io/vitess/go/mysql/replication" @@ -209,7 +209,7 @@ func newNotificationSystem(schemaName, serverAddr string) (*notificationSystem, cfg.TLSConfig = "rds-topo" } - db, err := sql.Open("mysql", cfg.FormatDSN()) + db, err := sql.Open(driverName, cfg.FormatDSN()) if err != nil { return nil, fmt.Errorf("failed to connect to MySQL: %v", err) } @@ -236,7 +236,7 @@ func newNotificationSystem(schemaName, serverAddr string) (*notificationSystem, // Create connection parameters for binlog streaming cfg.DBName = schemaName - // Parse host and port from cfg.Addr. The go-sql-driver/mysql DSN allows + // Parse host and port from cfg.Addr. The driver's DSN format allows // addresses without a port (e.g. `tcp(localhost)/db`); fall back to the // default MySQL port in that case. host, portStr, err := net.SplitHostPort(cfg.Addr) diff --git a/go/vt/topo/mysqltopo/notification_test.go b/go/vt/topo/mysqltopo/notification_test.go index 9ee3a5bd884..ebfb21862de 100644 --- a/go/vt/topo/mysqltopo/notification_test.go +++ b/go/vt/topo/mysqltopo/notification_test.go @@ -56,7 +56,7 @@ import ( "testing" "time" - "github.com/go-sql-driver/mysql" + "github.com/block/mysql" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -765,7 +765,7 @@ func TestNotificationSystemReconnection(t *testing.T) { require.Equal(t, initialData, current.Contents) // Create a separate connection to monitor and kill connections - monitorDB, err := sql.Open("mysql", mySQLTopoTestAddr) + monitorDB, err := sql.Open(driverName, mySQLTopoTestAddr) require.NoError(t, err) defer monitorDB.Close() diff --git a/go/vt/topo/mysqltopo/server.go b/go/vt/topo/mysqltopo/server.go index cc3c8e66640..3db61d772b7 100644 --- a/go/vt/topo/mysqltopo/server.go +++ b/go/vt/topo/mysqltopo/server.go @@ -51,7 +51,14 @@ import ( "sync" "time" - "github.com/go-sql-driver/mysql" + // Block's fork of go-sql-driver/mysql, registered as "block-mysql". strata + // links the fork for capabilities upstream does not carry; this package + // follows so that every *sql.DB it opens is served by the same driver whose + // *mysql.MySQLError type convertError below asserts on. That is a statement + // about this package, not about the binary: elsewhere in the repo, end-to-end + // tests still import upstream, and an error crossing from one of those would + // not match the assertion. + "github.com/block/mysql" "github.com/spf13/pflag" "vitess.io/vitess/go/mysql/sqlerror" @@ -62,6 +69,13 @@ import ( ) const ( + // driverName is the database/sql driver every connection in this package is + // opened with. It has to be block/mysql's registered name and not upstream's + // "mysql": convertError asserts on block/mysql's *mysql.MySQLError, and a + // *sql.DB opened with a different driver would return a type that assertion + // silently misses. + driverName = "block-mysql" + // DefaultSchema is the default database schema name for MySQL topo DefaultSchema = "topo" @@ -269,7 +283,7 @@ func connect(cfg *mysql.Config) (*sql.DB, error) { cfg.TLSConfig = "rds-topo" } - db, err := sql.Open("mysql", cfg.FormatDSN()) + db, err := sql.Open(driverName, cfg.FormatDSN()) if err != nil { return nil, fmt.Errorf("failed to connect to MySQL topo at %s (schema %q, user %q): %v", cfg.Addr, cfg.DBName, cfg.User, err) } @@ -539,7 +553,7 @@ func convertError(err error, path string) error { return topo.NewError(topo.NoNode, path) } - // Handle MySQL-specific errors. go-sql-driver returns *mysql.MySQLError, + // Handle MySQL-specific errors. block-mysql returns *mysql.MySQLError, // which carries the server error number directly; its message format // ("Error 1062 (23000): ...") is not recognized by // sqlerror.NewSQLErrorFromError, so check the typed error first and only diff --git a/go/vt/topo/mysqltopo/server_error_test.go b/go/vt/topo/mysqltopo/server_error_test.go index 7dc3ac7ab6f..d91d3d1ec25 100644 --- a/go/vt/topo/mysqltopo/server_error_test.go +++ b/go/vt/topo/mysqltopo/server_error_test.go @@ -24,7 +24,7 @@ import ( "sync" "testing" - "github.com/go-sql-driver/mysql" + "github.com/block/mysql" "github.com/stretchr/testify/require" "vitess.io/vitess/go/vt/topo" diff --git a/go/vt/topo/mysqltopo/server_resolve_test.go b/go/vt/topo/mysqltopo/server_resolve_test.go index e2049083025..e24da312761 100644 --- a/go/vt/topo/mysqltopo/server_resolve_test.go +++ b/go/vt/topo/mysqltopo/server_resolve_test.go @@ -22,7 +22,7 @@ import ( "net" "testing" - "github.com/go-sql-driver/mysql" + "github.com/block/mysql" "github.com/stretchr/testify/require" ) @@ -36,7 +36,7 @@ func newRawSchema(t *testing.T) (baseDB *sql.DB, schemaDSN, schemaName string, c schemaName = generateRandomSchemaName() cfg.DBName = "" - baseDB, err = sql.Open("mysql", cfg.FormatDSN()) + baseDB, err = sql.Open(driverName, cfg.FormatDSN()) require.NoError(t, err) _, err = baseDB.Exec(fmt.Sprintf("CREATE DATABASE IF NOT EXISTS `%s`", schemaName)) require.NoError(t, err)