Skip to content

cluster: add control-connection query fallback - #878

Merged
dkropachev merged 1 commit into
masterfrom
dk/add-control-connection-fallback
May 10, 2026
Merged

cluster: add control-connection query fallback#878
dkropachev merged 1 commit into
masterfrom
dk/add-control-connection-fallback

Conversation

@dkropachev

@dkropachevdkropachev commented May 7, 2026

Copy link
Copy Markdown

Summary

Add an opt-in control-connection fallback for application queries when the driver cannot populate normal node pools, which happens in deployments that expose the cluster through a non-broadcast IP address such as a TCP proxy or a node public IP. In that mode the driver can still execute queries over the single control connection, but throughput is poor and connection churn increases the chance of request errors. This option is intentionally disabled by default and should not be used in production.

Also propagate keyspace updates on the fallback path so USE keeps the control connection in sync.

Fixes: #720

Tests

  • uv run python - <<\"PY\" ... pytest tests/unit/test_cluster.py -q -k set_keyspace_for_all_pools_reports_all_errors ... PY
  • uv run python - <<\"PY\" ... pytest tests/unit/test_response_future.py -q -k control_connection_fallback_updates_connection_keyspace ... PY

@dkropachevdkropachev self-assigned this May 7, 2026
@dkropachev
dkropachev marked this pull request as ready for review May 7, 2026 05:58
@dkropachev
dkropachevforce-pushed the dk/add-control-connection-fallback branch from 88b0f45 to 82a5b3cCompareMay 7, 2026 05:59
@dkropachev
dkropachev marked this pull request as draft May 7, 2026 05:59
@dkropachev
dkropachevforce-pushed the dk/add-control-connection-fallback branch from 82a5b3c to 4eb62ceCompareMay 7, 2026 06:10
Comment threadcassandra/cluster.py Outdated
Comment threadcassandra/cluster.py
@dkropachev
dkropachev marked this pull request as ready for review May 7, 2026 11:08
@dkropachev

Copy link
Copy Markdown
Author

cqlsh manual test report

I tested cqlsh with the local driver from /extra/scylladb/python-driver-4, installed into the cqlsh venv as editable scylla-driver 3.29.9.

Test setup:

Scylla container: cqlsh-nodepool-test
Docker network: bridge
Reachable CQL endpoint: 127.0.0.1:19042
Advertised node endpoint: 10.255.255.1:19042

This setup makes the initial control connection reachable, but makes discovered node-pool connections unusable.

Results:

ModeSession startNode-pool behaviorQuery result
DisabledFailsno usable poolNoHostAvailable
FallbackSucceedstries pools, tolerates none usablequery succeeds via control connection
NoNodePoolFallbackSucceedsskips pool creationquery succeeds via control connection

Default Disabled behavior failed as expected:

Connection error: ('Unable to connect to any servers', ['10.255.255.1'])

With ControlConnectionQueryFallback.Fallback, cqlsh succeeded:

No usable node pools; falling back to control connection for host 127.0.0.1:19042
system.now()
--------------------------------------
11708f30-4a04-11f1-9b89-4372a228dacb
(1 rows)

I also verified directly through the driver that the session starts with no node pools and still executes the query:

pools_at_session_start {}
query_result OrderedDict([('system.now()', UUID(...))])
pools_after_query {}

With ControlConnectionQueryFallback.NoNodePoolFallback, cqlsh also succeeded, and the driver skipped pool creation entirely:

pools_at_session_start {}
initial_connect_futures set()
query_result OrderedDict([('system.now()', UUID(...))])
pools_after_query {}

Conclusion: Fallback now handles the intended case: cqlsh can start even when no node pools are reachable, and queries run through the control connection. NoNodePoolFallback also works and explicitly skips node-pool creation.

@dkropachev
dkropachevforce-pushed the dk/add-control-connection-fallback branch 3 times, most recently from d14ab6c to a94d092CompareMay 7, 2026 11:26
Comment threadcassandra/cluster.py
Comment threadcassandra/cluster.py Outdated
Comment threadcassandra/cluster.py
Comment threadcassandra/cluster.py Outdated
Comment threadcassandra/cluster.py
Comment threadcassandra/cluster.py Outdated
Comment threadcassandra/cluster.py
@dkropachev
dkropachevforce-pushed the dk/add-control-connection-fallback branch 2 times, most recently from b50342a to 5f16f20CompareMay 7, 2026 18:04
@dkropachevdkropachev reopened this May 8, 2026
@dkropachev
dkropachevforce-pushed the dk/add-control-connection-fallback branch from 5f16f20 to a37ecceCompareMay 8, 2026 01:06

