-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
*: support read consistency isolation level in the pessimistic transactions #14087
Conversation
Codecov Report
@@ Coverage Diff @@
## master #14087 +/- ##
===========================================
Coverage ? 80.1464%
===========================================
Files ? 483
Lines ? 121530
Branches ? 0
===========================================
Hits ? 97402
Misses ? 16363
Partials ? 7765 |
a1e5e22
to
3a520a4
Compare
/run-all-tests |
/bench |
Benchmark Report
@@ Benchmark Diff @@
================================================================================
--- tidb: a61e3cc324e800d54e5f70a6253eb027665b8a64
+++ tidb: 81cdde210aa8e0b7edd60050c8487e420b10ccce
tikv: 7f17c967ff9d9d778b2c39432cc5465096187261
pd: f3f89205f4a361d8f2116c780aeaab3777b7775b
================================================================================
oltp_update_non_index:
* QPS: 4727.46 ± 0.15% (std=5.53) delta: -0.03% (p=0.727)
* Latency p50: 27.08 ± 0.17% (std=0.03) delta: 0.04%
* Latency p99: 40.86 ± 1.19% (std=0.34) delta: -0.59%
oltp_insert:
* QPS: 4776.71 ± 0.04% (std=1.28) delta: -0.22% (p=0.041)
* Latency p50: 26.79 ± 0.05% (std=0.01) delta: 0.22%
* Latency p99: 46.35 ± 1.21% (std=0.40) delta: 2.50%
oltp_read_write:
* QPS: 15137.10 ± 1.08% (std=96.51) delta: -0.40% (p=0.359)
* Latency p50: 168.87 ± 0.19% (std=0.23) delta: -0.06%
* Latency p99: 321.65 ± 2.24% (std=4.78) delta: 2.89%
oltp_update_index:
* QPS: 4219.03 ± 0.42% (std=12.33) delta: -0.06% (p=0.809)
* Latency p50: 30.33 ± 0.40% (std=0.09) delta: 0.03%
* Latency p99: 54.50 ± 1.20% (std=0.46) delta: 1.82%
oltp_point_select:
* QPS: 38725.96 ± 0.61% (std=155.61) delta: -0.33% (p=0.341)
* Latency p50: 3.31 ± 0.45% (std=0.01) delta: 0.30%
* Latency p99: 10.09 ± 1.78% (std=0.13) delta: 0.00%
|
pessimistic repeatable-read from @mahjonp |
Repeatable Read vs. Read Comitted by this PR,
|
LGTM |
/run-all-tests |
c7a32c3
to
ba18d19
Compare
/run-all-tests |
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.
rest LGTM, but it seems wasted to get ts for each read in TiDB (even if no any data changed)
it seems we just need "read newest data" instead of "read current ts data", maybe we can optimize this base on https://github.com/tikv/tikv/pull/6123/files#diff-49763d722eeb4620a599e6bddecf8f56R50 ?
send a NaN ts and mark it's RC read , and kv mantain max read/write ts watermark like this ts_cache in each region leader, then kv replace NaN with max ts in ts_cache to read newest data, and piggyback ts to tidb.... seems be better?
if memory ts_cache is crashed, kv can report a retry error, tidb retake current ts and resend
maybe we can do it later
LGTM |
2b39b57
to
d48fcdd
Compare
/run-all-tests tidb-test=pr/971 |
|
||
session1.MustExec("begin;") | ||
session2.MustExec("begin;") | ||
session1.MustQuery("select c from x where id = 1;").Check(testkit.Rows("1")) |
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.
Use select for update and mysql should be no write skew here?
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.
yes
session2.MustExec("insert into x values(2, 1);") | ||
session2.MustExec("commit;") | ||
session1.MustExec("update x set c = c+1 where id < 5;") | ||
session1.MustQuery("select c from x where id < 5;").Check(testkit.Rows("2", "2")) |
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.
Compatible for MySQL's drawback -_-||
This PhantomRead is a designed feature!
return s.TxnCtx.Isolation == ast.ReadCommitted | ||
} | ||
if s.txnIsolationLevelOneShot.state == oneShotUse { | ||
s.TxnCtx.Isolation = s.txnIsolationLevelOneShot.value |
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.
When will this value be reset?
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.
When the session starts a new transaction, it will create a new TxnCtx. It works like StmtCtx for each statement.
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.
LGTM
session2.MustExec("begin;") | ||
session1.MustQuery("select c from x where id = 1;").Check(testkit.Rows("1")) | ||
session2.MustQuery("select c from y where id = 1;").Check(testkit.Rows("1")) | ||
session1.MustExec("update y set c = c+1 where id = 1;") |
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.
Should it be like this?
x.c1 <- 1 y.c1 <- 2
session1 session2
begin
begin
x.c1 <- y.c1
y.c1 <- x.c1
commit
commit
and verify x.c1
and y.c1
get swapped but not the same
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.
done
f6616fb
to
349cee9
Compare
Signed-off-by: Shuaipeng Yu <[email protected]>
PTAL @cfzjywxk @tiancaiamao |
LGTM |
/run-all-tests |
What problem does this PR solve?
TiDB does not support Oracle like read consistency isolation level.
What is changed and how it works?
Support read consistency isolation level in the pessimistic transactions.
Check List
Tests
Code changes