Skip to content

Commit

Permalink
test engine
Browse files Browse the repository at this point in the history
  • Loading branch information
CharlesCheung96 committed Sep 14, 2023
1 parent 7f00eb5 commit da6a77d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion engine/servermaster/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ func (s *Server) initElector() error {
return errors.Errorf("failed to convert conn to *sql.DB, got %T", conn)
}

sqlStorage, err := election.NewSQLStorage(db, leaderElectionTable)
sqlStorage, err := election.NewORMStorageFromSQLDB(db, leaderElectionTable)
if err != nil {
return err
}
Expand Down
11 changes: 11 additions & 0 deletions pkg/election/storage_orm.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ package election

import (
"context"
"database/sql"
"database/sql/driver"
"encoding/json"

"github.com/pingcap/log"
ormUtil "github.com/pingcap/tiflow/engine/pkg/orm"
"github.com/pingcap/tiflow/pkg/errors"
"gorm.io/gorm"
)
Expand Down Expand Up @@ -70,6 +72,15 @@ type ORMStorage struct {
tableName string
}

// NewORMStorageFromSQLDB creates a new ORMStorage from sql.DB.
func NewORMStorageFromSQLDB(backendDB *sql.DB, tableName string) (*ORMStorage, error) {
db, err := ormUtil.NewGormDB(backendDB, "mysql")
if err != nil {
return nil, err
}
return NewORMStorage(db, tableName)
}

// NewORMStorage creates a new ORMStorage.
func NewORMStorage(db *gorm.DB, tableName string) (*ORMStorage, error) {
TableNameElection = tableName
Expand Down

0 comments on commit da6a77d

Please sign in to comment.