Search code examples
c#cassandradatastaxdistributed-database

Can cassandra nodes be highly portable?


The Environment:

Nodes: 5
Replication: 5
Consistency: 1

The code:

using System;
using Cassandra;

    namespace CassandraSelectTest
    {
        class Program
        {
            static void Main(string[] args)
            {
                var cluster = Cluster.Builder()
                .AddContactPoints("192.168.0.18","192.168.0.21","192.168.0.22","192.168.0.23","192.168.0.24")
                .WithPort(9042)
                .Build();

                var session = cluster.Connect("test_keyspace");

                var results = session.Execute("SELECT * FROM test_table");

                foreach(var result in results)
                {
                    Console.WriteLine(result.GetValue<string>("col1"));
                }

                Console.WriteLine($"Finished");
                Console.ReadKey();
            }
        }
    }

The problem:

Some of the nodes ideally need to be highly portable, which results in the IP address of the node changing when it is in a different location, and then changing back to its normal IP address when back to its original location. This happens a few times a week.


The question:

Is it possible to configure a single node to have multiple IP addresses, or dynamic addresses which change automatically?


Solution

  • I think that in that scenario the driver will receive a protocol event which will make the driver refresh the cluster's topology. As long as the node's IP is up to date in system.peers table, i.e., you update broadcast_rpc_address / rpc_address / listen_address on the node's cassandra.yml the driver should be able to notice that the old IP is no longer in that table (which will remove the old host) and that there's a new IP (which will add a new host).

    If the control connection is not able to reconnect to any of the IPs on the local metadata cache (e.g. if all the nodes go down and change their IP addresses at the same time) then the driver will not be able to reconnect. There's this open ticket which will resolve this issue as long as the user provides hostnames as the contact points (and DNS resolution returns the updated IPs).