Skip to content

Commit 6de799f

Browse files
Don't check if host is in initial contact points when setting default local_dc
1 parent dbb1cdf commit 6de799f

File tree

1 file changed

+5
-13
lines changed

1 file changed

+5
-13
lines changed

cassandra/policies.py

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,6 @@ def __init__(self, local_dc='', used_hosts_per_remote_dc=0):
245245
self.used_hosts_per_remote_dc = used_hosts_per_remote_dc
246246
self._dc_live_hosts = {}
247247
self._position = 0
248-
self._endpoints = []
249248
LoadBalancingPolicy.__init__(self)
250249

251250
def _dc(self, host):
@@ -255,11 +254,6 @@ def populate(self, cluster, hosts):
255254
for dc, dc_hosts in groupby(hosts, lambda h: self._dc(h)):
256255
self._dc_live_hosts[dc] = tuple({*dc_hosts, *self._dc_live_hosts.get(dc, [])})
257256

258-
if not self.local_dc:
259-
self._endpoints = [
260-
endpoint
261-
for endpoint in cluster.endpoints_resolved]
262-
263257
self._position = randint(0, len(hosts) - 1) if hosts else 0
264258

265259
def distance(self, host):
@@ -301,13 +295,11 @@ def on_up(self, host):
301295
# not worrying about threads because this will happen during
302296
# control connection startup/refresh
303297
if not self.local_dc and host.datacenter:
304-
if host.endpoint in self._endpoints:
305-
self.local_dc = host.datacenter
306-
log.info("Using datacenter '%s' for DCAwareRoundRobinPolicy (via host '%s'); "
307-
"if incorrect, please specify a local_dc to the constructor, "
308-
"or limit contact points to local cluster nodes" %
309-
(self.local_dc, host.endpoint))
310-
del self._endpoints
298+
self.local_dc = host.datacenter
299+
log.info("Using datacenter '%s' for DCAwareRoundRobinPolicy (via host '%s'); "
300+
"if incorrect, please specify a local_dc to the constructor, "
301+
"or limit contact points to local cluster nodes" %
302+
(self.local_dc, host.endpoint))
311303

312304
dc = self._dc(host)
313305
with self._hosts_lock:

0 commit comments

Comments
 (0)