Automatic retry connection with couchbase servers before query or mutation?

If for example, during starup of my ASP.NET Core application, out of 3 couchbase servers only 1 is accessible. Throughout the lifetime of the application that server will only be talking to that 1 couchbase server. How do I ensure that before every query or mutation my application should try to re-connect to other available servers?

@ibrahim1

The SDK is actually doing this for you automatically behind the scenes. For mutations, a connection is always required to the specific data node where that document lives, so it will fail if a connection cannot be established or succeed if it can. For a query, only one HTTP connection to a single query node is required. Query nodes are regularly monitored to see when they become available again and are added back to the rotation once they appear online.

I am actually talking about 2 separate couchbase servers running on 2 different machines. In these couchbase servers they have 4 nodes each.

@ibrahim1

That shouldn’t matter. The SDK works by connecting to one node at random from the list, and then that first node provides information back to the SDK about the entire cluster. This information includes a list of the IPs or domain names of all the nodes, what services they are running, etc. From that point forward, this information is used to connect to the cluster by the SDK (your original connection string is ignored). It is required that your client app have network level access to all of the nodes in the cluster.

@btburnett3 So if I have two separate clusters with 2 nodes each for example: Server A: A1, A2 and Server B: B1, B2
And following is how I am connecting from my application and its singleton by the way:

var cluster = new Cluster(new ClientConfiguration
{
    Servers = ConnectionConfiguration.Servers.Select(x => new Uri(x)).ToList(),
    PoolConfiguration = new PoolConfiguration
    {
        MaxSize = ConnectionConfiguration.PoolMaxSize,
        SendTimeout = ConnectionConfiguration.SendTimeout,
        ConnectTimeout = ConnectionConfiguration.ConnectTimeout
    },
    ConnectionPoolCreator = ConnectionPoolFactory.GetFactory<CouchbaseConnectionPool<MultiplexingConnection>>()
});

Should ClientConfiguration.Servers contain addresses for A1, A2, B1, B2
or I should initialize 2 Cluster object; one with A1, A2 and another with B1,B2?

@ibrahim1

If you’re trying to connect to two independent Couchbase clusters, then yes, those should be separate Cluster objects, each with two servers in the Servers list.

Please note that some older versions of the Couchbase SDK had issues with connecting to more than one cluster, so I’d make sure you’re up to date.