Commit fa14e80
committed
DRIVER-153: negotiate and implement SCYLLA_USE_METADATA_ID extension
Implement the SCYLLA_USE_METADATA_ID protocol extension, which backports
the CQL v5 prepared-statement metadata-id mechanism to earlier protocol
versions. When negotiated, the server includes a hash of the result
metadata in the PREPARE response; the driver sends it back with every
EXECUTE, allowing the server to omit result metadata from responses
(skip_meta) and to report schema changes with METADATA_CHANGED plus
fresh metadata, which the driver adopts automatically.
protocol_features.py: parse the extension from SUPPORTED, echo it in
STARTUP, expose it as ProtocolFeatures.use_metadata_id.
protocol.py: ExecuteMessage carries connection-independent request data
(skip_meta, result_metadata_id) fixed at construction; serialization
decides the wire format from the (protocol_version, protocol_features)
that Connection.send_msg supplies for the serving connection:
- The metadata-id field is written iff the connection speaks CQL v5+ or
negotiated the extension - always, on such connections. An empty
sentinel (b'') is written when the statement has no id (prepared
before the extension was active, e.g. during a rolling upgrade, or an
LWT statement): the sentinel mismatch makes the server respond with
METADATA_CHANGED plus the current id and metadata, so such statements
acquire an id on their first execution. This also fixes a TypeError
on v5 when result_metadata_id was None.
- _SKIP_METADATA_FLAG is written only when the SCYLLA_USE_METADATA_ID
extension is negotiated on the connection; without the metadata-id
mechanism a schema change after PREPARE would leave the driver decoding
rows with stale cached metadata. This is deliberately narrower than the
metadata-id field above: on native CQL v5 the field is part of the
frame layout, but the driver does not request skip there. Upstream
never emitted _SKIP_METADATA_FLAG on any version (_write_query_params
never wrote it), and enabling the skip optimization for native v5 is a
separate change kept out of scope for this Scylla extension.
Because messages are immutable after construction, every send path is
correct without per-path setup - including the control-connection
fallback - and concurrent sends of the same message (speculative
executions) cannot race on per-connection state.
query.py: PreparedStatement stores (result_metadata, result_metadata_id)
as one tuple replaced in a single attribute assignment, read through
compatibility properties and updated via update_result_metadata().
Response callbacks update statements while request threads read them; a
torn pair (fresh id + stale metadata) would make the server skip sending
metadata while rows are decoded against the wrong columns, with no
recovery. The compatibility setters are documented as non-atomic
relative to each other - update_result_metadata() is the atomic path;
the setters exist only for callers assigning the old individual
attributes.
cluster.py: _create_response_future snapshots the pair once and requests
skip_meta only when the statement has both an id and usable cached
metadata (result_metadata is None for NO_METADATA/LWT statements and []
for zero-column statements; neither can nor needs to skip metadata). The
same snapshot is handed to the ResponseFuture, so a skip_meta response is
decoded against the metadata that pairs with the id the message sent -
not a later re-read of the statement cache, which a concurrent
METADATA_CHANGED could have replaced between construction and send (and
which also keeps speculative sends of one message internally consistent).
_set_result adopts a METADATA_CHANGED response by replacing the pair
atomically; a response carrying a new id without column metadata is
ignored with a warning, since adopting the id alone would create the
unrecoverable stale-decode state.
skip_meta additionally stays off for continuous paging (@dkropachev):
Connection.process_msg hardcodes result_metadata=None for every page
after the first, since it isn't threaded through the paging session -
a skip_meta response has nothing to decode page 2+ against, and would
crash on it.
_execute_after_prepare refreshes the pair from exactly what the
reprepare response carries, including the id (@dkropachev): falling
back to the previously cached id when the response has none risks
pairing it with metadata from a different schema version than the one
that id was computed for - e.g. if the schema changed and then reverted
between the two PREPAREs, the old id can become valid again for the
current schema while paired locally with an intermediate version's
metadata, with no server-side mismatch to catch it. Dropping it instead
lets the next id-aware execute re-acquire a correctly paired id through
the same b'' sentinel self-healing path a never-prepared statement uses.
docs/scylla-specific.rst: documents the extension and its behaviour,
worded so the skip_meta optimization reads as conditional on the
extension being negotiated rather than pre-existing default behaviour.
CHANGELOG.rst: add a Features entry for the extension.1 parent bcc2d3d commit fa14e80
6 files changed
Lines changed: 247 additions & 19 deletions
File tree
- cassandra
- docs
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
4 | 10 | | |
5 | 11 | | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
6 | 17 | | |
7 | 18 | | |
8 | 19 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3047 | 3047 | | |
3048 | 3048 | | |
3049 | 3049 | | |
| 3050 | + | |
| 3051 | + | |
| 3052 | + | |
| 3053 | + | |
3050 | 3054 | | |
3051 | 3055 | | |
3052 | 3056 | | |
| |||
3058 | 3062 | | |
3059 | 3063 | | |
3060 | 3064 | | |
| 3065 | + | |
| 3066 | + | |
| 3067 | + | |
| 3068 | + | |
| 3069 | + | |
| 3070 | + | |
| 3071 | + | |
| 3072 | + | |
| 3073 | + | |
| 3074 | + | |
| 3075 | + | |
| 3076 | + | |
| 3077 | + | |
| 3078 | + | |
3061 | 3079 | | |
3062 | 3080 | | |
3063 | 3081 | | |
3064 | | - | |
| 3082 | + | |
| 3083 | + | |
3065 | 3084 | | |
3066 | | - | |
| 3085 | + | |
3067 | 3086 | | |
3068 | 3087 | | |
3069 | 3088 | | |
| |||
3090 | 3109 | | |
3091 | 3110 | | |
3092 | 3111 | | |
3093 | | - | |
| 3112 | + | |
3094 | 3113 | | |
3095 | 3114 | | |
3096 | 3115 | | |
| |||
4717 | 4736 | | |
4718 | 4737 | | |
4719 | 4738 | | |
| 4739 | + | |
4720 | 4740 | | |
4721 | 4741 | | |
4722 | 4742 | | |
4723 | 4743 | | |
4724 | 4744 | | |
4725 | | - | |
| 4745 | + | |
| 4746 | + | |
4726 | 4747 | | |
4727 | 4748 | | |
4728 | 4749 | | |
| |||
4733 | 4754 | | |
4734 | 4755 | | |
4735 | 4756 | | |
| 4757 | + | |
| 4758 | + | |
| 4759 | + | |
| 4760 | + | |
| 4761 | + | |
| 4762 | + | |
4736 | 4763 | | |
4737 | 4764 | | |
4738 | 4765 | | |
| |||
4956 | 4983 | | |
4957 | 4984 | | |
4958 | 4985 | | |
4959 | | - | |
| 4986 | + | |
4960 | 4987 | | |
4961 | 4988 | | |
4962 | 4989 | | |
| |||
5010 | 5037 | | |
5011 | 5038 | | |
5012 | 5039 | | |
5013 | | - | |
| 5040 | + | |
5014 | 5041 | | |
5015 | 5042 | | |
5016 | 5043 | | |
| |||
5175 | 5202 | | |
5176 | 5203 | | |
5177 | 5204 | | |
| 5205 | + | |
| 5206 | + | |
| 5207 | + | |
| 5208 | + | |
| 5209 | + | |
| 5210 | + | |
| 5211 | + | |
| 5212 | + | |
| 5213 | + | |
| 5214 | + | |
| 5215 | + | |
| 5216 | + | |
| 5217 | + | |
| 5218 | + | |
| 5219 | + | |
| 5220 | + | |
| 5221 | + | |
| 5222 | + | |
| 5223 | + | |
| 5224 | + | |
| 5225 | + | |
| 5226 | + | |
| 5227 | + | |
| 5228 | + | |
| 5229 | + | |
| 5230 | + | |
| 5231 | + | |
5178 | 5232 | | |
5179 | 5233 | | |
5180 | 5234 | | |
| |||
5325 | 5379 | | |
5326 | 5380 | | |
5327 | 5381 | | |
5328 | | - | |
5329 | | - | |
5330 | | - | |
5331 | | - | |
| 5382 | + | |
| 5383 | + | |
| 5384 | + | |
| 5385 | + | |
| 5386 | + | |
| 5387 | + | |
| 5388 | + | |
| 5389 | + | |
| 5390 | + | |
| 5391 | + | |
| 5392 | + | |
5332 | 5393 | | |
5333 | 5394 | | |
5334 | 5395 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
558 | 558 | | |
559 | 559 | | |
560 | 560 | | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
561 | 569 | | |
562 | 570 | | |
563 | 571 | | |
| |||
576 | 584 | | |
577 | 585 | | |
578 | 586 | | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
579 | 590 | | |
580 | 591 | | |
581 | 592 | | |
| |||
625 | 636 | | |
626 | 637 | | |
627 | 638 | | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
628 | 650 | | |
629 | 651 | | |
630 | 652 | | |
| |||
638 | 660 | | |
639 | 661 | | |
640 | 662 | | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
641 | 680 | | |
642 | 681 | | |
643 | 682 | | |
644 | 683 | | |
645 | 684 | | |
646 | | - | |
647 | | - | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
648 | 691 | | |
649 | 692 | | |
650 | 693 | | |
| |||
748 | 791 | | |
749 | 792 | | |
750 | 793 | | |
751 | | - | |
| 794 | + | |
752 | 795 | | |
753 | 796 | | |
754 | 797 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
| 21 | + | |
20 | 22 | | |
21 | 23 | | |
22 | 24 | | |
23 | | - | |
| 25 | + | |
| 26 | + | |
24 | 27 | | |
25 | 28 | | |
26 | 29 | | |
27 | 30 | | |
28 | 31 | | |
| 32 | + | |
29 | 33 | | |
30 | 34 | | |
31 | 35 | | |
32 | 36 | | |
33 | 37 | | |
34 | 38 | | |
35 | 39 | | |
| 40 | + | |
36 | 41 | | |
37 | | - | |
| 42 | + | |
| 43 | + | |
38 | 44 | | |
39 | 45 | | |
40 | 46 | | |
| |||
60 | 66 | | |
61 | 67 | | |
62 | 68 | | |
| 69 | + | |
| 70 | + | |
63 | 71 | | |
64 | 72 | | |
65 | 73 | | |
| |||
84 | 92 | | |
85 | 93 | | |
86 | 94 | | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
87 | 100 | | |
88 | 101 | | |
89 | 102 | | |
| |||
0 commit comments