File tree Expand file tree Collapse file tree 2 files changed +32
-0
lines changed
MongoDB.Driver/Communication Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -530,6 +530,29 @@ internal void SetState(MongoServerState state)
530
530
OnStateChanged ( ) ;
531
531
}
532
532
533
+ /// <summary>
534
+ /// Unset the primary flag on this instance but retain all other information
535
+ /// </summary>
536
+ internal void UnsetPrimary ( )
537
+ {
538
+ lock ( _serverInstanceLock )
539
+ {
540
+ _serverInfo . IsPrimary = false ;
541
+ }
542
+ }
543
+
544
+ /// <summary>
545
+ /// Unset the primary flag on this instance but retain all other information
546
+ /// </summary>
547
+ internal void UnsetPrimarySecondary ( )
548
+ {
549
+ lock ( _serverInstanceLock )
550
+ {
551
+ _serverInfo . IsPrimary = false ;
552
+ _serverInfo . IsSecondary = false ;
553
+ }
554
+ }
555
+
533
556
// private methods
534
557
private void LookupServerInformation ( MongoConnection connection )
535
558
{
@@ -659,6 +682,7 @@ private void Ping(MongoConnection connection)
659
682
catch
660
683
{
661
684
_pingTimeAggregator . Clear ( ) ;
685
+ UnsetPrimarySecondary ( ) ;
662
686
SetState ( MongoServerState . Disconnected ) ;
663
687
throw ;
664
688
}
Original file line number Diff line number Diff line change @@ -254,6 +254,14 @@ private void ProcessConnectedPrimaryStateChange(MongoServerInstance instance)
254
254
// remove instances the primary doesn't know about and add instances we don't know about
255
255
MakeInstancesMatchAddresses ( members ) ;
256
256
}
257
+ var instancesMarkedPrimary = Instances . Where ( x => x . IsPrimary ) ;
258
+ foreach ( var otherInstance in instancesMarkedPrimary )
259
+ {
260
+ if ( ! otherInstance . Address . Equals ( instance . Address ) )
261
+ {
262
+ otherInstance . UnsetPrimary ( ) ;
263
+ }
264
+ }
257
265
}
258
266
259
267
private void ProcessConnectedSecondaryStateChange ( MongoServerInstance instance )
You can’t perform that action at this time.
0 commit comments