Skip to content

Conversation

wprzytula
Copy link
Collaborator

The bug

The found bug is quite severe: any prepared statement would have its consistency set to One by default. This is surprising, because One hasn't been the default consistency for prepared (or any other kind of) statements in CPP Driver since 2015 (as per the changelog)...

The expected behaviour

Anyway, the CPP Driver's behaviour upon preparing is to set consistency in prepared statements to UNKNOWN, which means "use the consistency configured in the exec profile/cluster". This is the behaviour of Rust Driver, too: PreparedStatement has no consistency set by default.

The fix

Thus, the fix is quite simple: we just remove the line that sets consistency to One in the cass_session_prepare_n function.

Testing

Again, the IT for consistencies is being written. The test has already confirmed the bug's existence and the fix.

Pre-review checklist

  • I have split my patch into logically separate commits.
  • All commit messages clearly explain what they change and why.
  • PR description sums up the changes and reasons why they should be introduced.
  • I have implemented Rust unit tests for the features/changes introduced.
  • [ ] I have enabled appropriate tests in Makefile in {SCYLLA,CASSANDRA}_(NO_VALGRIND_)TEST_FILTER.
  • [ ] I added appropriate Fixes: annotations to PR description.

@wprzytula wprzytula added this to the 0.6 milestone Jun 29, 2025
@wprzytula wprzytula self-assigned this Jun 29, 2025
@wprzytula wprzytula added the bug Something isn't working label Jun 29, 2025
@wprzytula wprzytula requested review from Copilot and Lorak-mmk June 29, 2025 07:45
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a severe bug where any prepared statement was erroneously set to a default consistency of One, instead of leaving it as UNKNOWN to use the configured execution profile.

  • Removed the line that set consistency to One in the prepared statement function.
  • Removed the now-unused import of Consistency from scylla::frame::types::Consistency in session.rs, and updated test imports accordingly.
Comments suppressed due to low confidence (2)

scylla-rust-wrapper/src/session.rs:777

  • Consider adding or updating tests in this module to verify that prepared statements inherit the correct default consistency (UNKNOWN) from the execution profile.
    use scylla_cql::Consistency;

@wprzytula wprzytula added the P0 P0 item - absolute must have label Jun 29, 2025
The fixed bug is quite severe: any prepared statement would have its
consistency set to `One` by default. This is surprising, because `One`
hasn't been the default consistency for prepared (or any other kind of)
statements in CPP Driver since 2015 (as per the changelog)...

Anyway, the CPP Driver's behaviour upon preparing is to set consistency
in prepared statements to `UNKNOWN`, which means "use the consistency
configured in the exec profile/cluster". This is the behaviour of Rust
Driver, too: `PreparedStatement` has no consistency set by default.

Thus, the fix is quite simple: we just remove the line that sets
consistency to `One` in the `cass_session_prepare_n` function.
@wprzytula wprzytula force-pushed the fix-prepared-consistency-bug branch from 2b151b6 to 165d955 Compare June 29, 2025 07:51
Copy link
Collaborator

@Lorak-mmk Lorak-mmk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"use the consistency configured in the exec profile/cluster".

What is the cpp-driver default for that? I see that the PR that introduced this set_consistency line aimed to align the behavior with cpp-driver - so perhaps it just went about it the wrong way?

@wprzytula
Copy link
Collaborator Author

wprzytula commented Jun 30, 2025

"use the consistency configured in the exec profile/cluster".

What is the cpp-driver default for that? I see that the PR that introduced this set_consistency line aimed to align the behavior with cpp-driver - so perhaps it just went about it the wrong way?

Per-cluster default consistency

The default per-cluster consistency has changed in time.

  1. One. (2014?)
  2. LocalQuorum.
  3. LocalOne. (2015)

So for many years it's been LocalOne.

Per-exec profile default consistency

It is unset (CASS_CONSISTENCY_UNKNOWN), so by default, the cluster setting prevails.

Per-statement default consistency

It is unset (CASS_CONSISTENCY_UNKNOWN), so by default, the exec profile setting prevails.

Our buggy implementation

The PreparedStatement obtained from Session::prepare() had its statement-level consistency explicitly set to One, which made it override cluster-level and exec profile-level consistencies. Only if someone called cass_statement_set_consistency() after calling cass_prepared_bind() would the consistency be different than One.

This is why I believe this is a severe bug.

@wprzytula wprzytula merged commit ebf4200 into scylladb:master Jun 30, 2025
11 of 19 checks passed
@wprzytula wprzytula deleted the fix-prepared-consistency-bug branch June 30, 2025 16:45
@Lorak-mmk
Copy link
Collaborator

One. (2014?)
LocalQuorum.
LocalOne. (2015)

So for many years it's been LocalOne.

Do you have some links to commits / PRs of that?
I'm interested in their reasoning behind the changes. Its surprising to move from LocalQuorum to LocalOne

@wprzytula wprzytula modified the milestones: 0.6, 0.5.1 Jul 6, 2025
@wprzytula wprzytula mentioned this pull request Jul 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working P0 P0 item - absolute must have
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants