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

kv, store: remove Rollback in RunInNewTxn #8250

Merged
merged 4 commits into from
Nov 12, 2018
Merged

Conversation

zimulala
Copy link
Contributor

@zimulala zimulala commented Nov 9, 2018

What problem does this PR solve?

In the RunInNewTxn function, the error of invalid transaction will be reported when the commit fails.

2018/11/07 11:37:41.755 txn.go:65: [warning] [kv] Retry txn 404118742386346212 original txn 404118742386346212 err [try again later]: WriteConflict: startTS=404118742386346212, conflictTS=404118742399452259, key=[]byte{0x6d, 0x44, 0x42, 0x3a, 0x31, 0x31, 0x31, 0x0, 0x0, 0xfd, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x68, 0x54, 0x49, 0x44, 0x3a, 0x31, 0x31, 0x33, 0x0, 0xfe} primary=[]byte{0x6d, 0x44, 0x42, 0x3a, 0x31, 0x31, 0x31, 0x0, 0x0, 0xfd, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x68, 0x54, 0x49, 0x44, 0x3a, 0x31, 0x31, 0x33, 0x0, 0xfe}
2018/11/07 11:37:41.755 terror.go:342: [error] [kv:8]invalid transaction
github.com/pingcap/errors.AddStack
    /home/ubuntu/projects/go/pkg/mod/github.com/pingcap/errors@v0.11.0/errors.go:174
github.com/pingcap/errors.Trace
    /home/ubuntu/projects/go/pkg/mod/github.com/pingcap/errors@v0.11.0/juju_adaptor.go:12
github.com/pingcap/tidb/kv.RunInNewTxn
    /home/ubuntu/projects/go/src/github.com/pingcap/tidb/kv/txn.go:67
...

What is changed and how it works?

If "Commit" is completed, it will call txn's close. So we can remove Rollback and the print log in RunInNewTxn.

Check List

Tests

  • Unit test

Related changes

  • Need to cherry-pick to the release branch

Copy link
Member

@zz-jason zz-jason left a comment

Choose a reason for hiding this comment

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

LGTM

@zz-jason zz-jason added type/enhancement The issue or PR belongs to an enhancement. status/LGT1 Indicates that a PR has LGTM 1. component/tikv labels Nov 9, 2018
@zimulala
Copy link
Contributor Author

zimulala commented Nov 9, 2018

/run-all-tests

@zimulala
Copy link
Contributor Author

zimulala commented Nov 9, 2018

/run-common-test
/run-integration-common-test
/run-sqllogic-test

kv/txn.go Outdated Show resolved Hide resolved
@@ -33,6 +34,10 @@ func (s *testCommitterSuite) TestFailCommitPrimaryRpcErrors(c *C) {
err = t1.Commit(context.Background())
c.Assert(err, NotNil)
c.Assert(terror.ErrorEqual(err, terror.ErrResultUndetermined), IsTrue, Commentf("%s", errors.ErrorStack(err)))

// We don't need to call "Rollback" after "Commit" fails.
Copy link
Member

Choose a reason for hiding this comment

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

The comment confuses me. Why do you call the Rollback() in line 39?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This test is used to prove why the rollback was removed in "RunInNewTxn".

@@ -63,8 +60,6 @@ func RunInNewTxn(store Storage, retryable bool, f func(txn Transaction) error) e
}
if retryable && IsRetryableError(err) {
log.Warnf("[kv] Retry txn %v original txn %v err %v", txn, originalTxnTS, err)
err1 := txn.Rollback()
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

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 said

If "Commit" is completed, it will call txn's close. So we can remove Rollback and the print log in RunInNewTxn.

@zimulala
Copy link
Contributor Author

PTAL @jackysp @crazycs520

Copy link
Member

@jackysp jackysp left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@crazycs520 crazycs520 left a comment

Choose a reason for hiding this comment

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

LGTM

@crazycs520
Copy link
Contributor

/run-all-tests

@zimulala
Copy link
Contributor Author

/run-integration-ddl-test

@zimulala zimulala added status/LGT2 Indicates that a PR has LGTM 2. status/all tests passed and removed status/LGT1 Indicates that a PR has LGTM 1. labels Nov 12, 2018
@zimulala zimulala merged commit e233ee9 into pingcap:master Nov 12, 2018
@zimulala zimulala deleted the run-txn branch November 12, 2018 08:40
zimulala added a commit to zimulala/tidb that referenced this pull request Nov 12, 2018
zimulala added a commit to zimulala/tidb that referenced this pull request Nov 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/tikv status/LGT2 Indicates that a PR has LGTM 2. type/enhancement The issue or PR belongs to an enhancement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants