Skip to content

Commit

Permalink
Remove unneeded loading of the MySQL driver (#15502)
Browse files Browse the repository at this point in the history
Signed-off-by: Dirkjan Bussink <[email protected]>
  • Loading branch information
dbussink authored Mar 18, 2024
1 parent 51debbd commit 4d4793d
Show file tree
Hide file tree
Showing 7 changed files with 5 additions and 18 deletions.
3 changes: 0 additions & 3 deletions go/cmd/vtorc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
1 change: 0 additions & 1 deletion go/test/endtoend/vtgate/queries/timeout/timeout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package misc
import (
"testing"

_ "github.com/go-sql-driver/mysql"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

Expand Down
2 changes: 0 additions & 2 deletions go/test/endtoend/vtorc/readtopologyinstance/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
14 changes: 5 additions & 9 deletions go/vt/external/golib/sqlutils/sqlutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import (
"sync"
"time"

_ "modernc.org/sqlite"

"vitess.io/vitess/go/vt/log"
)

Expand Down Expand Up @@ -135,17 +137,17 @@ 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()
}()

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
Expand All @@ -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) {
Expand Down
1 change: 0 additions & 1 deletion go/vt/vtorc/inst/keyspace_dao_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion go/vt/vtorc/inst/shard_dao_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion go/vt/vtorc/logic/keyspace_shard_discovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 4d4793d

Please sign in to comment.