1
- /* Copyright 2013-2015 MongoDB Inc.
1
+ /* Copyright 2013-2016 MongoDB Inc.
2
2
*
3
3
* Licensed under the Apache License, Version 2.0 (the "License");
4
4
* you may not use this file except in compliance with the License.
@@ -36,7 +36,7 @@ internal sealed class MultiServerCluster : Cluster
36
36
{
37
37
// fields
38
38
private readonly CancellationTokenSource _monitorServersCancellationTokenSource ;
39
- private volatile PrimaryVersion _maxPrimaryVersion ;
39
+ private volatile ElectionInfo _maxElectionInfo ;
40
40
private volatile string _replicaSetName ;
41
41
private readonly AsyncQueue < ServerDescriptionChangedEventArgs > _serverDescriptionChangedQueue ;
42
42
private readonly List < IClusterableServer > _servers ;
@@ -324,12 +324,14 @@ private ClusterDescription ProcessReplicaSetChange(ClusterDescription clusterDes
324
324
if ( args . NewServerDescription . ReplicaSetConfig . Version != null )
325
325
{
326
326
bool isCurrentPrimaryStale = true ;
327
- if ( _maxPrimaryVersion != null )
327
+ if ( _maxElectionInfo != null )
328
328
{
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 )
331
333
{
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.
333
335
lock ( _serversLock )
334
336
{
335
337
var server = _servers . SingleOrDefault ( x => EndPointHelper . Equals ( args . NewServerDescription . EndPoint , x . EndPoint ) ) ;
@@ -342,7 +344,7 @@ private ClusterDescription ProcessReplicaSetChange(ClusterDescription clusterDes
342
344
343
345
if ( isCurrentPrimaryStale )
344
346
{
345
- _maxPrimaryVersion = new PrimaryVersion (
347
+ _maxElectionInfo = new ElectionInfo (
346
348
args . NewServerDescription . ReplicaSetConfig . Version . Value ,
347
349
args . NewServerDescription . ElectionId ) ;
348
350
}
@@ -505,12 +507,12 @@ private static class State
505
507
public const int Disposed = 2 ;
506
508
}
507
509
508
- private class PrimaryVersion
510
+ private class ElectionInfo
509
511
{
510
512
private readonly int _setVersion ;
511
513
private readonly ElectionId _electionId ;
512
514
513
- public PrimaryVersion ( int setVersion , ElectionId electionId )
515
+ public ElectionInfo ( int setVersion , ElectionId electionId )
514
516
{
515
517
_setVersion = setVersion ;
516
518
_electionId = electionId ;
0 commit comments