Commit 4a28830
committed
transaction: refuse to resolve shared locks instead of mis-handling them
The re-vendored kvproto exposes shared locks (Op::SharedLock /
Op::SharedPessimisticLock). Their contract is unusual: a shared lock's real
holders live ONLY in kvrpcpb.LockInfo.shared_lock_infos — the proto comment is
explicit that you must "DO NOT read from the wrapper LockInfo", whose own key
and lock_version are unset.
This client does not implement shared-lock resolution, and every partial
handling of one is worse than none: resolving the wrapper checks transaction 0;
filtering on the wrapper's fields (use_async_commit, lock_type) silently drops
the real members; and the pessimistic-lock special cases in the resolver do not
know SharedPessimisticLock. So resolution REFUSES them with an explicit error —
in resolve_locks, in LockResolver's crate-public entry point, and in
CleanupLocks::execute before any filter runs. Until real support lands, an
explicit error is the only answer that cannot roll back a live transaction or
skip a dead one. Servers that predate shared locks never produce them, so this
is a no-op there.
The API-v2 keyspace codecs are made shared-lock-aware separately, because they
run on scan results that never reach the resolver. They now take the shape of
client-go's codecV2.decodeLockInfo (internal/apicodec/codec_v2.go), which
decodes a LockInfo's own Key/PrimaryLock/Secondaries and then recurses into
SharedLockInfos — it has no wrapper special case. This client now does the
same: convert the lock's OWN key fields, then recurse into the members.
An earlier revision skipped a wrapper's own fields entirely, reading the proto's
"DO NOT read from the wrapper LockInfo" as covering them. Checking the writer
(TiKV's SharedLocks::into_lock_info in components/txn_types/src/lock.rs,
identical at v8.5.7 and on master) shows
that is only half right, and the half it gets wrong matters:
info.set_shared_lock_infos(shared_locks.into());
info.set_key(raw_key);
A wrapper sets lock_type, shared_lock_infos and key — the key it locks — and
leaves primary_lock and lock_version at their defaults; each member is built
from that SAME raw key plus its own primary and version. So the caveat scopes
the per-transaction fields, not the locked key. Skipping the wrapper wholesale
would have handed scan_locks a physical key beside decoded member keys, while
converting it wholesale would have hit the length assertion on the unset
primary. Both fields are exercised by tests.
The two directions guard differently, on purpose. Truncating,
empty bytes can only mean "unset" — an encoded key always carries its 4-byte
prefix — so unset fields are skipped rather than run into pretruncate_bytes'
length assertion. Encoding, the input is a LOGICAL key and the empty logical key
is valid in API v2, so nothing is skipped: scan_locks -> resolve_locks
round-trips locks through truncate-then-encode, and skipping empties there would
strand a lock on the empty key with no prefix and send resolution after an empty
physical key. Wrappers need no encode-side guard because resolution refuses them
first. That panic hazard predates the re-vendor: a wrapper arrives the same way
whichever proto vintage parses it.
Full shared-lock support is deliberately follow-up work.
Split out of the kvproto re-vendor at pingyu's suggestion (#550).
Tests: 4 new — the resolver refusal (a plain lock passes; a wrapper carrying
members and a lock marked shared only by its op are both refused); the codec
converting a wrapper's own key alongside its members; a wrapper's unset fields
surviving truncation (the other reading, so both are pinned); and a lock on the
empty logical key round-tripping through truncate-then-encode. 71 lib tests
green.
The coverage is unit-level by necessity: CI pins TIKV_VERSION v8.5.5, which
predates shared locks, so no integration test in this repo can produce one, and
the refusal path is unreachable against that server. v8.5.6 is the first release
carrying shared locks, so a CI pin bump within the same release family would
make these paths reachable — left to a separate change.
Signed-off-by: Eduard R. <eduard@ralphovi.net>1 parent 2aa94c1 commit 4a28830
4 files changed
Lines changed: 243 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
160 | 160 | | |
161 | 161 | | |
162 | 162 | | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
163 | 174 | | |
164 | 175 | | |
165 | 176 | | |
166 | 177 | | |
167 | 178 | | |
168 | 179 | | |
169 | | - | |
170 | | - | |
171 | | - | |
172 | | - | |
173 | | - | |
174 | | - | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
175 | 203 | | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
176 | 213 | | |
177 | 214 | | |
178 | 215 | | |
179 | 216 | | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
180 | 220 | | |
181 | 221 | | |
182 | 222 | | |
| |||
188 | 228 | | |
189 | 229 | | |
190 | 230 | | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
191 | 242 | | |
192 | 243 | | |
193 | 244 | | |
| |||
203 | 254 | | |
204 | 255 | | |
205 | 256 | | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
206 | 260 | | |
207 | 261 | | |
208 | 262 | | |
| |||
477 | 531 | | |
478 | 532 | | |
479 | 533 | | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
480 | 650 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
841 | 841 | | |
842 | 842 | | |
843 | 843 | | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
844 | 848 | | |
845 | 849 | | |
846 | 850 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
46 | 75 | | |
47 | 76 | | |
48 | 77 | | |
| |||
56 | 85 | | |
57 | 86 | | |
58 | 87 | | |
| 88 | + | |
59 | 89 | | |
60 | 90 | | |
61 | 91 | | |
| |||
300 | 330 | | |
301 | 331 | | |
302 | 332 | | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
303 | 336 | | |
304 | 337 | | |
305 | 338 | | |
| |||
619 | 652 | | |
620 | 653 | | |
621 | 654 | | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
622 | 684 | | |
623 | 685 | | |
624 | 686 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| 31 | + | |
31 | 32 | | |
32 | 33 | | |
33 | 34 | | |
| |||
0 commit comments