Resolve contact point hostnames to avoid duplicate hosts

Description

If hostnames are used for contact points, duplicate Hosts will be created for all contact points other than the one that the control connection connects to. The reason this happens is that Hosts are immediately created for contact points (using the hostname). Later, when the control connection queries system.peers, it sees IP addresses for those nodes, and creates new Host objects for them. This results in multiple connections being opened to the same host.

Environment

None

Pull Requests

None

Activity

Show:
Adam Holmberg
April 6, 2016, 8:33 PM

Same PR for 103 and 415

Anton M
October 26, 2015, 11:10 AM
Edited

Hello,

Those duplicate hosts have no valid "datacenter" attribute so this problem also affects DCAware load-balancing policy:

DNS A-records:
cas01.dc01.net 172.16.3.15
cas02.dc01.net 172.16.3.16
cas01.dc02.net 172.16.9.3

cluster = Cluster(['cas01.dc01.net', 'cas02.dc01.net', 'cas01.dc02.net'], auth_provider=auth, protocol_version=3, load_balancing_policy=DCAwareRoundRobinPolicy(local_dc='dc01'))

>>> for host in cluster.metadata.all_hosts():
... print 'Datacenter: %s; Host: %s; Rack: %s' % (host.datacenter, host.address, host.rack)
...
Datacenter: None; Host: cas01.dc01.net; Rack: None
Datacenter: None; Host: cas01.dc02.net; Rack: None
Datacenter: dc01; Host: 172.16.3.15; Rack: Rack1
Datacenter: dc02; Host: 172.16.9.3; Rack: Rack1
Datacenter: dc01; Host: cas02.dc01.net; Rack: Rack1

>>> for k, v in cluster.load_balancing_policy._dc_live_hosts.items():
... print "DC name: %s; Node address: %s" % (k, [node.address for node in v])
...
DC name: dc01; Node address: ['cas01.dc01.net', 'cas01.dc02.net', 'cas02.dc01.net', '172.16.3.15']
DC name: dc02; Node address: ['172.16.9.3']

Fixed

Assignee

Unassigned

Reporter

Tyler Hobbs

Fix versions