Skip to content

Commit

Permalink
Don't pass gorm DB struct by value
Browse files Browse the repository at this point in the history
The latest version of gorm adds a RWMutex to this struct so we can't
pass by value or we will copy the mutex.

Signed-off-by: Jonny Stoten <[email protected]>
  • Loading branch information
jonnystoten committed May 12, 2022
1 parent 8fa7c9d commit e9fca75
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion server/storage/concurrent_sqldb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func init() {
gormDB.Close()
dbStore := SetupSQLDB(t, backend, dburl)
return dbStore, func() {
dropTables(&dbStore.DB)
dropTables(dbStore.DB)
dbStore.Close()
}
}
Expand Down
4 changes: 2 additions & 2 deletions server/storage/sql_models.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (c SQLChange) TableName() string {
}

// CreateTUFTable creates the DB table for TUFFile
func CreateTUFTable(db gorm.DB) error {
func CreateTUFTable(db *gorm.DB) error {
// TODO: gorm
query := db.AutoMigrate(&TUFFile{})
if query.Error != nil {
Expand All @@ -60,7 +60,7 @@ func CreateTUFTable(db gorm.DB) error {
}

// CreateChangefeedTable creates the DB table for Changefeed
func CreateChangefeedTable(db gorm.DB) error {
func CreateChangefeedTable(db *gorm.DB) error {
query := db.AutoMigrate(&SQLChange{})
return query.Error
}
6 changes: 3 additions & 3 deletions server/storage/sqldb.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
// SQLStorage implements a versioned store using a relational database.
// See server/storage/models.go
type SQLStorage struct {
gorm.DB
*gorm.DB
}

// NewSQLStorage is a convenience method to create a SQLStorage
Expand All @@ -28,7 +28,7 @@ func NewSQLStorage(dialect string, args ...interface{}) (*SQLStorage, error) {
return nil, err
}
return &SQLStorage{
DB: *gormDB,
DB: gormDB,
}, nil
}

Expand Down Expand Up @@ -311,7 +311,7 @@ func (db *SQLStorage) CheckHealth() error {
func (db *SQLStorage) GetChanges(changeID string, records int, filterName string) ([]Change, error) {
var (
changes []Change
query = &db.DB
query = db.DB
id int64
err error
)
Expand Down
2 changes: 1 addition & 1 deletion server/storage/sqldb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type sqldbSetupFunc func(*testing.T) (*SQLStorage, func())

var sqldbSetup sqldbSetupFunc

func assertExpectedGormTUFMeta(t *testing.T, expected []StoredTUFMeta, gormDB gorm.DB) {
func assertExpectedGormTUFMeta(t *testing.T, expected []StoredTUFMeta, gormDB *gorm.DB) {
expectedGorm := make([]TUFFile, len(expected))
for i, tufObj := range expected {
expectedGorm[i] = TUFFile{
Expand Down

0 comments on commit e9fca75

Please sign in to comment.