Skip to content

Commit ced919a

Browse files
committed
DNS resolve contact points
removes duplicate hosts, also expands A records PYTHON-103 PYTHON-415
1 parent 2eec974 commit ced919a

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

cassandra/cluster.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,10 @@ def __init__(self,
532532
self.contact_points = contact_points
533533

534534
self.port = port
535+
536+
self.contact_points_resolved = [endpoint[4][0] for a in self.contact_points
537+
for endpoint in socket.getaddrinfo(a, self.port, socket.AF_UNSPEC, socket.SOCK_STREAM)]
538+
535539
self.compression = compression
536540
self.protocol_version = protocol_version
537541
self.auth_provider = auth_provider
@@ -830,7 +834,7 @@ def connect(self, keyspace=None):
830834
self.contact_points, self.protocol_version)
831835
self.connection_class.initialize_reactor()
832836
atexit.register(partial(_shutdown_cluster, self))
833-
for address in self.contact_points:
837+
for address in self.contact_points_resolved:
834838
host, new = self.add_host(address, signal=False)
835839
if new:
836840
host.set_up()
@@ -2320,7 +2324,7 @@ def _refresh_node_list_and_token_map(self, connection, preloaded_results=None,
23202324
if old_host.address != connection.host and old_host.address not in found_hosts:
23212325
should_rebuild_token_map = True
23222326
if old_host.address not in self._cluster.contact_points:
2323-
log.debug("[control connection] Found host that has been removed: %r", old_host)
2327+
log.debug("[control connection] Removing host not found in peers metadata: %r", old_host)
23242328
self._cluster.remove_host(old_host)
23252329

23262330
log.debug("[control connection] Finished fetching ring info")

cassandra/policies.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ def populate(self, cluster, hosts):
235235
self._dc_live_hosts[dc] = tuple(set(dc_hosts))
236236

237237
if not self.local_dc:
238-
self._contact_points = cluster.contact_points
238+
self._contact_points = cluster.contact_points_resolved
239239

240240
self._position = randint(0, len(hosts) - 1) if hosts else 0
241241

0 commit comments

Comments
 (0)