Skip to content

Commit f2a80f1

Browse files
Only add host if endpoint is not already present
In d735957 there was a functionality added to reresolve hostnames when all hosts are unreachable. In such a scenario, the driver will try to save the situation by reresolving the contact points in case it helps. However, if there was no ip address change, this results in creation of new (duplicate) Hosts (same endpoint different host_id) which in turn starts new reconnection processes. Those duplicate reconnection processes can make the situation worse when the driver regains connectivity with the cluster. Different Hosts with the same endpoint are reconnecting in different moments and this cause host to be unreachable in unpredictable moments. This commit introduces checking if the resolved endpoint is already present in Cluster Metadata information. The new host is added only if this condition is not true. Fixes: #295 Refs: scylladb/scylladb#16709, scylladb/scylladb#17353
1 parent 8138dca commit f2a80f1

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

cassandra/cluster.py

+3
Original file line numberDiff line numberDiff line change
@@ -2169,6 +2169,9 @@ def add_host(self, endpoint, datacenter=None, rack=None, signal=True, refresh_no
21692169
the metadata.
21702170
Intended for internal use only.
21712171
"""
2172+
with self.metadata._hosts_lock:
2173+
if endpoint in self.metadata._host_id_by_endpoint:
2174+
return self.metadata._hosts[self.metadata._host_id_by_endpoint[endpoint]], False
21722175
host, new = self.metadata.add_or_return_host(Host(endpoint, self.conviction_policy_factory, datacenter, rack, host_id=host_id))
21732176
if new and signal:
21742177
log.info("New Cassandra host %r discovered", host)

0 commit comments

Comments
 (0)