Percona-Lab / mongodb_consistent_backup

A tool for performing consistent backups of MongoDB Clusters or Replica Sets
https://www.percona.com
Apache License 2.0
276 stars 81 forks source link

Fix sanity checking for member score #300

Closed dschneller closed 5 years ago

dschneller commented 5 years ago

The check was causing exceptions in case there was no secondary set due to the conditions before:

[ERROR] [MainProcess] [Main:exception:208] Failed to start oplog tailing threads! Error: 'NoneType' object has no attribute '__getitem__'
Traceback (most recent call last):
  File ".../mongodb_consistent_backup/Main.py", line 363, in run
    self.oplogtailer.run()
  File ".../mongodb_consistent_backup/Oplog/Tailer/Tailer.py", line 56, in run
    secondary   = self.replsets[shard].find_secondary()
  File ".../mongodb_consistent_backup/Replication/Replset.py", line 259, in find_secondary
    if self.secondary['score'] == 0:
TypeError: 'NoneType' object has no attribute '__getitem__'

Added "is not None" to the check condition to ensure the score is only validated if a secondary is actually set.

banpei-dbart commented 5 years ago

We encountered the same issue where no secondary was set due to too high replication lag on both secondaries. In the previous state the consistent backup would simply crash with the error above, but after I patched it with the change by @dschneller it now gave us a clear message that the secondaries were lagging behind too far to be used.