@Lorak-mmkLorak-mmk left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I have to admit I don't understand the logic and flow around _control_connection_query_attempted. I'll have to just assume it works.

I have 2 more questions regarding SkipPoolCreation:

  • WDYT about changing ProfileManager to return IGNORED distance for all hosts in this mode? It would be additional hardening about unexpected code paths doing something weird. One possible problem is that it may affect control connection, in which case we should not do it.
  • I think Cluster.on_up and Cluster.on_down should also be guarded in SkipPoolCreation mode. We don't want reconnectors to start etc.

@dkropachev
dkropachevforce-pushed the dk/add-control-connection-fallback branch from a37ecce to 16424dcCompareMay 8, 2026 10:32
@dkropachev

Copy link
Copy Markdown
Author

I have to admit I don't understand the logic and flow around _control_connection_query_attempted. I'll have to just assume it works.

I have 2 more questions regarding SkipPoolCreation:

  • WDYT about changing ProfileManager to return IGNORED distance for all hosts in this mode? It would be additional hardening about unexpected code paths doing something weird. One possible problem is that it may affect control connection, in which case we should not do it.
  • I think Cluster.on_up and Cluster.on_down should also be guarded in SkipPoolCreation mode. We don't want reconnectors to start etc.

Great idea, easily can see how it can stop driver spin on pool creation, added.

@dkropachev
dkropachev requested a review from Lorak-mmkMay 8, 2026 10:33

@sylwiaszunejkosylwiaszunejko left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Looks good now

@dkropachev
dkropachevforce-pushed the dk/add-control-connection-fallback branch from 16424dc to b0e8df1CompareMay 8, 2026 12:35
Comment threadtests/unit/test_cluster.py Fixed
Add an opt-in control-connection fallback for application queries when the driver cannot populate normal node pools, which happens in deployments that expose the cluster through a non-broadcast IP address such as a TCP proxy or a node public IP. In that mode the driver can still execute queries over the single control connection, but throughput is poor and connection churn increases the chance of request errors. This option is intentionally disabled by default and should not be used in production.
Also propagate keyspace updates on the fallback path so USE keeps the control connection in sync.
Tests:
- tests/unit/test_cluster.py::ClusterTest::test_set_keyspace_for_all_pools_reports_all_errors
- tests/unit/test_response_future.py::ResponseFutureTests::test_control_connection_fallback_updates_connection_keyspace
@dkropachev
dkropachevforce-pushed the dk/add-control-connection-fallback branch from b0e8df1 to baeae28CompareMay 10, 2026 04:30
@dkropachev
dkropachev merged commit 84b599c into masterMay 10, 2026
24 of 25 checks passed
@dkropachev
dkropachev deleted the dk/add-control-connection-fallback branch May 10, 2026 04:53
aleksbykov added a commit to aleksbykov/scylla-cluster-tests that referenced this pull request May 14, 2026
Enable ControlConnectionQueryFallback.Fallback for use_zero_nodes sessions so queries can continue through the driver control connection when zero-token topologies leave no usable node pools.
Refs: scylladb/python-driver#878
fruch pushed a commit to scylladb/scylla-cluster-tests that referenced this pull request May 20, 2026
Enable ControlConnectionQueryFallback.Fallback for use_zero_nodes sessions so queries can continue through the driver control connection when zero-token topologies leave no usable node pools.
Refs: scylladb/python-driver#878
fruch pushed a commit to scylladb/scylla-cluster-tests that referenced this pull request May 20, 2026
Enable ControlConnectionQueryFallback.Fallback for use_zero_nodes sessions so queries can continue through the driver control connection when zero-token topologies leave no usable node pools.
Refs: scylladb/python-driver#878
(cherry picked from commit 0a2025a)
Sign up for freeto 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.

SCT failing to connect via public adddress with scylla-driver==3.29.8

3 participants

@dkropachev@Lorak-mmk@sylwiaszunejko