Skip to content

Ensure set_prepare_statement is called once only per query_id #17

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

Closed
wants to merge 2 commits into from
Closed

Ensure set_prepare_statement is called once only per query_id #17

wants to merge 2 commits into from

Conversation

jnidzwetzki
Copy link

The function set_prepare_statement(...) is called with the same query_id and different values for query_text. As a result, the mapping between query_id and query_text will become inconsistent and setup_prepared_statements(...) is preparing wrong (or empty) statements on a new connection.

You can reproduce this issue by executing the prepared statement from the demo (demo/cql_query) repeated in a multi-node environment. set_prepare_statement(...) will be called with the same query_id and these values:

-+-
Query text is: SELECT * FROM schema_keyspaces WHERE keyspace_name=?
Query text is:
Query text is: USE system;
Query text is: SELECT * from schema_keyspaces;
-+-

The output of the demo is:

-+-
[...]
LOG: sending message: 0x01007e0700000013 {version: 0x01, flags: 0x00, stream: 0x7e, opcode: 0x07, length: 19} USE "system"; CQL_CONSISTENCY_ONE
LOG: wrote to socket 27 bytes
LOG: received header for message 0x81007e080000000c {version: 0x81, flags: 0x00, stream: 0x7e, opcode: 0x08, length: 12}
LOG: received body for message 0x81007e080000000c {version: 0x81, flags: 0x00, stream: 0x7e, opcode: 0x08, length: 12}
LOG: received result message 0x81007e080000000c {version: 0x81, flags: 0x00, stream: 0x7e, opcode: 0x08, length: 12}
LOG: sending message: 0x01007e0900000039 {version: 0x01, flags: 0x00, stream: 0x7e, opcode: 0x09, length: 57} SELECT * FROM schema_keyspaces WHERE keyspace_name=?;
LOG: wrote to socket 65 bytes
LOG: received header for message 0x81007e0800000049 {version: 0x81, flags: 0x00, stream: 0x7e, opcode: 0x08, length: 73}
LOG: received body for message 0x81007e0800000049 {version: 0x81, flags: 0x00, stream: 0x7e, opcode: 0x08, length: 73}
LOG: received result message 0x81007e0800000049 {version: 0x81, flags: 0x00, stream: 0x7e, opcode: 0x08, length: 73}
LOG: sending message: 0x01007e0a00000025 {version: 0x01, flags: 0x00, stream: 0x7e, opcode: 0x0a, length: 37} EXECUTE 0x9523a7ae8218a43a294345fa7aebb109 CQL_CONSISTENCY_ONE
LOG: wrote to socket 45 bytes
LOG: received header for message 0x81007e0800000073 {version: 0x81, flags: 0x00, stream: 0x7e, opcode: 0x08, length: 115}
LOG: received body for message 0x81007e0800000073 {version: 0x81, flags: 0x00, stream: 0x7e, opcode: 0x08, length: 115}
LOG: received result message 0x81007e0800000073 {version: 0x81, flags: 0x00, stream: 0x7e, opcode: 0x08, length: 115}
execute successful? true

The mapping between query_id and query_text is now inconsistent
the driver is trying to prepare the statement "" (empty statement)
instead of preparing:
SELECT * FROM schema_keyspaces WHERE keyspace_name=?;

LOG: sending message: 0x01007e0900000004 {version: 0x01, flags: 0x00, stream: 0x7e, opcode: 0x09, length: 4}
LOG: wrote to socket 12 bytes
LOG: received header for message 0x81007e0000000036 {version: 0x81, flags: 0x00, stream: 0x7e, opcode: 0x00, length: 54}
LOG: received body for message 0x81007e0000000036 {version: 0x81, flags: 0x00, stream: 0x7e, opcode: 0x00, length: 54}
execute successful? false
Error is: could not obtain viable client from the pool.
LOG: sending message: 0x01007e0900000004 {version: 0x01, flags: 0x00, stream: 0x7e, opcode: 0x09, length: 4}
LOG: wrote to socket 12 bytes
LOG: received header for message 0x81007e0000000036 {version: 0x81, flags: 0x00, stream: 0x7e, opcode: 0x00, length: 54}
LOG: received body for message 0x81007e0000000036 {version: 0x81, flags: 0x00, stream: 0x7e, opcode: 0x00, length: 54}
execute successful? false
Error is: could not obtain viable client from the pool.
[...]
-+-

I'm not sure if this is a real bugfix or only a workaround for this issue.

@jstasiewicz
Copy link
Contributor

This looks a little disturbing. Thank you for the report and for the patch, but I'll hold the merge back until I fully understand the origins of this issue.

@jnidzwetzki
Copy link
Author

Thank you very much. Your patch works perfectly for me.

@jnidzwetzki jnidzwetzki closed this Mar 4, 2014
@jnidzwetzki jnidzwetzki deleted the prepared-patch branch March 4, 2014 21:21
mpenick pushed a commit that referenced this pull request Aug 3, 2016
Added ClusterBuilder->withPort($port)
mpenick added a commit that referenced this pull request Jan 14, 2020
jul-stas added a commit to jul-stas/cpp-driver that referenced this pull request Jan 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants