Skip to content

Commit

Permalink
MDB-30823: use replication lag in seconds instead of bytes, allow lag…
Browse files Browse the repository at this point in the history
… in scheduled switchover (#35)

in scheduler switchover, replication lag is allowed, because primary will be stopped before replica promotion

Co-authored-by: reshke <reshkekirill@gmail.com>
  • Loading branch information
efimkin and reshke authored Oct 2, 2024
1 parent 392afca commit 0cf04a0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ def read_config(filename=None, options=None):
'verify_certs': 'no',
'drop_slot_countdown': 10,
'replication_slots_polling': None,
'max_allowed_switchover_lag_ms': 60000,
},
'primary': {
'change_replication_type': 'yes',
Expand Down
8 changes: 5 additions & 3 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1845,16 +1845,18 @@ def _candidate_is_sync_with_primary(self, db_state, switchover_candidate):
return True

replics_info = db_state.get('replics_info', list())
max_allowed_lag_ms = self.config.getint('global', 'max_allowed_switchover_lag_ms')
for replica in replics_info:
if replica.get('sync_state', '') != 'quorum':
continue
if replica.get('application_name', '') != helpers.app_name_from_fqdn(switchover_candidate):
continue
replay_lag = replica.get('replay_location_diff', -1)
if replay_lag != 0:
replay_lag = replica.get('replay_lag_msec', -1)
logging.info(f"Replica {switchover_candidate} has replay lag {replay_lag}ms")
if replay_lag > max_allowed_lag_ms:
if not self.config.getboolean('replica', 'allow_potential_data_loss'):
logging.warning(
f"Replica {switchover_candidate} has replay lag {replay_lag} so cannot be primary for switchover"
f"Replica {switchover_candidate} has replay lag {replay_lag}ms so cannot be primary for switchover, max allowed lag {max_allowed_lag_ms}ms"
)
return None
else:
Expand Down

0 comments on commit 0cf04a0

Please sign in to comment.