Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update(deps): upgrade gorm to v2 #916

Merged
merged 7 commits into from
May 24, 2021
Merged

Conversation

shhdgit
Copy link
Member

@shhdgit shhdgit commented May 11, 2021

This issue blocks #914-comment

@shhdgit
Copy link
Member Author

shhdgit commented May 11, 2021

/cc @breeswish
PTAL!

Copy link
Member

@breezewish breezewish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's hold this PR after the release. I'm afraid it will introduce some conflicts and undiscovered bugs.

@shhdgit shhdgit requested a review from breezewish May 13, 2021 02:53
pkg/apiserver/info/info.go Outdated Show resolved Hide resolved
@@ -141,7 +141,11 @@ func (s *Service) runHandler(c *gin.Context) {
defer cancel()

startTime := time.Now()
colNames, rows, err := executeStatements(ctx, utils.GetTiDBConnection(c).DB(), req.Statements)
sqlDB, err := utils.GetTiDBConnection(c).DB()
if err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In what case will this error happen?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to https://gorm.io/docs/generic_interface.html. If the underlying database connection is not a *sql.DB, like in a transaction, it will returns error.

pkg/apiserver/statement/config.go Outdated Show resolved Hide resolved
pkg/apiserver/utils/gorm.go Show resolved Hide resolved
pkg/apiserver/statement/service.go Outdated Show resolved Hide resolved
Comment on lines 227 to 232
defer db.Close() //nolint:errcheck
defer func() {
sqlDB, err := db.DB()
if err == nil {
sqlDB.Close()
}
}()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to change to this? (I didn't find this change in gorm v2 release note)

Copy link
Member Author

@shhdgit shhdgit May 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cuz there's no Close interface in v2 *gorm.DB. https://pkg.go.dev/gorm.io/gorm#pkg-index

And, is it really necessary to close the connection pool?
go-gorm/gorm#3145
go-gorm/gorm#3834
go-gorm/gorm#3535
go-gorm/gorm#4157

@@ -42,18 +41,23 @@ func NewDBStore(lc fx.Lifecycle, config *config.Config) (*DB, error) {

p := path.Join(config.DataDir, "dashboard.sqlite.db")
log.Info("Dashboard initializing local storage file", zap.String("path", p))
gormDB, err := gorm.Open("sqlite3", p)
gormDB, err := gorm.Open(sqlite.Open(p), &gorm.Config{
Logger: zapgorm2.New(log.L()),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice catch! could you test whether it really works? (for example, you can simulate it by producing some error connections). In my current implementation the logger does not really work.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's works by check cat /tmp/dashboard-data/dashboard.sqlite.db output. And why the logger not work in current implementation?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can simulate a database query error, like introducing a syntax error. And then you will find unexpected log output in current implementation.

pkg/apiserver/diagnose/diagnose.go Outdated Show resolved Hide resolved
@ti-chi-bot
Copy link
Member

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • breeswish

To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

The full list of commands accepted by this bot can be found here.

Reviewer can indicate their review by writing /lgtm in a comment.
Reviewer can cancel approval by writing /lgtm cancel in a comment.

@breezewish breezewish merged commit f5fc9ba into pingcap:master May 24, 2021
shhdgit added a commit to shhdgit/tidb-dashboard that referenced this pull request Jun 15, 2021
Conflicts:
	pkg/apiserver/diagnose/diagnose.go
breezewish pushed a commit that referenced this pull request Jun 15, 2021
* fix: label of y-axis is overflow (#924)
* update(deps): upgrade gorm to v2 (#916)
* debug_api: Add more endpoints (#927)
* fix(ui): localstorage compatibility issue (#930)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants