Veera
Veera

Reputation: 1815

Cassandra Clustering Failure handling

How Cassandra behaves when the contact node is dead? I mean to say, Cassandra has the ring structure of "n" nodes, If client is going to access that first node but it is dead. The first node is specified in the java client. I could not understand the failure handling. Could any one help me?

Upvotes: 3

Views: 2962

Answers (2)

Peter Coulton
Peter Coulton

Reputation: 55829

If you only have one node, or only specify one node, and that node is down then the client won't be able to connect (obviously); but usually a client library, like Hector, will allow you to specify a group of nodes and maintain a connection pool, connecting to which ever node is available.

The Hector documentation goes in to a little more detail, but the simplest way to specify multiple nodes is by passing a comma-separated list of hosts in the CassandraHostConfigurator when creating a cluster:

String hosts = "node1.example.com:9160, node2.example.com:9160, node3.example.com:9160";
Cluster cluster = HFactory.getOrCreateCluster(CLUSTER_NAME, new CassandraHostConfigurator(hosts));

Upvotes: 2

Lyuben Todorov
Lyuben Todorov

Reputation: 14173

It depends on the client, different client do different things to deal with this, but with most drivers you can supply several contact points.

Astyanax uses token discovery to keep track of various nodes in the cluster. Full docs here.

The host supplier associates the connection pool with a dynamic host registry. The connection pool will frequently poll this supplier for the current list of hosts and update its internal host connection pools to account for new or removed hosts.

This is configured during when you are setting up your context:

AstyanaxContext<Keyspace> context = new AstyanaxContext.Builder()
    ...
    .withAstyanaxConfiguration(new AstyanaxConfigurationImpl()      
        .setDiscoveryType(NodeDiscoveryType.RING_DESCRIBE)
        .setConnectionPoolType(ConnectionPoolType.TOKEN_AWARE)
    )
...
context.start();

The DataStax java driver handles failure well as long as you've supplied multiple contact points. If you have 3 nodes with a SimpleStrategy for replication and replication factor of 3 (aka all data is present on all 3 nodes) than you can query as long as one of the 3 nodes is alive.

Cluster cluster = Cluster.builder()
                         .addContactPoint("127.0.0.1")
                         .addContactPoint("127.0.0.2")
                         .addContactPoint("127.0.0.3")
                         .build();
Session session = cluster.connect();

Upvotes: 0

Related Questions