We're updating the issue view to help you get more done. 

Use per-request keyspace when repreparing on the fly

Description

With native protocol v5 it's possible to prepare a statement that has a per-request keyspace (). But currently, if the statement gets invalidated on the server and we need to reprepare it on the fly, the reprepare doesn't use the keyspace:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 try (CqlSession session = CqlSession.builder().build()) { session.execute("CREATE TABLE IF NOT EXISTS test.foo (k int primary key)"); PreparedStatement pst = session.prepare( SimpleStatement.newInstance("SELECT * FROM foo WHERE k=?").setKeyspace("test")); // Works as expected: session.execute(pst.bind(0)); // Drop and re-create the table to invalidate the prepared statement server side session.execute("DROP TABLE test.foo"); session.execute("CREATE TABLE test.foo (k int primary key)"); // Fails with "InvalidQueryException: No keyspace has been specified" session.execute(pst.bind(0)); }

The source of the bug is this line:

CqlRequestHandler#processErrorResponse

1 Prepare reprepareMessage = new Prepare(repreparePayload.query);

It should be:

1 2 3 4 Prepare reprepareMessage = new Prepare( repreparePayload.query, repreparePayload.keyspace == null ? null : repreparePayload.keyspace.asInternal());

Environment

None

Pull Requests

None

Status

Assignee

Olivier Michallat

Reporter

Olivier Michallat

Labels

None

PM Priority

None

Reproduced in

None

External issue ID

None

External issue ID

None

External issue ID

None

External issue ID

None

External issue ID

None

External issue ID

None

Doc Impact

None

Reviewer

None

Size

None

Fix versions

Priority

Minor