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

session: move more session vars to stmt context for retrying #8034

Merged
merged 20 commits into from
Dec 10, 2018

Conversation

jackysp
Copy link
Member

@jackysp jackysp commented Oct 24, 2018

What problem does this PR solve?

Some session variables should be in statement context e.g. prev-affected rows and last insert id. If not the behavior will be incorrect when retrying.

What is changed and how it works?

Move the session variables to statement context.

Check List

Tests

  • Unit test

Code changes

  • Has exported function/method change

Related changes

  • Need to cherry-pick to the release branch

PTAL @tiancaiamao @disksing


This change is Reviewable

@jackysp
Copy link
Member Author

jackysp commented Oct 24, 2018

create table t (i int key);
insert into t values (1);
begin;
insert into t values (10);
update t set i = i + row_count();
-- before the following commit, run `update t set i = i - 1;` in another session.
commit;

we got

mysql> select * from t;
+----+
| i  |
+----+
| -1 |
|  9 |
+----+
2 rows in set (0.00 sec)

I think it should be

mysql> select * from t;
+----+
| i  |
+----+
| 1  |
| 11 |
+----+
2 rows in set (0.00 sec)

@tiancaiamao tiancaiamao added the require-LGT3 Indicates that the PR requires three LGTM. label Oct 24, 2018
@jackysp
Copy link
Member Author

jackysp commented Oct 24, 2018

/run-all-tests

@jackysp
Copy link
Member Author

jackysp commented Oct 25, 2018

PTAL @disksing @tiancaiamao

@disksing
Copy link
Contributor

Sorry I'm not really familiar with session.go. Maybe @coocood can help you.

@jackysp
Copy link
Member Author

jackysp commented Oct 29, 2018

PTAL @zimulala

@jackysp jackysp added the priority/release-blocker This issue blocks a release. Please solve it ASAP. label Nov 5, 2018
@@ -111,10 +110,9 @@ type StmtHistory struct {
// Add appends a stmt to history list.
func (h *StmtHistory) Add(stmtID uint32, st sqlexec.Statement, stmtCtx *stmtctx.StatementContext, params ...interface{}) {
Copy link
Contributor

Choose a reason for hiding this comment

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

stmtCtx *stmtctx.StatementContext can be remove too

@lysu
Copy link
Contributor

lysu commented Nov 7, 2018

@jackysp PTAL this issue #2759, it seems has some reason previous keep stmtContext in history and only reset three fields? 🤣

@jackysp
Copy link
Member Author

jackysp commented Nov 7, 2018

PTAL @coocood if you are free.

@crazycs520

This comment has been minimized.

@jackysp
Copy link
Member Author

jackysp commented Nov 8, 2018

/run-all-tests

// PrevAffectedRows is the affected-rows value(DDL is 0, DML is the number of affected rows).
PrevAffectedRows int64
// params for prepared statements
PreparedParams []interface{}
Copy link
Contributor

Choose a reason for hiding this comment

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

why change []types.Datum to []interface{} ?

@@ -1175,6 +1175,7 @@ func ResetContextOfStmt(ctx sessionctx.Context, s ast.StmtNode) (err error) {
sc.MemTracker = memory.NewTracker(s.Text(), vars.MemQuotaQuery)
sc.NowTs = time.Time{}
sc.SysTs = time.Time{}
sc.PreparedParams = []interface{}{}
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe put PreparedParams in SessionVars can avoid re-allocating memory before every execution.

Copy link
Contributor

Choose a reason for hiding this comment

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

Why not set it to nil

@jackysp jackysp changed the title session: reset context of statement when retrying session: move more session vars to stmt context for retrying Nov 16, 2018
@jackysp
Copy link
Member Author

jackysp commented Nov 16, 2018

/run-all-tests

@jackysp
Copy link
Member Author

jackysp commented Nov 28, 2018

PTAL @zimulala , @lysu

@jackysp
Copy link
Member Author

jackysp commented Nov 29, 2018

PTAL @tiancaiamao

@tiancaiamao
Copy link
Contributor

LGTM

@tiancaiamao tiancaiamao added the status/LGT2 Indicates that a PR has LGTM 2. label Nov 29, 2018
@jackysp
Copy link
Member Author

jackysp commented Nov 30, 2018

PTAL @lysu @zimulala

4 similar comments
@jackysp
Copy link
Member Author

jackysp commented Dec 3, 2018

PTAL @lysu @zimulala

@jackysp
Copy link
Member Author

jackysp commented Dec 4, 2018

PTAL @lysu @zimulala

@jackysp
Copy link
Member Author

jackysp commented Dec 5, 2018

PTAL @lysu @zimulala

@jackysp
Copy link
Member Author

jackysp commented Dec 7, 2018

PTAL @lysu @zimulala

Copy link
Contributor

@lysu lysu left a comment

Choose a reason for hiding this comment

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

Reviewed 12 of 12 files at r1.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved

Copy link
Contributor

@lysu lysu left a comment

Choose a reason for hiding this comment

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

miss approve by reviewable

Copy link
Contributor

@lysu lysu left a comment

Choose a reason for hiding this comment

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

LGTM

@lysu lysu added status/LGT3 The PR has already had 3 LGTM. require-LGT3 Indicates that the PR requires three LGTM. and removed require-LGT3 Indicates that the PR requires three LGTM. status/LGT2 Indicates that a PR has LGTM 2. labels Dec 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
require-LGT3 Indicates that the PR requires three LGTM. status/LGT3 The PR has already had 3 LGTM. type/bugfix This PR fixes a bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants