Skip to content

Add Session.wait_for_schema_agreement to replace ControlConnection.wait_for_schema_agreement#877

Merged
dkropachev merged 2 commits intoscylladb:masterfrom
dkropachev:dk/session-wait-for-schema-agreement-api
May 8, 2026
Merged

Add Session.wait_for_schema_agreement to replace ControlConnection.wait_for_schema_agreement#877
dkropachev merged 2 commits intoscylladb:masterfrom
dkropachev:dk/session-wait-for-schema-agreement-api

Conversation

@dkropachev
Copy link
Copy Markdown
Collaborator

@dkropachev dkropachev commented May 7, 2026

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.

Summary

Fixes: #604

This change adds a session-scoped schema agreement API and moves callers over to it.

Session.wait_for_schema_agreement() queries schema_version from system.local on the connected hosts selected by rack, dc, or cluster scope. It uses regular host-targeted session queries, respects Cluster.max_schema_agreement_wait and the control-connection timeout, and retries until the outer schema-agreement deadline expires.

ControlConnection.wait_for_schema_agreement() is kept as a compatibility wrapper, but the implementation now lives under _wait_for_schema_agreement() and the public method is deprecated in favor of Session.wait_for_schema_agreement(). The control-connection wait path is meant for internal metadata refresh use, not as a user-facing schema agreement API. It observes schema agreement from a single node, assuming the schema-changing statement was run on that host. Using it directly from user code can therefore produce false positives when the statement was run on a different host than the control connection.

The integration callers that explicitly waited on schema agreement now use the session API.

Testing

Focused unit coverage passed for:

  • tests/unit/test_control_connection.py
  • tests/unit/test_session_schema_agreement.py
  • tests/unit/test_cluster.py

That focused run currently reports 49 passed, 28 skipped.

I did not rerun the full repo-ci workflow after the latest simplification.

Integration scenarios

The integration call sites updated in this series are:

  • tests/integration/long/test_schema.py
  • tests/integration/standard/test_udts.py

Those scenarios were not run locally in this branch.

@dkropachev dkropachev force-pushed the dk/session-wait-for-schema-agreement-api branch from 60de2cb to 7669675 Compare May 7, 2026 05:44
@dkropachev dkropachev changed the title schema-agreement: add session wait API Add Session.wait_for_schema_agreement to replace ControlConnection.wait_for_schema_agreement May 7, 2026
@dkropachev dkropachev force-pushed the dk/session-wait-for-schema-agreement-api branch from 837644c to 30fd542 Compare May 7, 2026 06:08
@dkropachev dkropachev marked this pull request as ready for review May 7, 2026 06:17
@dkropachev dkropachev force-pushed the dk/session-wait-for-schema-agreement-api branch from 30fd542 to 25e148d Compare May 7, 2026 06:18
Comment thread cassandra/cluster.py Outdated
Copy link
Copy Markdown

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

Adds a session-scoped schema agreement API (Session.wait_for_schema_agreement) and transitions existing call sites away from the control-connection implementation, addressing failures when the control connection is unhealthy/closed and improving correctness when schema changes are executed on non-control-connection hosts.

Changes:

  • Introduces Session.wait_for_schema_agreement(wait_time=None, scope=...) that checks system.local.schema_version via host-targeted session queries across connected hosts.
  • Deprecates ControlConnection.wait_for_schema_agreement() into a compatibility wrapper and moves logic to _wait_for_schema_agreement() for internal metadata-refresh flows.
  • Updates docs and unit/integration tests to validate the new session behavior and migrate callers.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
cassandra/cluster.py Adds Session.wait_for_schema_agreement with scoped host selection; deprecates ControlConnection.wait_for_schema_agreement in favor of _wait_for_schema_agreement.
docs/api/cassandra/cluster.rst Documents Session.wait_for_schema_agreement in the public API docs.
tests/unit/test_session_schema_agreement.py Adds focused unit tests for session-scoped schema agreement behavior.
tests/unit/test_control_connection.py Updates tests to use _wait_for_schema_agreement internally and asserts deprecation warning behavior on the public wrapper.
tests/unit/test_cluster.py Adds unit coverage for host selection scopes and retry/error behavior in Session.wait_for_schema_agreement.
tests/integration/standard/test_udts.py Migrates integration usage to Session.wait_for_schema_agreement.
tests/integration/long/test_schema.py Migrates integration usage to Session.wait_for_schema_agreement.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread cassandra/cluster.py Outdated
Comment thread cassandra/cluster.py Outdated
Copy link
Copy Markdown

@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.

You added type hints for some arguments, but not all. Please make sure all arguments in cluster.py are typed.

Comment thread cassandra/cluster.py Outdated
Comment thread cassandra/cluster.py Outdated
Comment thread cassandra/cluster.py
Comment thread cassandra/cluster.py
Comment thread cassandra/cluster.py Outdated
Comment thread cassandra/cluster.py Outdated
Comment thread cassandra/cluster.py Outdated
Comment thread cassandra/cluster.py Outdated
Comment thread cassandra/cluster.py
Comment thread cassandra/cluster.py Outdated
@dkropachev dkropachev force-pushed the dk/session-wait-for-schema-agreement-api branch 3 times, most recently from 12e789c to 539c714 Compare May 7, 2026 12:01
@sylwiaszunejko
Copy link
Copy Markdown
Collaborator

I believe last two commits should be squashed into previous commits to make the history clean

@dkropachev
Copy link
Copy Markdown
Collaborator Author

I believe last two commits should be squashed into previous commits to make the history clean

fixed

@dkropachev dkropachev force-pushed the dk/session-wait-for-schema-agreement-api branch from 539c714 to 0140afc Compare May 7, 2026 13:31
Comment thread cassandra/cluster.py Outdated
Comment thread cassandra/cluster.py Outdated
Comment thread cassandra/cluster.py
@dkropachev dkropachev force-pushed the dk/session-wait-for-schema-agreement-api branch from 0140afc to 13bd713 Compare May 7, 2026 18:37
@dkropachev dkropachev requested a review from Lorak-mmk May 7, 2026 18:37
@dkropachev dkropachev force-pushed the dk/session-wait-for-schema-agreement-api branch from 13bd713 to 0d8250e Compare May 7, 2026 19:48
@dkropachev dkropachev force-pushed the dk/session-wait-for-schema-agreement-api branch from 0d8250e to c2c3c1c Compare May 8, 2026 01:06
Copy link
Copy Markdown

@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.

Looks good, just 2 small comments.

Comment thread cassandra/cluster.py Outdated
Comment thread cassandra/cluster.py
dkropachev added 2 commits May 8, 2026 06:44
Add Session.wait_for_schema_agreement() as a session-scoped schema agreement check. The new API queries schema_version from system.local on the connected hosts selected by the requested rack, dc, or cluster scope, respects Cluster.max_schema_agreement_wait and the control-connection metadata timeouts, and bounds the fan-out with configurable parallelism.

Update the public Session docs and switch the integration callers that were explicitly waiting on schema agreement to use the session API. Add unit coverage for agreement, retries, busy connections, missing pools, batching, scope filtering, and invalid scope handling.
…ment

Keep ControlConnection.wait_for_schema_agreement() as a compatibility wrapper, but move the existing implementation to _wait_for_schema_agreement() and deprecate the public method in favor of Session.wait_for_schema_agreement(). This lets the control-connection refresh path continue using the old logic internally without emitting warnings.

The control-connection wait path was designed for internal metadata refresh use, not as a user-facing schema agreement API.
It observes schema agreement from one single node, assuming that schema change statement have been ran on that host.
Using it by users will lead to false positives, if user ran statement on
a host different from host of control connection.

Update the unit tests to call the internal helper everywhere a warning is not expected, add explicit deprecation coverage for the public wrapper, and set stacklevel=2 so the warning points at the caller instead of inside the driver.
@dkropachev dkropachev force-pushed the dk/session-wait-for-schema-agreement-api branch from c2c3c1c to d050c34 Compare May 8, 2026 10:44
@dkropachev dkropachev requested a review from Lorak-mmk May 8, 2026 10:45
@dkropachev dkropachev merged commit ef7c2d0 into scylladb:master May 8, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

wait_for_schema_agreement fails when connection is closed

4 participants