diff --git a/patroni/ha.py b/patroni/ha.py index 12927526..3988cb75 100644 --- a/patroni/ha.py +++ b/patroni/ha.py @@ -1960,8 +1960,7 @@ class Ha(object): if cluster: slots = self.state_handler.slots_handler.sync_replication_slots(cluster, self.patroni.nofailover, - self.patroni.replicatefrom, - self.is_paused()) + self.patroni.replicatefrom) # Don't copy replication slots if failsafe_mode is active return [] if self.failsafe_is_active() else slots diff --git a/patroni/postgresql/slots.py b/patroni/postgresql/slots.py index 66bb1f00..025a88a9 100644 --- a/patroni/postgresql/slots.py +++ b/patroni/postgresql/slots.py @@ -320,7 +320,7 @@ class SlotsHandler: ' FULL OUTER JOIN dropped ON true'), name) return (rows[0][0], rows[0][1]) if rows else (False, False) - def _drop_incorrect_slots(self, cluster: Cluster, slots: Dict[str, Any], paused: bool) -> None: + def _drop_incorrect_slots(self, cluster: Cluster, slots: Dict[str, Any]) -> None: """Compare required slots and configured as permanent slots with those found, dropping extraneous ones. .. note:: @@ -331,11 +331,10 @@ class SlotsHandler: :param cluster: cluster state information object. :param slots: dictionary of desired slot names as keys with slot attributes as a dictionary value, if known. - :param paused: ``True`` if the patroni cluster is currently in a paused state. """ # drop old replication slots which are not presented in desired slots. for name in set(self._replication_slots) - set(slots): - if not paused and not self.ignore_replication_slot(cluster, name): + if not global_config.is_paused and not self.ignore_replication_slot(cluster, name): active, dropped = self.drop_replication_slot(name) if dropped: logger.info("Dropped unknown replication slot '%s'", name) @@ -494,7 +493,7 @@ class SlotsHandler: return create_slots + copy_slots def sync_replication_slots(self, cluster: Cluster, nofailover: bool, - replicatefrom: Optional[str] = None, paused: bool = False) -> List[str]: + replicatefrom: Optional[str] = None) -> List[str]: """During the HA loop read, check and alter replication slots found in the cluster. Read physical and logical slots from ``pg_replication_slots``, then compare to those configured in the DCS. @@ -506,7 +505,6 @@ class SlotsHandler: :param cluster: object containing stateful information for the cluster. :param nofailover: ``True`` if this node has been tagged to not be a failover candidate. :param replicatefrom: the tag containing the node to replicate from. - :param paused: ``True`` if the cluster is in maintenance mode. :returns: list of logical replication slots names that should be copied from the primary. """ @@ -518,7 +516,7 @@ class SlotsHandler: slots = cluster.get_replication_slots(self._postgresql.name, self._postgresql.role, nofailover, self._postgresql.major_version, show_error=True) - self._drop_incorrect_slots(cluster, slots, paused) + self._drop_incorrect_slots(cluster, slots) self._ensure_physical_slots(slots) diff --git a/tests/test_slots.py b/tests/test_slots.py index 215c9b84..ee1c4ee9 100644 --- a/tests/test_slots.py +++ b/tests/test_slots.py @@ -52,9 +52,10 @@ class TestSlotsHandler(BaseTestPostgresql): mock_debug.assert_called_once() self.p.set_role('replica') with patch.object(Postgresql, 'is_primary', Mock(return_value=False)), \ + patch.object(global_config.__class__, 'is_paused', PropertyMock(return_value=True)), \ patch.object(SlotsHandler, 'drop_replication_slot') as mock_drop: config.data['slots'].pop('ls') - self.s.sync_replication_slots(cluster, False, paused=True) + self.s.sync_replication_slots(cluster, False) mock_drop.assert_not_called() self.p.set_role('primary') with mock.patch('patroni.postgresql.Postgresql.role', new_callable=PropertyMock(return_value='replica')):