Reconnection

If the driver loses a connection to a node, it tries to re-establish it according to a configurable policy. This is used in two places:

  • connection pools: for each node, a session has a fixed-size pool of connections to execute user requests. If a node is detected as down, a reconnection is started.

  • control connection: a session uses a single connection to an arbitrary node for administrative requests. If that connection goes down, a reconnection gets started; each attempt iterates through all active nodes until one of them accepts a connection. This goes on until we have a control node again.

ReconnectionPolicy controls the interval between each attempt. The policy to use may be provided using Cluster.Builder.withReconnectionPolicy. For example, the following configures an ExponentialReconnectionPolicy with a base delay of 1 second, and a max delay of 10 minutes (this is the default behavior).

Cluster.builder()
  .withReconnectionPolicy(new ExponentialReconnectionPolicy(1000, 10 * 60 * 1000))
  .build();

ConstantReconnectionPolicy uses the same delay every time, regardless of the previous number of attempts.

You can also write your own policy; it must implement ReconnectionPolicy.

For best results, use reasonable values: very low values (for example a constant delay of 10 milliseconds) will quickly saturate your system.