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

txn: support 2pc async commit protocol #18622

Merged
merged 7 commits into from Jul 22, 2020

Conversation

cfzjywxk
Copy link
Contributor

What problem does this PR solve?

Issue Number: async commit project

Problem Summary:
Change the 2pc commit logic to support async commit protocol.

What is changed and how it works?

What's Changed:
Return success to the client if all prewrites are successful, and get the commit work done asynchronously.

How it Works:

Related changes

Check List

Tests

Side effects

Release note

@cfzjywxk cfzjywxk added require-LGT3 Indicates that the PR requires three LGTM. sig/transaction SIG:Transaction labels Jul 16, 2020
@sticnarf
Copy link
Contributor

Binlog is not compatible with async commit. Should we ignore the binlog part when async commit is used?

@cfzjywxk
Copy link
Contributor Author

Binlog is not compatible with async commit. Should we ignore the binlog part when async commit is used?

I think so, seems no perfect solution by now. And it did reduce the usability a lot.

// checkAsyncCommit checks if async commit protocol is available for current transaction commit, true is returned if possible.
func (c *twoPhaseCommitter) checkAsyncCommit(ctx context.Context) bool {
const asyncCommitKeysLimit = 256
if c.connID > 0 && config.GetGlobalConfig().TiKVClient.EnableAsyncCommit && len(c.mutations.keys) <= asyncCommitKeysLimit {
Copy link
Collaborator

Choose a reason for hiding this comment

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

when will c.ConnID will be 0~?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The system session running background works.

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 bypass the internal SQLs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To make the tests easier by now, maybe we could remove this constraint if it's stable.

@@ -666,44 +669,60 @@ func sendTxnHeartBeat(bo *Backoffer, store *tikvStore, primary []byte, startTS,
}
}

// checkAsyncCommit checks if async commit protocol is available for current transaction commit, true is returned if possible.
func (c *twoPhaseCommitter) checkAsyncCommit(ctx context.Context) bool {
const asyncCommitKeysLimit = 256
Copy link
Collaborator

Choose a reason for hiding this comment

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

do we need to check the total size for "key size is large but key count is less" situation?

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 think it should be considered. But I haven't think carefully about how to set this limit, maybe some tests are needed.

failpoint.Inject("asyncCommitDoNothing", func() {
failpoint.Return()
})
commitBo := NewBackofferWithVars(ctx, CommitMaxBackoff, c.txn.vars)
Copy link
Collaborator

@lysu lysu Jul 16, 2020

Choose a reason for hiding this comment

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

maybe there is a tiny optimization we should take care at here.

it'd better transfer ttlManager's ownership to this forked goroutine and keep the heartbeat even if commit result has be given to end-user(close ttlManager after this goroutine done?).

other txn should wait origin txn commit's fork goroutine if it's alive, this seems make the origin txn has more opportunity to commit success and reduce duplicate resolve when txn size is larger

@@ -128,6 +128,11 @@ func (action actionPrewrite) handleSingleBatch(c *twoPhaseCommitter, bo *Backoff
c.run(c, nil)
}
}
c.mu.Lock()
if prewriteResp.MinCommitTs > c.minCommitTS {
c.minCommitTS = prewriteResp.MinCommitTs
Copy link
Contributor

Choose a reason for hiding this comment

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

And if MinCommitTS is 0, it means async commit cannot proceed due to some reason. We should also set useAysncCommit to false.

@codecov
Copy link

codecov bot commented Jul 16, 2020

Codecov Report

Merging #18622 into master will not change coverage.
The diff coverage is n/a.

@@             Coverage Diff             @@
##             master     #18622   +/-   ##
===========================================
  Coverage   79.5004%   79.5004%           
===========================================
  Files           542        542           
  Lines        147618     147618           
===========================================
  Hits         117357     117357           
  Misses        20939      20939           
  Partials       9322       9322           

Copy link
Contributor

@sticnarf sticnarf left a comment

Choose a reason for hiding this comment

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

The rest LGTM.

Comment on lines 823 to 827
if binlogSkipped {
binloginfo.RemoveOneSkippedCommitter()
} else {
c.writeFinishBinlog(ctx, binlog.BinlogType_Commit, int64(c.commitTS))
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Are these lines still necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed.

@cfzjywxk cfzjywxk requested a review from lysu July 16, 2020 09:42
store/tikv/2pc.go Outdated Show resolved Hide resolved
@cfzjywxk cfzjywxk requested a review from jackysp July 17, 2020 06:57
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

@ti-srebot ti-srebot added the status/LGT1 Indicates that a PR has LGTM 1. label Jul 17, 2020
@cfzjywxk cfzjywxk added this to In progress in SIG Transaction Jul 17, 2020
@sticnarf
Copy link
Contributor

LGTM

@ti-srebot ti-srebot removed the status/LGT1 Indicates that a PR has LGTM 1. label Jul 22, 2020
@ti-srebot ti-srebot added the status/LGT2 Indicates that a PR has LGTM 2. label Jul 22, 2020
@coocood
Copy link
Member

coocood commented Jul 22, 2020

LGTM

@ti-srebot ti-srebot removed the status/LGT2 Indicates that a PR has LGTM 2. label Jul 22, 2020
@ti-srebot ti-srebot added the status/LGT3 The PR has already had 3 LGTM. label Jul 22, 2020
@coocood
Copy link
Member

coocood commented Jul 22, 2020

/merge

@ti-srebot ti-srebot added the status/can-merge Indicates a PR has been approved by a committer. label Jul 22, 2020
@ti-srebot
Copy link
Contributor

/run-all-tests

@ti-srebot
Copy link
Contributor

@cfzjywxk merge failed.

@cfzjywxk
Copy link
Contributor Author

/merge

@ti-srebot
Copy link
Contributor

/run-all-tests

@ti-srebot
Copy link
Contributor

@cfzjywxk merge failed.

@cfzjywxk
Copy link
Contributor Author

/merge

@ti-srebot
Copy link
Contributor

/run-all-tests

@ti-srebot
Copy link
Contributor

@cfzjywxk merge failed.

@zz-jason zz-jason merged commit e66f8eb into pingcap:master Jul 22, 2020
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. sig/transaction SIG:Transaction status/can-merge Indicates a PR has been approved by a committer. status/LGT3 The PR has already had 3 LGTM.
Projects
No open projects
SIG Transaction
  
In progress
Development

Successfully merging this pull request may close these issues.

None yet

7 participants