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

Make RawBatchValuesIteratorAdapter length equal to its internal BatchValuesIter length #1142

Merged
merged 3 commits into from
Dec 7, 2024

Conversation

Lorak-mmk
Copy link
Collaborator

@Lorak-mmk Lorak-mmk commented Dec 6, 2024

When executing batch statement, the amount of statements should be equal to amount of batch values.
This is checked in scylla-cql/src/frame/request/batch.rs in impl of Batch, specifically it's do_serialize method.
This method iterates over statements, serializes the statement and serializes the values for the statement.

If the value iterator returns None, then there were not enough values, so it returns an error.
After serialization it verifies that the iterator is finished - if it is not, then there are too many values.

The problem is that the length of RawBatchValuesIteratorAdapter is limited to the amount
of statements, because all of it's methods first try to get next serialization context, and if it is not present, return None.
This limits the length of this iterator to the amount of statement, so the second check (the one after serializing all the statements) couldn't do it's job.

The fix is to make sure that the length of RawBatchValuesIteratorAdapter is always equal to the length of its internal BatchValuesIterator.
This is done by:

  • Ignoring the return value of self.contexts.next() in is_empty_next and skip_next
  • Using empty serialization context as a default value in serialize_next.

Fixes #1114

Pre-review checklist

  • I have split my patch into logically separate commits.
  • All commit messages clearly explain what they change and why.
  • I added relevant tests for new features and bug fixes.
  • All commits compile, pass static checks and pass test.
  • PR description sums up the changes and reasons why they should be introduced.
  • I have provided docstrings for the public items that I want to introduce.
  • I have adjusted the documentation in ./docs/source/.
  • I added appropriate Fixes: annotations to PR description.

The length of this iterator should be equal to the length of its internal
`BatchValuesIter`. In other words, the amount of serialization contexts should
not affect this length. Otherwise, the caller is not able to detect
a situation when value count is different than statement count.
@Lorak-mmk Lorak-mmk added this to the 0.15.1 milestone Dec 6, 2024
Copy link

github-actions bot commented Dec 6, 2024

cargo semver-checks found no API-breaking changes in this PR! 🎉🥳
Checked commit: 559583f

wprzytula
wprzytula previously approved these changes Dec 7, 2024
@wprzytula wprzytula added the bug Something isn't working label Dec 7, 2024
Functional programming and iterators are the supreme, concise style!
@Lorak-mmk Lorak-mmk merged commit d7a02a4 into scylladb:main Dec 7, 2024
11 checks passed
@Lorak-mmk Lorak-mmk deleted the batch-bugfix branch December 11, 2024 14:46
wprzytula pushed a commit to wprzytula/scylla-rust-driver that referenced this pull request Dec 11, 2024
Make RawBatchValuesIteratorAdapter length equal to its internal BatchValuesIter length

(cherry picked from commit d7a02a4)
@wprzytula wprzytula mentioned this pull request Dec 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

When N of batch of statements is smaller than N of values, session.batch() silently drops extra values.
2 participants