-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
Set ServerStatusInTrans flag #159
Merged
Merged
Changes from 5 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
3531df9
stmt: set ServerStatusInTrans
zimulala 2287542
sessionctx: add ServerStatusInTrans and comments
zimulala a11fa52
sessionctx: update comments
zimulala 8824321
sessionctx: update format
zimulala 39fcb95
tidb: add SetStatusInTrans test
zimulala c745049
tidb: fix a bug and update test
zimulala b435e3e
tidb: update format
zimulala ee2a4cb
tidb: fix a bug
zimulala 73df308
*: remove DisableAutocommit and rename IsAutocommit to ShouldAutocommit
zimulala a2ab430
Merge branch 'master' into zimuxia/status-in-trans
zimulala 127b0fb
*: clean up and update test
zimulala File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -513,6 +513,45 @@ func (s *testSessionSuite) TestAutoicommit(c *C) { | |
mustExecSQL(c, se, s.dropDBSQL) | ||
} | ||
|
||
func checkInTrans(c *C, se Session, stmt string, isNil bool, expect uint16) { | ||
mustExecSQL(c, se, stmt) | ||
if isNil { | ||
c.Assert(se.(*session).txn, IsNil) | ||
} else { | ||
c.Assert(se.(*session).txn, NotNil) | ||
} | ||
ret := variable.GetSessionVars(se.(*session)).Status & mysql.ServerStatusInTrans | ||
c.Assert(ret, Equals, expect) | ||
} | ||
|
||
// See: https://dev.mysql.com/doc/internals/en/status-flags.html | ||
func (s *testSessionSuite) TestInTrans(c *C) { | ||
store := newStore(c, s.dbName) | ||
se := newSession(c, store, s.dbName) | ||
mustExecSQL(c, se, "drop table if exists t") | ||
c.Assert(se.(*session).txn, IsNil) | ||
checkInTrans(c, se, "create table t (id BIGINT PRIMARY KEY AUTO_INCREMENT NOT NULL)", true, 0) | ||
checkInTrans(c, se, "insert t values ()", true, 0) | ||
checkInTrans(c, se, "begin", false, 1) | ||
checkInTrans(c, se, "insert t values ()", false, 1) | ||
se.Execute("drop table if exists t;") | ||
c.Assert(se.(*session).txn, IsNil) | ||
c.Assert(variable.GetSessionVars(se.(*session)).Status&mysql.ServerStatusInTrans, Equals, uint16(1)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A little confused, here why txn is nil but in ServerStatusInTrans? |
||
checkInTrans(c, se, "create table t (id BIGINT PRIMARY KEY AUTO_INCREMENT NOT NULL)", true, 1) | ||
checkInTrans(c, se, "insert t values ()", false, 1) | ||
checkInTrans(c, se, "commit", true, 0) | ||
checkInTrans(c, se, "insert t values ()", true, 0) | ||
|
||
se.Execute("drop table if exists t;") | ||
mustExecSQL(c, se, "create table t (id BIGINT PRIMARY KEY AUTO_INCREMENT NOT NULL)") | ||
c.Assert(variable.GetSessionVars(se.(*session)).Status&mysql.ServerStatusInTrans, Equals, uint16(0)) | ||
checkInTrans(c, se, "begin", false, 1) | ||
checkInTrans(c, se, "insert t values ()", false, 1) | ||
checkInTrans(c, se, "rollback", true, 0) | ||
|
||
mustExecSQL(c, se, s.dropDBSQL) | ||
} | ||
|
||
// See: http://dev.mysql.com/doc/refman/5.7/en/commit.html | ||
func (s *testSessionSuite) TestRowLock(c *C) { | ||
store := newStore(c, s.dbName) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems no need to use expect or isNil variable? Use one of them is enough?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep.