2
votes

I am new in Elastic search. I want to know how the cluster failover works in ES using NEST. I went through available links http://nest.azurewebsites.net/elasticsearch-net/cluster-failover.html and http://nest.azurewebsites.net/elasticsearch-net/connecting.html. But it is not much clear for me.

Suppose i have two nodes. Node1(10.20.2.1:9203) and node2(10.20.2.2:9204). Both nodes are connected to single cluster 'TestCluster'. My requirement is that, if any of the node is down, i want to get the data from live node.

My config file for Node1(10.20.2.1:9203) is as follows

cluster.name: TestCluster
node.name: "Node1"
node.master: true
node.data: true
network.host: 10.20.2.1
http.port: 9203

My config file for Node2(10.20.2.2:9204) is as follows

cluster.name: TestCluster
node.name: "Node2"
node.master: false
node.data: true
network.host: 10.20.2.2
http.port: 9204

I am accessing the ES client as follows

private static ElasticClient ElasticClientNew
        {
            get
            {
                var node = new Uri("http://10.20.2.1:9203");
                var node1 = new Uri("http://10.20.2.2:9204");
                var connectionPool = new SniffingConnectionPool(new[] { node, node1 });
                var setting = new ConnectionSettings(connectionPool)
                                    .SniffOnConnectionFault(false)
                                    .SniffOnStartup(false)
                                    .SniffLifeSpan(TimeSpan.FromMinutes(1));
                return new ElasticClient(setting);
            }
        }

I am using this ES client for searching as follows

var result = ElasticClientNew.Search<Attendance>(s => s
                            .From(0)
                            .Size(5000)
                            .Index("attendance").Type("Worker"));

I am running the MVS application from node1, and elasticsearch service is stopped in this machine. But the ES service is running in node2. When i try to search, am getting error as follows

Failed after retrying 1 times: 'POST attendance/Worker/_search'. 
InnerException: PingException, InnerMessage: Pinging http://10.20.2.1:9203 caused an exception, InnerStackTrace:    at Elasticsearch.Net.Connection.Transport.Ping(ITransportRequestState requestState) in c:\Users\gmarz\code\elasticsearch-net\src\Elasticsearch.Net\Connection\Transport.cs:line 96
   at Elasticsearch.Net.Connection.Transport.DoRequest[T](TransportRequestState`1 requestState) in c:\Users\gmarz\code\elasticsearch-net\src\Elasticsearch.Net\Connection\Transport.cs:line 334

Please suggest how the cluster failover can be achieved in my application.

2
Since you are not using any sniffing and you know the entire topology for your cluster it makes more sense in this case to use the StaticConnectionPool over the SniffingConnectionPool. That aside this may be a bug, will investigate further trying with the exact same setup as you. - Martijn Laarman
If you can paste more information (InnerException, fiddler logs that be super helpful!) thanks :) - Martijn Laarman
Another thing i just noticed you configured node2 as node.master: false, which means that if you take node1 down, node2 will close as well because it sees no active masters anymore. - Martijn Laarman
Martijn Laarman: Do i need to make all nodes config files's node.master: false to 'true'? - Renjith Thomas
Martijn Laarman: When i changed node.master: false to true, it worked successfully. Thanks... - Renjith Thomas

2 Answers

1
votes

The problem is that only one of the nodes has

node.master: true

set so when that node goes down the other node is masterless and turns off as well.

0
votes

I have similar issue:

When I tried connecting using StaticConnection pool, I am getting following error:

An unhandled exception of type 'Elasticsearch.Net.Exceptions.MaxRetryException' occurred in Elasticsearch.Net.dll

Additional information: Failed after retrying 0 times: 'POST els_logentries/logentries/_search'.

AS I Run again, It works fine.

        var node1 = new Uri("http://192.168.115.102:9200");
        var node2 = new Uri("http://192.168.115.102:9200");

        var connectionPool = new StaticConnectionPool(new List<Uri>() { node1,node2});
        var settings = new ConnectionSettings(connectionPool, defaultIndex: "els_logentries");

        ElasticClient client = new ElasticClient(settings);

        var results = client.Search<Logentries>(s => s
            .Type("logentries")
             .Query(q=>q
            .Bool(bq=>bq
            .Must(
            mq=>mq.MatchAll()
                )    )));