Skip to content

Commit 5a35146

Browse files
committed
Shouldn't use global cursor #1810
Always return the lowest alive node in the sequence they were provided
1 parent 17968b5 commit 5a35146

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

src/Elasticsearch.Net/ConnectionPool/StickyConnectionPool.cs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4-
using System.Text;
54
using System.Threading;
6-
using System.Threading.Tasks;
75

8-
namespace Elasticsearch.Net.ConnectionPool
6+
namespace Elasticsearch.Net
97
{
108
public class StickyConnectionPool : IConnectionPool
119
{
@@ -50,8 +48,6 @@ public StickyConnectionPool(IEnumerable<Node> nodes, IDateTimeProvider dateTimeP
5048
this.LastUpdate = this.DateTimeProvider.Now();
5149
}
5250

53-
protected int GlobalCursor = -1;
54-
5551
public IEnumerable<Node> CreateView(Action<AuditEvent, Node> audit = null)
5652
{
5753
var now = this.DateTimeProvider.Now();
@@ -60,20 +56,18 @@ public IEnumerable<Node> CreateView(Action<AuditEvent, Node> audit = null)
6056
var count = nodes.Count;
6157
Node node;
6258

63-
var globalCursor = Interlocked.Increment(ref GlobalCursor);
64-
6559
if (count == 0)
6660
{
6761
//could not find a suitable node retrying on first node off globalCursor
6862
audit?.Invoke(AuditEvent.AllNodesDead, null);
69-
node = this.InternalNodes[globalCursor % this.InternalNodes.Count];
63+
node = this.InternalNodes[0];
7064
node.IsResurrected = true;
7165
audit?.Invoke(AuditEvent.Resurrection, node);
7266
yield return node;
7367
yield break;
7468
}
7569

76-
var localCursor = globalCursor % count;
70+
var localCursor = 0;
7771

7872
for (var attempts = 0; attempts < count; attempts++)
7973
{

0 commit comments

Comments
 (0)