From 4d4793d0d7563c21dd0d57809525586b44839229 Mon Sep 17 00:00:00 2001 From: Dirkjan Bussink Date: Mon, 18 Mar 2024 09:42:10 +0100 Subject: [PATCH] Remove unneeded loading of the MySQL driver (#15502) Signed-off-by: Dirkjan Bussink --- go/cmd/vtorc/main.go | 3 --- .../vtgate/queries/timeout/timeout_test.go | 1 - .../vtorc/readtopologyinstance/main_test.go | 2 -- go/vt/external/golib/sqlutils/sqlutils.go | 14 +++++--------- go/vt/vtorc/inst/keyspace_dao_test.go | 1 - go/vt/vtorc/inst/shard_dao_test.go | 1 - go/vt/vtorc/logic/keyspace_shard_discovery_test.go | 1 - 7 files changed, 5 insertions(+), 18 deletions(-) diff --git a/go/cmd/vtorc/main.go b/go/cmd/vtorc/main.go index 101265b16c5..c85d51e9325 100644 --- a/go/cmd/vtorc/main.go +++ b/go/cmd/vtorc/main.go @@ -17,9 +17,6 @@ package main import ( - _ "github.com/go-sql-driver/mysql" - _ "modernc.org/sqlite" - "vitess.io/vitess/go/cmd/vtorc/cli" "vitess.io/vitess/go/vt/log" ) diff --git a/go/test/endtoend/vtgate/queries/timeout/timeout_test.go b/go/test/endtoend/vtgate/queries/timeout/timeout_test.go index 9c81a6c5822..bab9699d027 100644 --- a/go/test/endtoend/vtgate/queries/timeout/timeout_test.go +++ b/go/test/endtoend/vtgate/queries/timeout/timeout_test.go @@ -19,7 +19,6 @@ package misc import ( "testing" - _ "github.com/go-sql-driver/mysql" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" diff --git a/go/test/endtoend/vtorc/readtopologyinstance/main_test.go b/go/test/endtoend/vtorc/readtopologyinstance/main_test.go index e3b55d64c6b..78e4f4dfcda 100644 --- a/go/test/endtoend/vtorc/readtopologyinstance/main_test.go +++ b/go/test/endtoend/vtorc/readtopologyinstance/main_test.go @@ -30,10 +30,8 @@ import ( "vitess.io/vitess/go/vt/vtorc/logic" "vitess.io/vitess/go/vt/vtorc/server" - _ "github.com/go-sql-driver/mysql" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - _ "modernc.org/sqlite" ) func TestReadTopologyInstanceBufferable(t *testing.T) { diff --git a/go/vt/external/golib/sqlutils/sqlutils.go b/go/vt/external/golib/sqlutils/sqlutils.go index eb1cb8c8941..c88af1176b1 100644 --- a/go/vt/external/golib/sqlutils/sqlutils.go +++ b/go/vt/external/golib/sqlutils/sqlutils.go @@ -28,6 +28,8 @@ import ( "sync" "time" + _ "modernc.org/sqlite" + "vitess.io/vitess/go/vt/log" ) @@ -135,9 +137,9 @@ func (this *RowMap) GetTime(key string) time.Time { var knownDBs = make(map[string]*sql.DB) var knownDBsMutex = &sync.Mutex{} -// GetGenericDB returns a DB instance based on uri. +// GetSQLiteDB returns a SQLite DB instance based on DB file name. // bool result indicates whether the DB was returned from cache; err -func GetGenericDB(driverName, dataSourceName string) (*sql.DB, bool, error) { +func GetSQLiteDB(dataSourceName string) (*sql.DB, bool, error) { knownDBsMutex.Lock() defer func() { knownDBsMutex.Unlock() @@ -145,7 +147,7 @@ func GetGenericDB(driverName, dataSourceName string) (*sql.DB, bool, error) { var exists bool if _, exists = knownDBs[dataSourceName]; !exists { - if db, err := sql.Open(driverName, dataSourceName); err == nil { + if db, err := sql.Open("sqlite", dataSourceName); err == nil { knownDBs[dataSourceName] = db } else { return db, exists, err @@ -154,12 +156,6 @@ func GetGenericDB(driverName, dataSourceName string) (*sql.DB, bool, error) { return knownDBs[dataSourceName], exists, nil } -// GetSQLiteDB returns a SQLite DB instance based on DB file name. -// bool result indicates whether the DB was returned from cache; err -func GetSQLiteDB(dbFile string) (*sql.DB, bool, error) { - return GetGenericDB("sqlite", dbFile) -} - // RowToArray is a convenience function, typically not called directly, which maps a // single read database row into a NullString func RowToArray(rows *sql.Rows, columns []string) ([]CellData, error) { diff --git a/go/vt/vtorc/inst/keyspace_dao_test.go b/go/vt/vtorc/inst/keyspace_dao_test.go index 015d3e75256..dda3ffaa9d2 100644 --- a/go/vt/vtorc/inst/keyspace_dao_test.go +++ b/go/vt/vtorc/inst/keyspace_dao_test.go @@ -20,7 +20,6 @@ import ( "testing" "github.com/stretchr/testify/require" - _ "modernc.org/sqlite" topodatapb "vitess.io/vitess/go/vt/proto/topodata" "vitess.io/vitess/go/vt/topo" diff --git a/go/vt/vtorc/inst/shard_dao_test.go b/go/vt/vtorc/inst/shard_dao_test.go index 3357bd2ee36..84f6aef7a4a 100644 --- a/go/vt/vtorc/inst/shard_dao_test.go +++ b/go/vt/vtorc/inst/shard_dao_test.go @@ -21,7 +21,6 @@ import ( "time" "github.com/stretchr/testify/require" - _ "modernc.org/sqlite" "vitess.io/vitess/go/protoutil" topodatapb "vitess.io/vitess/go/vt/proto/topodata" diff --git a/go/vt/vtorc/logic/keyspace_shard_discovery_test.go b/go/vt/vtorc/logic/keyspace_shard_discovery_test.go index 2911b3d29c2..097865db84a 100644 --- a/go/vt/vtorc/logic/keyspace_shard_discovery_test.go +++ b/go/vt/vtorc/logic/keyspace_shard_discovery_test.go @@ -23,7 +23,6 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - _ "modernc.org/sqlite" topodatapb "vitess.io/vitess/go/vt/proto/topodata" "vitess.io/vitess/go/vt/topo"