In a JVM,
Create Cluster 1
Create Session 1 on Cluster 1
Create Cluster 2
Create Session 2 on Cluster 2
Prepare Statement on Session 1
Use that prepared statement to bind a query on Session 2
We know this is the incorrect usage of prepared statements. We should have created prepared statement once per cluster. However the above situation works with out giving any hints to the user that some thing is wrong. Only when the server is bounced, we start getting errors like:
Caused by: com.datastax.driver.core.exceptions.DriverInternalError: Tried to execute unknown prepared query 0x42f722da3923dc793f0d18c665455983
It is best for driver to reject such requests right from the beginning.
The idea is that, before we execute a BoundStatement, we do a simple check that the prepared id exists in the driver's local cache (Cluster.Manager.preparedQueries).
, this could potentially make it into 2.0.10 (it's really trivial and we'd had the fix for a while). Feel free to move it though, the priority is not very high and I have no problem keeping it for 2.0.11.
, that sounds reasonable to me and straightforward enough to test. I believe this may break some existing tests as they prepared on another cluster and used on another to produce some issues more easily. Will make sure that is not the case.
The added testcase PreparedStatementTest#should_fail_when_prepared_on_another_cluster() validates that PreparedStatements cannot be used unless it was previously Prepared by the Cluster.
Executed integration tests to validate this introduced no regressions.