@@ -151,6 +151,7 @@ def find_secondary(self, force=False, quiet=False):
151151 if self .secondary and not force :
152152 return self .secondary
153153
154+ secondary_count = 0
154155 for member in rs_status ['members' ]:
155156 member_uri = MongoUri (member ['name' ], 27017 , rs_name )
156157 if member ['state' ] == 7 :
@@ -186,12 +187,12 @@ def find_secondary(self, force=False, quiet=False):
186187 if self .secondary is None or score > self .secondary ['score' ]:
187188 self .secondary = {
188189 'replSet' : rs_name ,
189- 'count' : 1 if self .secondary is None else self .secondary ['count' ] + 1 ,
190190 'uri' : member_uri ,
191191 'optime' : optime_ts ,
192192 'score' : score
193193 }
194194 log_msg = "Found SECONDARY %s" % member_uri
195+ secondary_count += 1
195196 else :
196197 log_msg = "Found SECONDARY %s with too high replication lag! Skipping" % member_uri
197198
@@ -203,8 +204,7 @@ def find_secondary(self, force=False, quiet=False):
203204 log_data ['score' ] = int (score )
204205 logging .info ("%s: %s" % (log_msg , str (log_data )))
205206 self .replset_summary ['secondary' ] = { "member" : member , "uri" : member_uri .str (), "data" : log_data }
206- if self .secondary is None or (self .secondary ['count' ] + 1 ) < quorum :
207- secondary_count = self .secondary ['count' ] + 1 if self .secondary else 0
207+ if self .secondary is None or (secondary_count + 1 ) < quorum :
208208 logging .error ("Not enough valid secondaries in replset %s to take backup! Num replset members: %i, required quorum: %i" % (
209209 rs_name ,
210210 secondary_count ,
0 commit comments