Skip to content

Commit fc57b1d

Browse files
committed
cluster: address fallback review feedback
1 parent a94d092 commit fc57b1d

4 files changed

Lines changed: 16 additions & 19 deletions

File tree

cassandra/cluster.py

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -625,15 +625,15 @@ class ControlConnectionQueryFallback(enum.Enum):
625625
available. Session startup is allowed to proceed even if the initial pool
626626
attempts all fail.
627627
628-
``NoNodePoolFallback`` disables node-pool creation for the session and uses
628+
``SkipPoolCreation`` disables node-pool creation for the session and uses
629629
the control-connection fallback path for application queries.
630630
631631
The fallback path is not used for requests targeted to an explicit host.
632632
"""
633633

634634
Disabled = "Disabled"
635635
Fallback = "Fallback"
636-
NoNodePoolFallback = "NoNodePoolFallback"
636+
SkipPoolCreation = "SkipPoolCreation"
637637

638638

639639
class Cluster(object):
@@ -962,7 +962,7 @@ def default_retry_policy(self, policy):
962962
963963
``Disabled`` keeps the old behavior.
964964
``Fallback`` enables control-connection fallback when no usable node pools exist.
965-
``NoNodePoolFallback`` skips node-pool creation and uses the control connection fallback path.
965+
``SkipPoolCreation`` skips node-pool creation and uses the control connection fallback path.
966966
This fallback is still not used for requests targeted to an explicit host.
967967
"""
968968

@@ -2668,7 +2668,7 @@ def __init__(self, cluster, hosts, keyspace=None):
26682668
# create connection pools in parallel
26692669
self._initial_connect_futures = set()
26702670
fallback_mode = self.cluster.allow_control_connection_query_fallback
2671-
if fallback_mode is not ControlConnectionQueryFallback.NoNodePoolFallback:
2671+
if fallback_mode is not ControlConnectionQueryFallback.SkipPoolCreation:
26722672
for host in hosts:
26732673
future = self.add_or_renew_pool(host, is_host_addition=False)
26742674
if future:
@@ -3283,7 +3283,7 @@ def add_or_renew_pool(self, host, is_host_addition):
32833283
"""
32843284
For internal use only.
32853285
"""
3286-
if self.cluster.allow_control_connection_query_fallback is ControlConnectionQueryFallback.NoNodePoolFallback:
3286+
if self.cluster.allow_control_connection_query_fallback is ControlConnectionQueryFallback.SkipPoolCreation:
32873287
return None
32883288

32893289
distance = self._profile_manager.distance(host)
@@ -3356,7 +3356,7 @@ def update_created_pools(self):
33563356
33573357
For internal use only.
33583358
"""
3359-
if self.cluster.allow_control_connection_query_fallback is ControlConnectionQueryFallback.NoNodePoolFallback:
3359+
if self.cluster.allow_control_connection_query_fallback is ControlConnectionQueryFallback.SkipPoolCreation:
33603360
return set()
33613361

33623362
futures = set()
@@ -4592,7 +4592,7 @@ def _on_timeout(self, _attempts=0):
45924592
self._connection.orphaned_threshold_reached = True
45934593

45944594
pool.return_connection(self._connection, stream_was_orphaned=True)
4595-
elif getattr(self._connection, 'is_control_connection', False):
4595+
elif self._connection.is_control_connection:
45964596
with self._connection.lock:
45974597
self._connection.orphaned_request_ids.add(self._req_id)
45984598
if len(self._connection.orphaned_request_ids) >= self._connection.orphaned_threshold:
@@ -4682,15 +4682,12 @@ def _has_usable_node_pool(self):
46824682
return any(pool and not pool.is_shutdown for pool in pools)
46834683

46844684
def _fallback_to_control_connection(self):
4685-
fallback_mode = getattr(
4686-
self.session.cluster,
4687-
'allow_control_connection_query_fallback',
4688-
ControlConnectionQueryFallback.Disabled)
4685+
fallback_mode = self.session.cluster.allow_control_connection_query_fallback
46894686
if fallback_mode is ControlConnectionQueryFallback.Disabled:
46904687
return False
46914688
if self._host or self._control_connection_query_attempted:
46924689
return False
4693-
if fallback_mode is ControlConnectionQueryFallback.NoNodePoolFallback:
4690+
if fallback_mode is ControlConnectionQueryFallback.SkipPoolCreation:
46944691
return True
46954692
return not self._has_usable_node_pool()
46964693

@@ -4886,7 +4883,7 @@ def start_fetching_next_page(self):
48864883

48874884
def _reprepare(self, prepare_message, host, connection, pool):
48884885
cb = partial(self.session.submit, self._execute_after_prepare, host, connection, pool)
4889-
if pool is None and getattr(connection, 'is_control_connection', False):
4886+
if pool is None and connection.is_control_connection:
48904887
request_id = self._query_control_connection(prepare_message, cb=cb,
48914888
connection=connection, host=host)
48924889
else:
@@ -5110,7 +5107,7 @@ def _execute_after_prepare(self, host, connection, pool, response):
51105107

51115108
# use self._query to re-use the same host and
51125109
# at the same time properly borrow the connection
5113-
if pool is None and getattr(connection, 'is_control_connection', False):
5110+
if pool is None and connection.is_control_connection:
51145111
request_id = self._query_control_connection(connection=connection, host=host)
51155112
else:
51165113
request_id = self._query(host)

tests/integration/standard/test_control_connection_query_fallback.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def test_fallback_executes_queries_when_broadcast_rpc_address_is_unreachable(sel
9898

9999
def test_no_node_pool_fallback_executes_queries_without_creating_pools(self):
100100
self.cluster = TestCluster(
101-
allow_control_connection_query_fallback=ControlConnectionQueryFallback.NoNodePoolFallback,
101+
allow_control_connection_query_fallback=ControlConnectionQueryFallback.SkipPoolCreation,
102102
connect_timeout=1,
103103
monitor_reporting_enabled=False,
104104
)

tests/unit/test_cluster.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,12 +198,12 @@ def test_control_connection_query_fallback_modes(self):
198198
is ControlConnectionQueryFallback.Fallback
199199
)
200200
assert Cluster(
201-
allow_control_connection_query_fallback=ControlConnectionQueryFallback.NoNodePoolFallback
202-
).allow_control_connection_query_fallback is ControlConnectionQueryFallback.NoNodePoolFallback
201+
allow_control_connection_query_fallback=ControlConnectionQueryFallback.SkipPoolCreation
202+
).allow_control_connection_query_fallback is ControlConnectionQueryFallback.SkipPoolCreation
203203

204204
def test_control_connection_query_fallback_no_node_pool_mode_skips_pool_creation(self):
205205
cluster = Cluster(
206-
allow_control_connection_query_fallback=ControlConnectionQueryFallback.NoNodePoolFallback,
206+
allow_control_connection_query_fallback=ControlConnectionQueryFallback.SkipPoolCreation,
207207
monitor_reporting_enabled=False,
208208
)
209209
host = Host("127.0.0.1", SimpleConvictionPolicy, host_id=uuid.uuid4())

tests/unit/test_response_future.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ def set_keyspace_for_all_pools(keyspace, callback):
452452

453453
def test_control_connection_fallback_when_no_usable_pools(self):
454454
session = self.make_basic_session()
455-
session.cluster.allow_control_connection_query_fallback = ControlConnectionQueryFallback.NoNodePoolFallback
455+
session.cluster.allow_control_connection_query_fallback = ControlConnectionQueryFallback.SkipPoolCreation
456456
session.cluster._default_load_balancing_policy.make_query_plan.return_value = ['ip1', 'ip2']
457457
session._pools = {}
458458
connection = self.make_control_connection()

0 commit comments

Comments
 (0)