Skip to content

IT: Support set_record_contacted_hosts() and get_attempted_hosts_from_future() #322

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

Merged

Conversation

wprzytula
Copy link
Collaborator

@wprzytula wprzytula commented Jun 17, 2025

This PR re-implements set_record_contacted_hosts() and associated get_attempted_hosts_from_future() integration test functions in the Rust wrapper.

For now, no test using it is enabled. This is because none of them has its other requirements met. In #321, I'll be able to enable DCAware test suite.

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.

BoundStatement was manually constructed in two places. This commit
extracts its internal constructor (`new()`) and uses it in two new
public constructors: `new_unprepared()` and `new_prepared()`, for
deduplication and readability.
We no longer use the term "query" for unprepared statements in the Rust
Driver nor the wrapper. This commit renames `BoundSimpleQuery` to
`BoundSimpleStatement` to reflect this change.
This is the first of the two commits that implement and expose recording
hosts that were attempted during execution of a statement.
This is useful for testing purposes, allowing us to verify which hosts
were attempted during a request.
In particular, some existing integration tests rely on this feature.
Implementing this will allow us to run those tests, as well as write
new tests with more assertions regarding routing.

Implementation involves:
- Implementing `RecordingHistoryListener` that records attempted hosts;
- Adding exposed `testing_statement_set_recording_history_listener` to
  enable recording in the statement's history listener;
- Modifying the session execution to set the history listener if
  recording is enabled;
- Adding a method to retrieve the recorded hosts from the listener
  (which will be used in the next commit).
@wprzytula wprzytula requested review from Lorak-mmk and Copilot June 17, 2025 09:24
@wprzytula wprzytula self-assigned this Jun 17, 2025
@wprzytula wprzytula added the area/testing Related to unit/integration testing label Jun 17, 2025
@wprzytula wprzytula added this to the 0.5 milestone Jun 17, 2025
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 re-implements support for recording and retrieving the hosts attempted during statement execution by adding new Rust wrapper functions and integration testing functionality.

  • Implements new C API functions in the header and their corresponding behavior in the C++ and Rust code.
  • Refactors simple statement naming from BoundSimpleQuery to BoundSimpleStatement and updates CassStatement creation.
  • Integrates recording of attempted hosts via a new RecordingHistoryListener in both future and session handling, with test support and Makefile changes.

Reviewed Changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/testing_rust_impls.h Adds declarations for setting a recording history listener and retrieving attempted hosts.
src/testing.cpp Implements get_attempted_hosts_from_future() using a newly allocated concatenated string.
scylla-rust-wrapper/src/statement.rs Refactors simple statement naming and updates the new_unprepared constructor.
scylla-rust-wrapper/src/session.rs Passes the recording listener in CassFuture::make_raw and related functions.
scylla-rust-wrapper/src/prepared.rs Updates CassStatement construction for prepared statements.
scylla-rust-wrapper/src/integration_testing.rs Implements the recording listener, associated C API functions, and test case.
scylla-rust-wrapper/src/future.rs Introduces a recording_listener field and attempted_hosts() method in CassFuture.
Makefile Updates the test command with new configuration flags.
.github/pull_request_template.md Adds a checklist item for Fixes annotations.

Comment on lines 294 to +295
run-test-unit: install-cargo-if-missing _update-rust-tooling
@cd ${CURRENT_DIR}/scylla-rust-wrapper; cargo test
@cd ${CURRENT_DIR}/scylla-rust-wrapper; RUSTFLAGS="--cfg cpp_rust_unstable --cfg cpp_integration_testing" cargo test
Copy link
Collaborator

@Lorak-mmk Lorak-mmk Jun 17, 2025

Choose a reason for hiding this comment

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

Unrelated: I find this style of Makefile very weird. One reason is that it assumes users env (in this case it uses apt). Other is that is performs unrelated actions (installing cargo using a package manager) when I told it to run tests.

Its fine to have targets / scripts that install stuff, but they should not be in dependencies of normal targets. If they are needed by CI, they should be explicitly called by CI.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You're more than welcome to improve this Makefile!
Especially if this makes it run on my Fedora, or Arch.

@wprzytula wprzytula force-pushed the support-set_record_contacted_hosts branch from 4eca162 to ad90c81 Compare June 17, 2025 10:38
@wprzytula wprzytula requested a review from Lorak-mmk June 17, 2025 10:38
@wprzytula wprzytula force-pushed the support-set_record_contacted_hosts branch from ad90c81 to 68edd1d Compare June 17, 2025 10:42
@wprzytula wprzytula force-pushed the support-set_record_contacted_hosts branch from 68edd1d to 5ed14a4 Compare June 17, 2025 10:53
This commit exposes the `attempted_hosts` method on `CassFuture`,
allowing users to retrieve the hosts that were attempted during
the execution of a future. This can be used in proxy tests in the
wrapper itself, but the main use case is in the C++ integration
tests. The necessary bridging code is implemented in the next commit.
This commit implements the function `testing_future_get_attempted_hosts`
in Rust, as well as includes a test for the new function. It's going to
be used in the C++ integration tests.

I had tough time figuring out how to return a list of attempted hosts'
addresses to C code, so I decided to return a concatenated string of
them in a stringified form, delimited by '\n'. The overhead this
introduces is not important at all, as these are just integration tests.

The caller is responsible for freeing the memory. They must do so by
calling `testing_free_cstring`, because the string is allocated in Rust.

The new unit test, unlike all unit tests so far, is put behind
the #[cfg(cpp_integration_testing)] attribute. In order to run it,
we must to supply the `cpp_integration_testing` flag to RUSTFLAGS.
So far, RUSTFLAGS were configured in .cargo/config.toml, in `[build]`.
As this method of setting RUSTFLAGS does not allow setting different
flags for test target and for the rest of the build, I decided to
set the necessary RUSTFLAGS for tests in the Makefile. Keep in mind
that this will require us to keep the flags there and in the
`.cargo/config.toml` in sync, unfortunately.
`get_attempted_hosts_from_future` was originally implemented in C++
using the internal C++ Driver API. This commit reimplements it using
the new exposed Rust API, namely `testing_future_get_attempted_hosts`.

To finish up, the commit also reimplements `set_record_attempted_hosts`,
which is tightly coupled with the previous function, using
`testing_statement_set_recording_history_listener` (introduced a couple
of commits ago).
This completes the re-implementation of this testing functionality in
Rust.

I'd like to enable some tests that depend on this functionality,
but none of them has all the requirements met yet. Once I rework
the DCAware LBP in a follow-up, I'll be able to enable its tests
thanks to this commit.
@wprzytula wprzytula force-pushed the support-set_record_contacted_hosts branch from 5ed14a4 to dbda206 Compare June 17, 2025 11:02
@wprzytula wprzytula requested a review from Lorak-mmk June 17, 2025 11:12
@wprzytula wprzytula merged commit eb3d6b9 into scylladb:master Jun 17, 2025
12 checks passed
@wprzytula wprzytula deleted the support-set_record_contacted_hosts branch June 17, 2025 11:37
@wprzytula wprzytula mentioned this pull request Jun 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/testing Related to unit/integration testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants