A cluster should not allow use of statements prepared in another cluster of same JVM

Description

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
at com.datastax.driver.core.RequestHandler.onSet(RequestHandler.java:373)
at com.datastax.driver.core.Connection$Dispatcher.messageReceived(Connection.java:680)
at org.jboss.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:70)

It is best for driver to reject such requests right from the beginning.

Environment

None

Pull Requests

None

Activity

Show:
Olivier Michallat
January 30, 2015, 1:22 PM
Edited

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).

Olivier Michallat
March 30, 2015, 5:19 PM

, 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.

Andy Tolbert
March 30, 2015, 6:21 PM

, 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.

Andy Tolbert
March 31, 2015, 8:21 PM

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.

Fixed

Assignee

Kevin Gallardo

Reporter

Vishy Kasar

Labels

PM Priority

None

Reproduced in

None

Affects versions

None

Fix versions

Pull Request

None

Doc Impact

None

Size

None

External issue ID

None

External issue ID

None

Priority

Minor
Configure