1- /* Copyright 2013-2015 MongoDB Inc.
1+ /* Copyright 2013-2016 MongoDB Inc.
22*
33* Licensed under the Apache License, Version 2.0 (the "License");
44* you may not use this file except in compliance with the License.
@@ -36,7 +36,7 @@ internal sealed class MultiServerCluster : Cluster
3636 {
3737 // fields
3838 private readonly CancellationTokenSource _monitorServersCancellationTokenSource ;
39- private volatile PrimaryVersion _maxPrimaryVersion ;
39+ private volatile ElectionInfo _maxElectionInfo ;
4040 private volatile string _replicaSetName ;
4141 private readonly AsyncQueue < ServerDescriptionChangedEventArgs > _serverDescriptionChangedQueue ;
4242 private readonly List < IClusterableServer > _servers ;
@@ -324,12 +324,14 @@ private ClusterDescription ProcessReplicaSetChange(ClusterDescription clusterDes
324324 if ( args . NewServerDescription . ReplicaSetConfig . Version != null )
325325 {
326326 bool isCurrentPrimaryStale = true ;
327- if ( _maxPrimaryVersion != null )
327+ if ( _maxElectionInfo != null )
328328 {
329- isCurrentPrimaryStale = _maxPrimaryVersion . IsStale ( args . NewServerDescription . ReplicaSetConfig . Version . Value , args . NewServerDescription . ElectionId ) ;
330- if ( ! isCurrentPrimaryStale && args . NewServerDescription . ElectionId != null )
329+ isCurrentPrimaryStale = _maxElectionInfo . IsStale ( args . NewServerDescription . ReplicaSetConfig . Version . Value , args . NewServerDescription . ElectionId ) ;
330+ var isReportedPrimaryStale = ! isCurrentPrimaryStale ;
331+
332+ if ( isReportedPrimaryStale && args . NewServerDescription . ElectionId != null )
331333 {
332- // we only invalidate the "newly" reported primary if electionId was used.
334+ // we only invalidate the "newly" reported stale primary if electionId was used.
333335 lock ( _serversLock )
334336 {
335337 var server = _servers . SingleOrDefault ( x => EndPointHelper . Equals ( args . NewServerDescription . EndPoint , x . EndPoint ) ) ;
@@ -342,7 +344,7 @@ private ClusterDescription ProcessReplicaSetChange(ClusterDescription clusterDes
342344
343345 if ( isCurrentPrimaryStale )
344346 {
345- _maxPrimaryVersion = new PrimaryVersion (
347+ _maxElectionInfo = new ElectionInfo (
346348 args . NewServerDescription . ReplicaSetConfig . Version . Value ,
347349 args . NewServerDescription . ElectionId ) ;
348350 }
@@ -505,12 +507,12 @@ private static class State
505507 public const int Disposed = 2 ;
506508 }
507509
508- private class PrimaryVersion
510+ private class ElectionInfo
509511 {
510512 private readonly int _setVersion ;
511513 private readonly ElectionId _electionId ;
512514
513- public PrimaryVersion ( int setVersion , ElectionId electionId )
515+ public ElectionInfo ( int setVersion , ElectionId electionId )
514516 {
515517 _setVersion = setVersion ;
516518 _electionId = electionId ;
0 commit comments