-
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
tikv: fix TxnSize to be the number of involved keys in the region #11725
Conversation
fa1a12f
to
f58f3bd
Compare
84454e4
to
87e25f5
Compare
69a436d
to
7545602
Compare
Codecov Report
@@ Coverage Diff @@
## master #11725 +/- ##
=========================================
Coverage 81.541% 81.541%
=========================================
Files 434 434
Lines 93857 93857
=========================================
Hits 76532 76532
Misses 11855 11855
Partials 5470 5470 |
PTAL @disksing |
store/tikv/2pc.go
Outdated
@@ -323,6 +325,12 @@ func (c *twoPhaseCommitter) doActionOnKeys(bo *Backoffer, action twoPhaseCommitA | |||
var batches []batchKeys | |||
var sizeFunc = c.keySize | |||
if action == actionPrewrite { | |||
if c.regionTxnSize == nil { | |||
c.regionTxnSize = make(map[RegionVerID]int) |
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.
I prefer to create it at initial phase.
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.
OK. I will do it.
store/tikv/2pc.go
Outdated
c.regionTxnSize = make(map[RegionVerID]int) | ||
} | ||
for region, keys := range groups { | ||
c.regionTxnSize[region] = len(keys) |
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.
I noticed that the map is not recalculated when encounter region miss (may cause by region split or balance), during retry, all batch size will become 0.
A quick fix is to use region.ID
as the map key instead, it's not 100% accurate but will be better.
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.
On region errors, now txn size will become the batch size instead of 0 because the failed batch will go through the whole prewrite process. Then, it will be as bad as the original code when we have large value size :(
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.
There will be some other problems when we use region.ID
as the map key. When there are several batches in a new region retrying concurrently, it is a problem how we update the txn size of the region...
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.
oh good point 🤣
adf8a49
to
df8fb83
Compare
df8fb83
to
720be0d
Compare
Unexpected "resolve lock lite" is worse than doing more normal resolve lock. As we don't know what the transaction size when doing a retry, I propose we just set it to MaxUint64 to prevent resolve lock lite completely. @disksing PTAL again. Thanks! |
LGTM. |
Yes, all of them are just workarounds. But I think the better solution is to make tikv able to resolve locks themselves (maybe embed a client in tikv) instead of trying reducing the resolve lock round trips between client and tikv. Then, there won't be abortion in cop processing and it is more controllable. For example, (just an inmature idea) tikv can maintain an LRU cache of unfinished locks, and resolve expired ones of them actively when the load is low. |
I guess this scheme violates our design philosophy, which is, tikv is not allowed to access tikv as a client... |
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
/run-all-tests |
/run-all-tests |
Can we merge it? |
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
@sticnarf do we need cherry-pick it to 3.0 ? |
LGTM |
/run-all-tests |
I'm inclined to. There is small chance (a transaction with many keys and big values is down and a coprocessor request needs to scan them) that inaccurate txn_size harms performance a lot. |
cherry pick to release-3.0 failed |
…ngcap#11725) Signed-off-by: Yilin Chen <[email protected]>
It seems that, not for sure, we failed to cherry-pick this commit to release-3.0. Please comment '/run-cherry-picker' to try to trigger the cherry-picker if we did fail to cherry-pick this commit before. @sticnarf PTAL. |
What problem does this PR solve?
In prewrite, the
TxnSize
is now the number of keys in a single batch. Because there is a 16KB batch size limit, it is possible that we write a number of batches to the same region. Then, theTxnSize
is actually not the number of keys involved in a single region.What is changed and how it works?
I create a map in the
twoPhaseCommitter
to store the number of involved keys in each region. Then, we minimize the changes to the commit process. The map is used inbuildPrewriteRequest
to fill theTxnSize
field in thePrewriteRequest
.Check List
Tests
Code changes
Side effects
Related changes
TxnSize
in kvproto