-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Create a separate nuget package to handle cluster failovers #365
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I made a very basic and simple cluster-friendly client that supports failover and random node selection; could be very much improved but its a start. /// <summary>
/// Fetch an instance of the ElasticClient to use
/// </summary>
public ElasticClient CreateClient()
{
// Load Nodes
var nodes = _configurationService.ElasticSearchNodes.Split(',').ToList();
if (nodes.Count == 0)
throw new ArgumentException("No ElasticSearchNodes were specified in configuration");
// Create a client to an online server
var random = new Random();
while (true) {
// If there are no nodes to use now, we're out of options
if (nodes.Count == 0)
throw new ArgumentException("There are no available ElasticSearch nodes to use");
// Pick random node
var nodeToUse = nodes[random.Next(0, nodes.Count)];
// Create Client
var connectUri = string.Format("http://{0}", nodeToUse);
var elasticSettings = new ConnectionSettings(new Uri(connectUri))
.SetMaximumAsyncConnections(50);
var client = new ElasticClient(elasticSettings);
// Verify Connectivity
if (!client.RootNodeInfo().IsValid) {
// Client is not valid, remove from node list and retry
nodes.Remove(nodeToUse);
continue;
}
// Otherwise this client is valid to be used
return client;
}
} |
Hi Plasma, Thanks for sharing your solution! I'm starting my new job at elasticsearch next month and this will be a high high priority and the cluster failover will be inline with the elasticsearch official clients. |
Is there a desire for this feature to be backwards compatible or can it be a breaking change. I ask because I am working on this at my company and would prefer to implement it in a way that can be pulled back into the main project. Our goal would be to have a single client that is created by the IoC container which would function with failover without any additional input. I can do it as a minimally breaking change by modifying the ConnectionSettings class by making it accept a list of URI for failover purposes. Then the current client can manage its failover during its lifetime. The other option would be to make a separate FailoverConnectionSettings object to avoid any breaking changes. |
No you may break as you please, the next release is going to be NEST 0.90 but should be treated as a new major version. I always saw the FailOver as a factory around IElasticClient, the elasticsearch official guideline on clients however states that it should be a property of the Client itself i.e: http://www.elasticsearch.org/guide/en/elasticsearch/client/javascript-api/current/configuration.html So indeed more like you suggested with an additional constructor taking more Uri's and a sniffing mode fluent call on the IElasticClient is stateless by design so whether you register as a singleton or as a new instantiation should not matter. I think that is my only requirement. Do have a look at the official clients, I'm starting on the 1st of februari at elasticsearch but until then I'm really swamped handing over my existing projects. I do however really appreciate any effort in this area so please don't hesitate to email me questions/feedback/updates (gh handle and then think of a popular email service). |
This is now implemented through this PR #528 |
Ideally this would be be a Factory like class that you can spawn clients of that checks whether nodes are up based on timers and by inspecting the result of calls the spawned clients make.
TO BE SPEC'd.
Thoughts, ideas, code all very much appreciated 👍
The text was updated successfully, but these errors were encountered: