Ruby driver uses plug-able address-resolution policy to map Apache Cassandra node’s ip address to another address value when necessary.
Default address resolution policy simply returns original address. This should be enough for most cluster setups, however, can present problems in environments like multi-region EC2, since it would force ruby-driver to use public IPs of cassandra instances even within the same datacenter.
Therefore, Ruby driver comes with an EC2 Multi-Region address resolution policy.
This address resolution policy relies on some properties of AWS DNS to work.
When activated, this strategy performs a forward-confirmed reverse DNS lookup of a given peer’s ip address. These addresses are public (e.g. 220.127.116.11). This lookup will resolve to a private ip when done within datacenter and to public ip from anywhere else. Finally, if DNS lookup fails, the policy will return original address.
Note: This policy uses blocking DNS lookups internally and may hang the reactor for the duration of the lookup. Fortunately, these address resolutions happen only during initial connect or host additions/recoveries.
Also note that the policy will resolve to the first successfully looked up IP address. It should present no problems on EC2, but is worth mentioning explicitly.
To enable EC2 Multi-Region address resolution policy, use the following:
cluster = Cassandra.cluster(address_resolution: :ec2_multi_region)