Problem
Fallback considers every non-shutdown pool usable:
|
def _has_usable_node_pool(self): |
|
try: |
|
pools = tuple(self.session._pools.values()) |
|
except (AttributeError, TypeError): |
|
return False |
|
|
|
return any(pool and not pool.is_shutdown for pool in pools) |
|
|
|
def _fallback_to_control_connection(self): |
|
fallback_mode = self.session.cluster.allow_control_connection_query_fallback |
|
if fallback_mode is ControlConnectionQueryFallback.Disabled: |
|
return False |
|
if self._host or self._control_connection_query_attempted: |
|
return False |
|
if fallback_mode is ControlConnectionQueryFallback.SkipPoolCreation: |
|
return True |
|
return not self._has_usable_node_pool() |
A pool can remain non-shutdown while having no live connections. Its borrow_connection() then fails, but the pool suppresses control-connection fallback and the request ends with NoHostAvailable.
The current test encodes this behavior:
|
def test_control_connection_fallback_not_used_when_pool_can_serve(self): |
|
session = self.make_basic_session() |
|
session.cluster.allow_control_connection_query_fallback = ControlConnectionQueryFallback.Fallback |
|
session.cluster._default_load_balancing_policy.make_query_plan.return_value = ['ip1'] |
|
pool = Mock(is_shutdown=False) |
|
pool.borrow_connection.side_effect = NoConnectionsAvailable() |
|
session._pools = {'ip1': pool} |
|
connection = self.make_control_connection() |
|
session.cluster.control_connection._connection = connection |
|
|
|
rf = self.make_response_future(session) |
|
rf.send_request() |
|
|
|
connection.send_msg.assert_not_called() |
|
with pytest.raises(NoHostAvailable): |
|
rf.result() |
Expected behavior
Treat pools with no open/live connections as unusable and allow fallback after the query plan is exhausted.
Problem
Fallback considers every non-shutdown pool usable:
python-driver/cassandra/cluster.py
Lines 5029 to 5045 in b666e5c
A pool can remain non-shutdown while having no live connections. Its
borrow_connection()then fails, but the pool suppresses control-connection fallback and the request ends withNoHostAvailable.The current test encodes this behavior:
python-driver/tests/unit/test_response_future.py
Lines 615 to 630 in b666e5c
Expected behavior
Treat pools with no open/live connections as unusable and allow fallback after the query plan is exhausted.