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

Warn if PreparedStatement's consistency level is ignored #304

Open
nyh opened this issue May 26, 2024 · 0 comments
Open

Warn if PreparedStatement's consistency level is ignored #304

nyh opened this issue May 26, 2024 · 0 comments
Assignees
Labels

Comments

@nyh
Copy link

nyh commented May 26, 2024

Our documentation of PreparedStatement (see https://java-driver.docs.scylladb.com/stable/manual/core/statements/prepared/) doesn't explain too clearly what the ConsistencyLevel options does (Datastax's documentation, https://docs.datastax.com/en/drivers/java/2.1/com/datastax/driver/core/PreparedStatement.html, is clearer), but to make a long story short:

The consistency level given when preparing a PreparedStatement has no immediate effect. All that happens is that the given consistency-level value is saved in the PreparedStatement Java object - and only later when the prepared statement is bound into a BoundStatement, this saved consistency-level is inherited by the new object, and when the bound statement it is executed, the consistency level is sent via the CQL protocol. So far so good.

@michoecho discovered a case where a user was using a batch statement with a prepared statement in it, something like

BatchStatementBuilder batchStatementBuilder = new BatchStatementBuilder(BatchType.LOGGED);
batchStatementBuilder.addStatement(myPreparedStatement.bind(...));

The problem is that a batch statement has its own consistency level setting, and only that setting is sent to the server (CQL only allows one consistency setting per statement - even if it's a batch). The consistency level variable set in myPreparedStatement and copied to the bind() output is outright ignored!

Note how confusing this is - the user may think that he created a prepared statement with QUORUM consistency, but when when inserting it into a batch statement, it ends up executed using the batch statement's default consistency level which is usually ONE, resulting in incorrect consistency!

I think BatchStatementBuilder should check if any of the of the statements added by addStatement() has a different (or just higher?) consistency level requirement than it itself has, and if that situation is detected, the request should produce a run-time warning, or even run-time error and not run at all.

I don't know if we have a similar problem also in drivers of other languages :-(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants