kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 489fb8c56d5a8618444414cfe07e6631a7c46931d73aa6fd954ed38aa92c6356 |
|---|---|
| Author | Olivier Michallat <olim7t@users.noreply.github.com> · 2016-02-26 19:37 +01:00 |
| Committer | olim7t <omichallat+github@gmail.com> · 2016-03-31 17:15 +02:00 |
| Parents | 6d5deb0e2ba0 |
1 file changed
modified manual/address_resolution/README.md +76 −24
| @@ -1,19 +1,61 @@ | ||
| 1 | 1 | ## Address resolution |
| 2 | 2 | |
| 3 | -The driver auto-detects new Cassandra nodes added to the cluster through server | |
| 4 | -side push notifications and through checking the system tables. | |
| 3 | +Each node in the Cassandra cluster is uniquely identified by an IP address that the driver will use to establish | |
| 4 | +connections. | |
| 5 | 5 | |
| 6 | -For each node, the address the driver will receive will correspond to the address set as | |
| 7 | -`rpc_address` in the node's `cassandra.yaml` file. In most cases, this is the correct value. | |
| 8 | -However, sometimes the addresses received through this mechanism will either not be | |
| 9 | -reachable directly by the driver, or should not be the preferred address to use | |
| 10 | -(for instance, it might be a private IP, but some clients may have to use a public IP, or | |
| 11 | -go through a router). | |
| 6 | +* for contact points, these are provided as part of configuring the `Cluster` object; | |
| 7 | +* for other nodes, addresses will be discovered dynamically, either by inspecting `system.peers` on already connected | |
| 8 | + nodes, or via push notifications received from the [control host](../control_connection) when new nodes are discovered | |
| 9 | + by gossip. | |
| 12 | 10 | |
| 13 | -### The [AddressTranslator][at] interface | |
| 14 | 11 | |
| 15 | -This interface allows you to deal with such cases, by transforming the address sent by a | |
| 16 | -Cassandra node to another address to be used by the driver for connection. | |
| 12 | +### Cassandra-side configuration | |
| 13 | + | |
| 14 | +The address that each Cassandra node shares with clients is the **broadcast RPC address**; it is controlled by various | |
| 15 | +properties in [cassandra.yaml]: | |
| 16 | + | |
| 17 | +* [rpc_address] or [rpc_interface] is the address that the Cassandra process *binds to*. You must set one or the other, | |
| 18 | + not both (for more details, see the inline comments in the default `cassandra.yaml` that came with your installation); | |
| 19 | +* [broadcast_rpc_address] \(introduced in Cassandra 2.1) is the address to share with clients, if it is different than | |
| 20 | + the previous one (the reason for having a separate property is if the bind address is not public to clients, because | |
| 21 | + there is a router in between). | |
| 22 | + | |
| 23 | +If `broadcast_rpc_address` is not set, it defaults to `rpc_address`/`rpc_interface`. If `rpc_address`/`rpc_interface` | |
| 24 | +is 0.0.0.0 (all interfaces), then `broadcast_rpc_address` *must* be set. | |
| 25 | + | |
| 26 | +If you're not sure which address a Cassandra node is broadcasting, launch cqlsh locally on the node, execute the | |
| 27 | +following query and take node of the result: | |
| 28 | + | |
| 29 | +``` | |
| 30 | +cqlsh> select broadcast_address from system.local; | |
| 31 | + | |
| 32 | + broadcast_address | |
| 33 | +------------------- | |
| 34 | + 172.1.2.3 | |
| 35 | +``` | |
| 36 | + | |
| 37 | +Then connect to *another* node in the cluster and run the following query, injecting the previous result: | |
| 38 | + | |
| 39 | +``` | |
| 40 | +cqlsh> select rpc_address from system.peers where peer = '172.1.2.3'; | |
| 41 | + | |
| 42 | + rpc_address | |
| 43 | +------------- | |
| 44 | + 1.2.3.4 | |
| 45 | +``` | |
| 46 | + | |
| 47 | +That last result is the broadcast RPC address. Ensure that it is accessible from the client machine where the driver | |
| 48 | +will run. | |
| 49 | + | |
| 50 | + | |
| 51 | +### Driver-side address translation | |
| 52 | + | |
| 53 | +Sometimes it's not possible for Cassandra nodes to broadcast addresses that will work for each and every client; for | |
| 54 | +instance, they might broadcast private IPs because most clients are in the same network, but a particular client could | |
| 55 | +be on another network and go through a router. | |
| 56 | + | |
| 57 | +For such cases, you can register a driver-side component that will perform additional address translation. Write a class | |
| 58 | +that implements [AddressTranslator] and register an instance with your `Cluster`: | |
| 17 | 59 | |
| 18 | 60 | ```java |
| 19 | 61 | public class MyAddressTranslator implements AddressTranslator { |
| @@ -31,19 +73,15 @@ | ||
| 31 | 73 | Note: the contact points provided while creating the `Cluster` are not translated, only |
| 32 | 74 | addresses retrieved from or sent by Cassandra nodes are. |
| 33 | 75 | |
| 34 | -[at]: http://docs.datastax.com/en/drivers/java/3.0/com/datastax/driver/core/policies/AddressTranslator.html | |
| 35 | - | |
| 36 | 76 | ### EC2 multi-region |
| 37 | 77 | |
| 38 | -[EC2MultiRegionAddressTranslator][ec2] is provided out of the box. It | |
| 39 | -helps optimize network costs when your infrastructure (both Cassandra | |
| 40 | -nodes *and* clients) is distributed across multiple Amazon EC2 regions: | |
| 78 | +If you deploy both Cassandra and client applications on Amazon EC2, and your cluster spans multiple regions, you'll have | |
| 79 | +to configure your Cassandra nodes to broadcast public RPC addresses. | |
| 41 | 80 | |
| 42 | -* a client communicating with a Cassandra node *in the same EC2 region* should use the node's | |
| 43 | - private IP (which is less expensive); | |
| 44 | -* a client communicating with a node in a different region should use the public IP. | |
| 81 | +However, this is not always the most cost-effective: if a client and a node are in the same region, it would be cheaper | |
| 82 | +to connect over the private IP. Ideally, you'd want to pick the best address in each case. | |
| 45 | 83 | |
| 46 | -To use this implementation, provide an instance when initializing the `Cluster`: | |
| 84 | +The driver provides an address translator that does just that: [EC2MultiRegionAddressTranslator]. | |
| 47 | 85 | |
| 48 | 86 | ```java |
| 49 | 87 | Cluster cluster = Cluster.builder() |
| @@ -52,8 +90,22 @@ | ||
| 52 | 90 | .build(); |
| 53 | 91 | ``` |
| 54 | 92 | |
| 55 | -This class performs a reverse DNS lookup of the origin address, to find the domain name of the | |
| 56 | -target instance. Then it performs a forward DNS lookup of the domain name; the EC2 DNS does the | |
| 57 | -private/public switch automatically based on location. | |
| 93 | +With this configuration, you keep broadcasting public RPC addresses. But each time the driver connects to a new | |
| 94 | +Cassandra node: | |
| 95 | + | |
| 96 | +* if the node is *in the same EC2 region*, the public IP will be translated to the intra-region private IP; | |
| 97 | +* otherwise, it will not be translated. | |
| 98 | + | |
| 99 | +(To achieve this, `EC2MultiRegionAddressTranslator` performs a reverse DNS lookup of the origin address, to find the | |
| 100 | +domain name of the target instance. Then it performs a forward DNS lookup of the domain name; the EC2 DNS does the | |
| 101 | +private/public switch automatically based on location). | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | +[AddressTranslator]: http://docs.datastax.com/en/drivers/java/3.0/com/datastax/driver/core/policies/AddressTranslator.html | |
| 106 | +[EC2MultiRegionAddressTranslator]: http://docs.datastax.com/en/drivers/java/3.0/com/datastax/driver/core/policies/EC2MultiRegionAddressTranslator.html | |
| 58 | 107 | |
| 59 | -[ec2]: http://docs.datastax.com/en/drivers/java/3.0/com/datastax/driver/core/policies/EC2MultiRegionAddressTranslator.html | |
| 108 | +[cassandra.yaml]: https://docs.datastax.com/en/cassandra/3.x/cassandra/configuration/configCassandra_yaml.html | |
| 109 | +[rpc_address]: https://docs.datastax.com/en/cassandra/3.x/cassandra/configuration/configCassandra_yaml.html?scroll=configCassandra_yaml__rpc_address | |
| 110 | +[rpc_interface]: https://docs.datastax.com/en/cassandra/3.x/cassandra/configuration/configCassandra_yaml.html?scroll=configCassandra_yaml__rpc_interface | |
| 111 | +[broadcast_rpc_address]: https://docs.datastax.com/en/cassandra/3.x/cassandra/configuration/configCassandra_yaml.html?scroll=configCassandra_yaml__broadcast_rpc_address |