Skip to content

Commit 4effe4b

Browse files
committed
populate default lbp on connection
1 parent 4681d3e commit 4effe4b

3 files changed

Lines changed: 23 additions & 1 deletion

File tree

CHANGELOG.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
Bug Fixes
55
---------
66
* Both _set_final_exception/result called for the same ResponseFuture (PYTHON-630)
7+
* Use of DCAwareRoundRobinPolicy raises NoHostAvailable exception (PYTHON-781)
78

89

910
3.11.0

cassandra/cluster.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1175,6 +1175,9 @@ def connect(self, keyspace=None, wait_for_all_pools=False):
11751175

11761176
self.profile_manager.populate(
11771177
weakref.proxy(self), self.metadata.all_hosts())
1178+
self.load_balancing_policy.populate(
1179+
weakref.proxy(self), self.metadata.all_hosts()
1180+
)
11781181

11791182
try:
11801183
self.control_connection.connect()
@@ -2661,7 +2664,13 @@ def _reconnect_internal(self):
26612664
a connection to that host.
26622665
"""
26632666
errors = {}
2664-
for host in self._cluster._default_load_balancing_policy.make_query_plan():
2667+
lbp = (
2668+
self._cluster.load_balancing_policy
2669+
if self._cluster._config_mode == _ConfigMode.LEGACY else
2670+
self._cluster._default_load_balancing_policy
2671+
)
2672+
2673+
for host in lbp.make_query_plan():
26652674
try:
26662675
return self._try_connect(host)
26672676
except ConnectionException as exc:

tests/integration/standard/test_cluster.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,18 @@ def test_profile_load_balancing(self):
824824
# make sure original profile is not impacted
825825
self.assertTrue(session.execute(query, execution_profile='node1')[0].release_version)
826826

827+
def test_setting_lbp_legacy(self):
828+
cluster = Cluster()
829+
self.addCleanup(cluster.shutdown)
830+
cluster.load_balancing_policy = RoundRobinPolicy()
831+
self.assertEqual(
832+
list(cluster.load_balancing_policy.make_query_plan()), []
833+
)
834+
cluster.connect()
835+
self.assertNotEqual(
836+
list(cluster.load_balancing_policy.make_query_plan()), []
837+
)
838+
827839
def test_profile_lb_swap(self):
828840
"""
829841
Tests that profile load balancing policies are not shared

0 commit comments

Comments
 (0)