Connection pooling / cluster failover support #528
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds support for builtin cluster failover support and connection pooling.
SingleNodeConnectionPool
This is still the default when you do not specify any connectionpool.
In this example we never explicitly passed an
IConnectionPoolto use so it will default to theSingleNodeConnectionPoolwhich will always report the single node we passed in as alive and well. This means that the defaults for existing code is unchangedStaticConnectionPool
This adds a static pool of nodes that will be round robin'ed over when performing elasticsearch calls. Whenever a node reports a known failure (timout, 503 etcetera) it will retry on the next node in the pool and mark the failing node as dead. This means that while the node has been marked dead it will automatically be skipped for the duration it has been marked dead. When all nodes are marked dead it will simply pick one at random. You can specify the maximum amount of retries which will default to the amount of nodes you pass in minus 1.
SniffingConnectionPool
Similar to the static connection pool this will round robin over the specified nodes but will use the nodes to initially sniff the rest of the cluster to build the list of known hosts. You can make it re-sniff whenever a connection fault occurs or sniff whenever the last sniff happened too long ago.
See the unit tests here:
https://github.com/Mpdreamz/NEST/tree/feature/connection-pooling/src/Elasticsearch.Net.Tests.Unit/Connection
In particular read this tests to know why builtin support for cluster failover in NEST is an absolute must:
https://github.com/Mpdreamz/NEST/blob/feature/connection-pooling/src/Elasticsearch.Net.Tests.Unit/Connection/ConcurrencyTests.cs#L94