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

stats: fix dump stats #6285

Merged
merged 14 commits into from
Apr 26, 2018
Merged

stats: fix dump stats #6285

merged 14 commits into from
Apr 26, 2018

Conversation

fipped
Copy link
Contributor

@fipped fipped commented Apr 14, 2018

There are two problems in the current implementation of dumping/loading stats info:

  • While dumping stats, the modify_count and version of table are always dumped to 0 since the copy function of table not copy these attributes.
  • While loading stats, these attributes are not saved to the storage. We forget to save stats_meta to TiKV.

This PR fixed these issues.
PTAL @lamxTyler @coocood

var sql string
sql = fmt.Sprintf("replace into mysql.stats_meta (version, table_id, count, modify_count) values (%d, %d, %d, %d)", version, tableID, count, modifyCount)
if _, err = exec.Execute(ctx, sql); err != nil {
return errors.Trace(err)
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we should execute rollback here.

return nil
Err: nil,
}
err = statistics.SaveMetaToStorage(e.Ctx, tbl.TableID, tbl.Count, tbl.ModifyCount, tbl.Version)
Copy link
Member

Choose a reason for hiding this comment

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

I think if err is nil, we should not trace it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If err is nil, the errors.Trace will return nil.

@shenli
Copy link
Member

shenli commented Apr 16, 2018

LGTM

@shenli
Copy link
Member

shenli commented Apr 16, 2018

/run-all-tests

@shenli
Copy link
Member

shenli commented Apr 16, 2018

@coocood @lamxTyler PTAL

@shenli shenli added status/LGT1 Indicates that a PR has LGTM 1. type/bugfix This PR fixes a bug. labels Apr 16, 2018
@@ -143,6 +145,10 @@ func (e *LoadStatsInfo) Update(data []byte) error {
return errors.Trace(err)
}
}
err = statistics.SaveMetaToStorage(e.Ctx, tbl.TableID, tbl.Count, tbl.ModifyCount, tbl.Version)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why save it twice?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't save it twice. They are two situations, and it will return immediately after the previous call.

return errors.Trace(err)
}
var sql string
sql = fmt.Sprintf("replace into mysql.stats_meta (version, table_id, count, modify_count) values (%d, %d, %d, %d)", version, tableID, count, modifyCount)
Copy link
Contributor

Choose a reason for hiding this comment

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

We cannot use the original version, it may not be loaded into stats cache.

@shenli
Copy link
Member

shenli commented Apr 16, 2018

/run-all-tests

@coocood
Copy link
Member

coocood commented Apr 23, 2018

/run-all-tests

@@ -54,6 +54,8 @@ type Handle struct {
feedback []*QueryFeedback

Lease time.Duration
// loadMetaCh is a channel to notify a load stats operation has done.
loadMetaCh chan *LoadMeta
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that it is not initialized.

@coocood coocood added priority/release-blocker This issue blocks a release. Please solve it ASAP. and removed priority/release-blocker This issue blocks a release. Please solve it ASAP. labels Apr 25, 2018
@coocood
Copy link
Member

coocood commented Apr 26, 2018

LGTM

@coocood coocood added the status/LGT2 Indicates that a PR has LGTM 2. label Apr 26, 2018
@coocood coocood removed the status/LGT1 Indicates that a PR has LGTM 1. label Apr 26, 2018
@alivxxx alivxxx merged commit 8729424 into pingcap:master Apr 26, 2018
@sre-bot sre-bot added the contribution This PR is from a community contributor. label Dec 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/statistics contribution This PR is from a community contributor. status/LGT2 Indicates that a PR has LGTM 2. type/bugfix This PR fixes a bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants