Skip to content
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 for result_metadata_id in PREPARED and EXECUTE messages #1782

Open
wants to merge 3 commits into
base: trunk
Choose a base branch
from

Conversation

worryg0d
Copy link

This PR provides support for the result_metadata_id field in PREPARED response and EXECUTE messages.
This PR is part of Native Protocol v5 support.

@worryg0d worryg0d force-pushed the prepared-statement-metadata-id branch from 860880b to b4e0726 Compare July 22, 2024 10:50
@absurdfarce absurdfarce added the protocol_v5 Tickets related to supporting protocol version 5 label Aug 21, 2024
conn.go Outdated
preparedID: info.id,
params: params,
customPayload: qry.customPayload,
preparedMetadataID: info.request.id,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is definitely not correct. You should send here <result_metadata_id> received from PREPARE response, not the <id> of PREPARE response.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Following part of specification has not been implemented:

If a RESULT/Rows message reports
changed resultset metadata with the Metadata_changed flag, the reported new
resultset metadata must be used in subsequent executions.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! Thanks a lot. Also, I added the described mechanism. Now the driver receives the RESULT/ROWS response it updates the prepared stmt meta and result_metadata_id in the stmtsLRU cache and re-run query execution.

frame.go Outdated
@@ -1604,23 +1611,31 @@ type writeExecuteFrame struct {

// v4+
customPayload map[string][]byte

// v5+
preparedMetadataID []byte
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would consider following naming convention from protocol specification, so this would be result_metadata_id.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also good catch! Thanks! I renamed it no resultMetadataID

frame.go Outdated
@@ -952,6 +955,10 @@ func (f *framer) parsePreparedMetadata() preparedMetadata {
// TODO: deduplicate this from parseMetadata
meta := preparedMetadata{}

if f.proto > protoVersion4 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<id> field of PREPARE response is already present in V4. Here we are missing reading of <result_metadata_id>.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry for the misunderstanding here. The id field in preparedMetadata doesn't represent <id> in the specification, but result_metadata_id.
Also, the naming is terrible here, which leads to a big misunderstanding.

I moved parsing of the result_metadata_id from this method to the parseResultPrepared method, because the result_metadata_id field is a part of the PREPARED message, not its metadata.

@@ -127,3 +127,27 @@ func TestFrameReadTooLong(t *testing.T) {
t.Fatalf("expected to get header %v got %v", opReady, head.op)
}
}

func Test_framer_writeExecuteFrame_preparedMetadataID(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need an integration test to validate <result_metadata_id> logic. Details of why it was included can be found in ticket CASSANDRA-10786.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I totally agree with you here. We should run tests over C* to ensure the logic works fine. However, I struggled with triggering C* to return a <new_metadata_id> by changing the table columns number, but C* responded with UNPREPARED error message, not the RESULT/ROWS.

Could you please give me some advices on how to trigger this mechanism?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you merge all those V5 pull requests into one branch and one PR? I have a test nearly ready, but wanted to double test it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lukasz-antoniak Yes, here it is 1882

… result metadata updating mechanism in the stmts cache in order to avoid stmt re-preparing.
@joao-r-reis
Copy link
Contributor

Can this be closed in favor of #1822 ?

@worryg0d
Copy link
Author

worryg0d commented Oct 1, 2024

Can this be closed in favor of #1822 ?

Replied in #1778.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
protocol_v5 Tickets related to supporting protocol version 5
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants