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

store: implement non-block reading for Get and BatchGet under the large transaction protocol #13599

Merged
merged 8 commits into from Nov 27, 2019

Conversation

tiancaiamao
Copy link
Contributor

What problem does this PR solve?

Large transactions should not block the read operation.

We've handle the coprocessor reading in #11986, and this commit continues with snapshot reading.

What is changed and how it works?

Implement non-block read for snapshot.Get() and snapshot.BatchGet() function.

When those operations meet lock, ResolveLock and retry.
The SendReqCtx operation would not block in the retry as we pass the resolvedLocks.

Check List

Tests

  • Unit test

Code changes

  • Has exported function/method change

@tiancaiamao
Copy link
Contributor Author

PTAL @coocood @lysu

@tiancaiamao
Copy link
Contributor Author

/run-all-tests

@tiancaiamao
Copy link
Contributor Author

Integration test fails, we also need to implement this in TiKV? @MyonKeminta @youjiali1995

[2019-11-19T17:06:20.975Z] ----------------------------------------------------------------------
[2019-11-19T17:06:20.975Z] FAIL: snapshot_test.go:211: testSnapshotSuite.TestSkipLargeTxnLock
[2019-11-19T17:06:20.975Z] 
[2019-11-19T17:06:20.975Z] snapshot_test.go:232:
[2019-11-19T17:06:20.975Z]     // Commit txn, check the final commit ts is pushed.
[2019-11-19T17:06:20.975Z]     c.Assert(committer.commitKeys(bo, committer.keys), IsNil)
[2019-11-19T17:06:20.975Z] ... value *errors.fundamental = tikv aborts txn: Txn(InvalidTxnTso { start_ts: 412662674766430256, commit_ts: 0 }) ("tikv aborts txn: Txn(InvalidTxnTso { start_ts: 412662674766430256, commit_ts: 0 })")
[2019-11-19T17:06:20.975Z] 
[2019-11-19T17:06:20.975Z] [2019/11/20 01:06:17.109 +08:00] [INFO] [lock_resolver.go:540] ["resolveLock rollback"] [lock="key: []byte{0x78}, primary: []byte{0x78}, txnStartTS: 412662674766430256, ttl: 18, type: Put"]
[2019-11-19T17:06:20.975Z] [2019/11/20 01:06:17.110 +08:00] [INFO] [lock_resolver.go:540] ["resolveLock rollback"] [lock="key: []byte{0x79}, primary: []byte{0x78}, txnStartTS: 412662674766430256, ttl: 18, type: Put"]
[2019-11-19T17:06:20.975Z] 
[2019-11-19T17:06:20.975Z] ----------------------------------------------------------------------

tk.MustQuery("select * from t where id in (1)").Check(testkit.Rows("1 1"))

// Cover PointGet.
tk.MustQuery("select * from t where id = 1").Check(testkit.Rows("1 1"))
Copy link
Member

Choose a reason for hiding this comment

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

Does this query use MaxTS?
Then we need also to cover PointGet with real TS.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@tiancaiamao
Copy link
Contributor Author

/integration-common-test

@codecov
Copy link

codecov bot commented Nov 20, 2019

Codecov Report

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

@@             Coverage Diff             @@
##             master     #13599   +/-   ##
===========================================
  Coverage   80.2676%   80.2676%           
===========================================
  Files           475        475           
  Lines        117898     117898           
===========================================
  Hits          94634      94634           
  Misses        15846      15846           
  Partials       7418       7418

@sre-bot sre-bot closed this Nov 20, 2019
@tiancaiamao tiancaiamao reopened this Nov 20, 2019
@coocood
Copy link
Member

coocood commented Nov 20, 2019

LGTM

Copy link
Collaborator

@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 the status/LGT2 Indicates that a PR has LGTM 2. label Nov 20, 2019
@@ -285,10 +298,17 @@ func (s *tikvSnapshot) get(bo *Backoffer, k kv.Key) ([]byte, error) {
}

failpoint.Inject("snapshot-get-cache-fail", func(_ failpoint.Value) {
panic("cache miss")
if bo.ctx.Value("TestSnapshotCache") != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe using exp like 1*return(true)->return(false) like this

c.Assert(failpoint.Enable("github.com/pingcap/tidb/session/keepHistory", `1*return(true)->return(false)`), IsNil)
and check failpoint.Value == true at here is more gofail idiom~

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the concurrent test environment, that mock panic may affect other tests.
bo.ctx.Value("TestSnapshotCache") is used to address that problem. @lysu

Copy link
Member

Choose a reason for hiding this comment

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

Or we can pass a TS and panic on equal TS.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In failpoint.Inject it doesn't know which TS @coocood

@coocood
Copy link
Member

coocood commented Nov 20, 2019

@MyonKeminta PTAL

Copy link
Contributor

@youjiali1995 youjiali1995 left a comment

Choose a reason for hiding this comment

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

LGTM

@coocood
Copy link
Member

coocood commented Nov 27, 2019

/merge

@sre-bot sre-bot added the status/can-merge Indicates a PR has been approved by a committer. label Nov 27, 2019
@sre-bot
Copy link
Contributor

sre-bot commented Nov 27, 2019

/run-all-tests

@sre-bot sre-bot merged commit c10c576 into pingcap:master Nov 27, 2019
XiaTianliang pushed a commit to XiaTianliang/tidb that referenced this pull request Dec 21, 2019
@tiancaiamao tiancaiamao deleted the non-block-point-get branch May 26, 2020 09:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/tikv status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants