KingOfHypocrites
KingOfHypocrites

Reputation: 9537

Handling All Nodes Down in Cassandra when using DataStax C# Driver

I have a simple two node cluster setup in Azure and I'm using the DataStax C# driver to connect to it.

I am able to take a single node down without any issues. As long as I have one node running all is well. However if I take both nodes down and then bring a node back up the driver never catches on to this. It keeps saying all hosts were tried and could not be queried even though a node is available again.

I imagine this is a rare scenario for someone with 20 nodes, but having only two nodes and a limited budget at the moment, I have to plan for this possibility. I have a worker role in Azure that is always running and I need a way to reconnect (or refresh the connection) to get the C# driver to see a node is available again. I don't want to have to restart my service every time something like that happens.

I do not see any great way to know from the exception that I need to reconnect as it could be a temporary error and I don't see any obvious properties on the Cluster or Session object to know I need to reset the connection.

Upvotes: 3

Views: 465

Answers (1)

jorgebg
jorgebg

Reputation: 6600

The DataStax C# driver exposes a ReconnectionPolicy interface and delivers some builtin implementations to configure how the driver will try to reconnect when a node goes down.

For example, configure the Cluster try to reconnect to nodes considered as down after 500ms passed:

Cluster.Builder()
   .WithReconnectionPolicy(new ConstantReconnectionPolicy(500))
   .Build()

Upvotes: 3

Related Questions