Elffuss BraidHub

kikocis/java-driver public

JAVA-1083: Document server-side RPC address configuration.
Changesetfd64e7876dffca7d617607e1e9b31f0293d23fd2f6b6db755025e8eb69e264f1
Authorolim7t <omichallat+github@gmail.com> · 2016-02-23 10:08 +01:00
Committerolim7t <omichallat+github@gmail.com> · 2016-02-26 19:36 +01:00
Parents8ae5bc7181fe

Browse the files at this changeset

1 file changed

modified manual/address_resolution/README.md +79 −27
@@ -1,19 +1,61 @@
11 ## Address resolution
22
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.
55
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.
1210
13-### The [AddressTranslater][at] interface
1411
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 [AddressTranslater] and register an instance with your `Cluster`:
1759
1860 ```java
1961 public class MyAddressTranslater implements AddressTranslater {
@@ -32,26 +74,21 @@
3274
3375 * the contact points provided while creating the `Cluster` are not translated, only addresses
3476 retrieved from or sent by Cassandra nodes are;
35-* you might want to implement [CloseableAddressTranslater][cat] if your
77+* you might want to implement [CloseableAddressTranslater] if your
3678 implementation has state that should be cleaned up when the `Cluster`
3779 shuts down. This is provided as a separate interface for historical
38- reasons, the `close()` method will be merged in `AddressTranslater` in a
39- future release.
80+ reasons, the `close()` method was merged in `AddressTranslater` in 3.0.
4081
41-[at]: http://docs.datastax.com/en/drivers/java/2.1/com/datastax/driver/core/policies/AddressTranslater.html
42-[cat]: http://docs.datastax.com/en/drivers/java/2.1/com/datastax/driver/core/policies/CloseableAddressTranslater.html
4382
4483 ### EC2 multi-region
4584
46-[EC2MultiRegionAddressTranslater][ec2] is provided out of the box. It
47-helps optimize network costs when your infrastructure (both Cassandra
48-nodes *and* clients) is distributed across multiple Amazon EC2 regions:
85+If you deploy both Cassandra and client applications on Amazon EC2, and your cluster spans multiple regions, you'll have
86+to configure your Cassandra nodes to broadcast public RPC addresses.
4987
50-* a client communicating with a Cassandra node *in the same EC2 region* should use the node's
51- private IP (which is less expensive);
52-* a client communicating with a node in a different region should use the public IP.
88+However, this is not always the most cost-effective: if a client and a node are in the same region, it would be cheaper
89+to connect over the private IP. Ideally, you'd want to pick the best address in each case.
5390
54-To use this implementation, provide an instance when initializing the `Cluster`:
91+The driver provides an address translator that does just that: [EC2MultiRegionAddressTranslater].
5592
5693 ```java
5794 Cluster cluster = Cluster.builder()
@@ -60,8 +97,23 @@
6097 .build();
6198 ```
6299
63-This class performs a reverse DNS lookup of the origin address, to find the domain name of the
64-target instance. Then it performs a forward DNS lookup of the domain name; the EC2 DNS does the
65-private/public switch automatically based on location.
100+With this configuration, you keep broadcasting public RPC addresses. But each time the driver connects to a new
101+Cassandra node:
102+
103+* if the node is *in the same EC2 region*, the public IP will be translated to the intra-region private IP;
104+* otherwise, it will not be translated.
105+
106+(To achieve this, `EC2MultiRegionAddressTranslater` performs a reverse DNS lookup of the origin address, to find the
107+domain name of the target instance. Then it performs a forward DNS lookup of the domain name; the EC2 DNS does the
108+private/public switch automatically based on location).
109+
110+
111+
112+[AddressTranslater]: http://docs.datastax.com/en/drivers/java/2.1/com/datastax/driver/core/policies/AddressTranslater.html
113+[CloseableAddressTranslater]: http://docs.datastax.com/en/drivers/java/2.1/com/datastax/driver/core/policies/CloseableAddressTranslater.html
114+[EC2MultiRegionAddressTranslater]: http://docs.datastax.com/en/drivers/java/2.1/com/datastax/driver/core/policies/EC2MultiRegionAddressTranslater.html
66115
67-[ec2]: http://docs.datastax.com/en/drivers/java/2.1/com/datastax/driver/core/policies/EC2MultiRegionAddressTranslater.html
116+[cassandra.yaml]: https://docs.datastax.com/en/cassandra/2.1/cassandra/configuration/configCassandra_yaml_r.html
117+[rpc_address]: https://docs.datastax.com/en/cassandra/2.1/cassandra/configuration/configCassandra_yaml_r.html?scroll=reference_ds_qfg_n1r_1k__rpc_address
118+[rpc_interface]: https://docs.datastax.com/en/cassandra/2.1/cassandra/configuration/configCassandra_yaml_r.html?scroll=reference_ds_qfg_n1r_1k__rpc_interface
119+[broadcast_rpc_address]: https://docs.datastax.com/en/cassandra/2.1/cassandra/configuration/configCassandra_yaml_r.html#reference_ds_qfg_n1r_1k__broadcast_rpc_address