-
Notifications
You must be signed in to change notification settings - Fork 52
DRIVER-153: negotiate and implement SCYLLA_USE_METADATA_ID extension #770
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -573,6 +573,9 @@ def _write_query_params(self, f, protocol_version): | |||||
| if self.timestamp is not None: | ||||||
| flags |= _PROTOCOL_TIMESTAMP_FLAG | ||||||
|
|
||||||
| if self.skip_meta: | ||||||
| flags |= _SKIP_METADATA_FLAG | ||||||
|
|
||||||
| if self.keyspace is not None: | ||||||
| if ProtocolVersion.uses_keyspace_flag(protocol_version): | ||||||
| flags |= _WITH_KEYSPACE_FLAG | ||||||
|
|
@@ -642,6 +645,8 @@ def send_body(self, f, protocol_version): | |||||
| write_string(f, self.query_id) | ||||||
| if ProtocolVersion.uses_prepared_metadata(protocol_version): | ||||||
| write_string(f, self.result_metadata_id) | ||||||
| elif self.result_metadata_id is not None: | ||||||
| write_string(f, self.result_metadata_id) | ||||||
|
Comment on lines
+648
to
+649
|
||||||
| elif self.result_metadata_id is not None: | |
| write_string(f, self.result_metadata_id) |
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.
Agreed. The elif self.result_metadata_id is not None path in send_body is now only reached when the caller explicitly set the field — which only happens in _query() after confirming connection.features.use_metadata_id (or CQL v5). For any connection that didn't negotiate the extension, result_metadata_id remains None and the branch is never taken, so the wire layout is unaffected.
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 is still a problem here. If the result id feature is negotiated on the connection, then you need to ALWAYS send some result metadata id in EXECUTE. Skipping the write_string will result in a protocol error.
Your use_metadata_id may be False even if extension was negotiated, if the server decided to skip the metadata in PREPARED response. In such case, you'll skip writing the id here, and encounter protocol error.
Even if you fix this specific case, there is still possibility of mixed cluster, with some nodes supporting the extension. In that case result_metadata_id will be None, and if you send to a node that has the extension negotiated, you'll again not send the id and encounter protocol error.
To sum up: this serialization here should check if feature is negotiated, and base sending this field only on that.
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.
High: this gate enables
skip_metafor any prepared statement with a non-Noneresult_metadata_id, but some prepared statements still legitimately have no cached result metadata. The repo already has that case intests/integration/standard/test_prepared_statements.py(_test_updated_conditionalassertsprepared_statement.result_metadata is Nonewhileresult_metadata_idstays set for prepared conditional/LWT statements).With
SCYLLA_USE_METADATA_IDnegotiated, this branch will setskip_meta=Trueand send that metadata id anyway. On Scylla, if the request/response metadata ids match, the server keepsNO_METADATAon theEXECUTEresponse instead of forcing metadata back, so the driver reachesrecv_results_rows()with neither response metadata nor cached metadata to decode against. That turns into a real decode failure, not just a missed optimization.I think this needs one more safety condition: only enable
skip_metawhen the prepared statement has usable cached result metadata, and keep it disabled for statements prepared withNO_METADATA/ empty result metadata.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.
Fixed. Added
has_result_metadata = bool(self.prepared_statement.result_metadata)as an additional condition in theuse_metadata_idgate —skip_metais now only enabled when the prepared statement has both aresult_metadata_idand usable cached result metadata. LWT/conditional statements (INSERT ... IF NOT EXISTSetc.) haveresult_metadata_idset butresult_metadata = None(the PREPARE response carriesNO_METADATAfor the result columns), so they correctly fall through toskip_meta=Falseand the server always sends full metadata.On the test side: added
test_query_no_skip_meta_when_result_metadata_is_noneto directly cover this case, and corrected two existing_querytests (test_query_sets_skip_meta_with_scylla_extension,test_query_sets_skip_meta_for_protocol_v5) that were using an empty list[]forresult_metadata— those were accidentally falsy and would have hidden this regression going forward.