Skip to content

Commit 7589291

Browse files
author
rstam
committed
Fixed CSHARP-412. When looking for a replica set member to send slaveOk queries to it is sufficient to look for IsSecondary members. It is not necessary to check IsPassive because IsSecondary will also be true for passive members. And most importantly, IsSecondary will temporarily change to false if a passive member is in recovering mode (and IsPassive remains true), and we don't want to send slaveOk queries to passive members that are in recovering mode.
1 parent 4647ed9 commit 7589291

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

Driver/Core/ConnectWaitFor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public enum ConnectWaitFor
3434
/// </summary>
3535
Primary,
3636
/// <summary>
37-
/// Wait for any slaveOk member of the replica set to be connected (includes primary, secondaries and passives).
37+
/// Wait for any slaveOk member of the replica set to be connected (primary or any secondary).
3838
/// </summary>
3939
AnySlaveOk
4040
}

Driver/Core/MongoServer.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,8 @@ public virtual void Connect(TimeSpan timeout, ConnectWaitFor waitFor)
599599
}
600600
break;
601601
case ConnectWaitFor.AnySlaveOk:
602-
if (_instances.Any(i => i.State == MongoServerState.Connected && (i.IsPrimary || i.IsSecondary || i.IsPassive)))
602+
// don't check for IsPassive because IsSecondary is also true for passives (and only true if not in recovery mode)
603+
if (_instances.Any(i => i.State == MongoServerState.Connected && (i.IsPrimary || i.IsSecondary)))
603604
{
604605
return;
605606
}
@@ -1162,7 +1163,8 @@ internal MongoServerInstance ChooseServerInstance(bool slaveOk)
11621163
_loadBalancingInstanceIndex = 0;
11631164
}
11641165
var instance = _instances[_loadBalancingInstanceIndex];
1165-
if (instance.State == MongoServerState.Connected && (instance.IsSecondary || instance.IsPassive))
1166+
// don't check for IsPassive because IsSecondary is also true for passives (and only true if not in recovery mode)
1167+
if (instance.State == MongoServerState.Connected && instance.IsSecondary)
11661168
{
11671169
return instance;
11681170
}

Driver/Internal/ReplicaSetConnector.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ internal void Connect(TimeSpan timeout, ConnectWaitFor waitFor)
7979
}
8080
break;
8181
case ConnectWaitFor.AnySlaveOk:
82-
if (_server.Instances.Any(i => (i.IsPrimary || i.IsSecondary || i.IsPassive) && i.State == MongoServerState.Connected))
82+
// don't check for IsPassive because IsSecondary is also true for passives (and only true if not in recovery mode)
83+
if (_server.Instances.Any(i => (i.IsPrimary || i.IsSecondary) && i.State == MongoServerState.Connected))
8384
{
8485
exitEarly = true;
8586
}

0 commit comments

Comments
 (0)