|
17 | 17 | from .dcs import AbstractDCS, Cluster, Leader, Member, RemoteMember, Status, SyncState |
18 | 18 | from .exceptions import DCSError, PatroniFatalException, PostgresConnectionException |
19 | 19 | from .postgresql.callback_executor import CallbackAction |
20 | | -from .postgresql.misc import postgres_version_to_int, PostgresqlState |
| 20 | +from .postgresql.misc import postgres_version_to_int, PostgresqlRole, PostgresqlState |
21 | 21 | from .postgresql.postmaster import PostmasterProcess |
22 | 22 | from .postgresql.rewind import Rewind |
23 | 23 | from .quorum import QuorumStateResolver |
@@ -515,7 +515,7 @@ def touch_member(self) -> bool: |
515 | 515 | ret = self.dcs.touch_member(data) |
516 | 516 | if ret: |
517 | 517 | new_state = (data['state'], data['role']) |
518 | | - if self._last_state != new_state and new_state == (PostgresqlState.RUNNING, 'primary'): |
| 518 | + if self._last_state != new_state and new_state == (PostgresqlState.RUNNING, PostgresqlRole.PRIMARY): |
519 | 519 | self.notify_mpp_coordinator('after_promote') |
520 | 520 | self._last_state = new_state |
521 | 521 | return ret |
@@ -661,7 +661,7 @@ def recover(self) -> str: |
661 | 661 | and data.get('Database cluster state') in ('in production', 'in crash recovery', |
662 | 662 | 'shutting down', 'shut down')\ |
663 | 663 | and self.state_handler.state == PostgresqlState.CRASHED\ |
664 | | - and self.state_handler.role == 'primary'\ |
| 664 | + and self.state_handler.role == PostgresqlRole.PRIMARY\ |
665 | 665 | and not self.state_handler.config.recovery_conf_exists(): |
666 | 666 | # We know 100% that we were running as a primary a few moments ago, therefore could just start postgres |
667 | 667 | msg = 'starting primary after failure' |
@@ -1184,7 +1184,7 @@ def update_failsafe(self, data: Dict[str, Any]) -> Union[int, str, None]: |
1184 | 1184 |
|
1185 | 1185 | :returns: the reason why caller shouldn't continue as a primary or the current value of received/replayed LSN. |
1186 | 1186 | """ |
1187 | | - if self.state_handler.state == PostgresqlState.RUNNING and self.state_handler.role == 'primary': |
| 1187 | + if self.state_handler.state == PostgresqlState.RUNNING and self.state_handler.role == PostgresqlRole.PRIMARY: |
1188 | 1188 | return 'Running as a leader' |
1189 | 1189 | self._failsafe.update(data) |
1190 | 1190 | return self._last_wal_lsn |
|
0 commit comments