Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some language in messages, comments, and docstrings #2

Open
wants to merge 10 commits into
base: multisite
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions patroni/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -671,13 +671,9 @@ def do_GET_metrics(self) -> None:
metrics.append("# TYPE patroni_is_paused gauge")
metrics.append("patroni_is_paused{0} {1}".format(labels, int(postgres.get('pause', 0))))

if patroni.multisite.is_active:
metrics.append("# HELP patroni_multisite_switches Number of times multisite leader has been switched")
metrics.append("# TYPE patroni_multisite_switches counter")
metrics.append("patroni_multisite_switches{0} {1}"
.format(labels, patroni.multisite.site_switches))
patroni.multisite.append_metrics(metrics, labels)

self.write_response(200, '\n'.join(metrics)+'\n', content_type='text/plain')
self.write_response(200, '\n'.join(metrics) + '\n', content_type='text/plain')

def do_GET_multisite(self):
self._write_json_response(200, self.server.patroni.multisite.status())
Expand Down Expand Up @@ -1199,7 +1195,7 @@ def do_POST_multisite_switchover(self):
if not request:
return
if not self.server.patroni.multisite.is_active:
return self._write_response(400, 'Cluster is not in multisite mode')
return self.write_response(400, 'Cluster is not in multisite mode')

scheduled_at = request.get('scheduled_at')
target_site = request.get('target_site')
Expand Down
2 changes: 0 additions & 2 deletions patroni/ctl.py
Original file line number Diff line number Diff line change
Expand Up @@ -1502,8 +1502,6 @@ def get_cluster_service_info(cluster: Dict[str, Any]) -> List[str]:
"""
service_info: List[str] = []



if 'multisite' in cluster:
info = f"Multisite {cluster['multisite']['name'] or ''} is {cluster['multisite']['status'].lower()}"
standby_config = cluster['multisite'].get('standby_config', {})
Expand Down
5 changes: 3 additions & 2 deletions patroni/dcs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ class Failover(NamedTuple):
leader: Optional[str]
candidate: Optional[str]
scheduled_at: Optional[datetime.datetime]
target_site: Optional[str]
target_site: Optional[str] = None

@staticmethod
def from_node(version: _Version, value: Union[str, Dict[str, str]]) -> 'Failover':
Expand Down Expand Up @@ -496,7 +496,8 @@ def from_node(version: _Version, value: Union[str, Dict[str, str]]) -> 'Failover
if data.get('scheduled_at'):
data['scheduled_at'] = dateutil.parser.parse(data['scheduled_at'])

return Failover(version, data.get('leader'), data.get('member'), data.get('scheduled_at'), data.get('target_site'))
return Failover(version, data.get('leader'), data.get('member'), data.get('scheduled_at'),
data.get('target_site'))

def __len__(self) -> int:
"""Implement ``len`` function capability.
Expand Down
3 changes: 2 additions & 1 deletion patroni/dcs/etcd3.py
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,8 @@ def _cluster_from_nodes(self, nodes: Dict[str, Any]) -> Cluster:

# get leader
leader = nodes.get(self._LEADER)
if not self._ctl and not self._multisite and leader and leader['value'] == self._name and self._lease != leader.get('lease'):
if not self._ctl and not self._multisite and leader and leader['value'] == self._name \
and self._lease != leader.get('lease'):
logger.warning('I am the leader but not owner of the lease')

if leader:
Expand Down
12 changes: 7 additions & 5 deletions patroni/ha.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,8 @@
self.set_is_leader(ret)
multisite_ret = self.patroni.multisite.resolve_leader()
if multisite_ret:
logger.error("Releasing leader lock because multi site status is: "+multisite_ret)
self.dcs.delete_leader()
logger.error("Releasing leader lock because multi site status is: %s", multisite_ret)
self.dcs.delete_leader(None, None)
return False
return ret

Expand Down Expand Up @@ -566,7 +566,7 @@
# no leader, but configuration may allowed replica creation using backup tools
create_replica_methods = self.get_standby_cluster_config().get('create_replica_methods', []) \
if self.is_standby_cluster() else None
can_bootstrap = self.state_handler.can_create_replica_without_replication_connection(create_replica_methods)

Check failure on line 569 in patroni/ha.py

View workflow job for this annotation

GitHub Actions / pyright

Argument of type "Any | list[str] | str | None" cannot be assigned to parameter "replica_methods" of type "List[str] | None" in function "can_create_replica_without_replication_connection"   Type "Any | list[str] | str | None" is not assignable to type "List[str] | None"     Type "str" is not assignable to type "List[str] | None"       "str" is not assignable to "List[str]"       "str" is not assignable to "None" (reportArgumentType)
concurrent_bootstrap = self.cluster.initialize == ""
if can_bootstrap and not concurrent_bootstrap:
msg = 'bootstrap (without leader)'
Expand Down Expand Up @@ -1555,7 +1555,7 @@
'graceful': dict(stop='fast', checkpoint=True, release=True, offline=False, async_req=False), # noqa: E241,E501
'immediate': dict(stop='immediate', checkpoint=False, release=True, offline=False, async_req=True), # noqa: E241,E501
'immediate-nolock': dict(stop='immediate', checkpoint=False, release=False, offline=False, async_req=True), # noqa: E241,E501
'multisite': dict(stop='fast', checkpoint=True, release=False, offline=True, async_req=False), # noqa: E241,E501
'multisite': dict(stop='fast', checkpoint=True, release=False, offline=True, async_req=False), # noqa: E241,E501
}[mode]

logger.info('Demoting self (%s)', mode)
Expand All @@ -1577,7 +1577,7 @@
status['released'] = True

if mode == 'multisite':
on_shutdown = self.patroni.multisite.on_shutdown
on_shutdown = self.patroni.multisite.on_shutdown # noqa: F811

def before_shutdown() -> None:
if self.state_handler.mpp_handler.is_coordinator():
Expand All @@ -1599,8 +1599,9 @@
with self._async_executor:
self.release_leader_key_voluntarily(checkpoint_location)
time.sleep(2) # Give a time to somebody to take the leader lock
# FIXME: multisite.on_shutdown() was already called above with _state_handler.stop(), do we really need it here?
if mode == 'multisite':
self.patroni.multisite.on_shutdown(self.state_handler.latest_checkpoint_location())

Check failure on line 1604 in patroni/ha.py

View workflow job for this annotation

GitHub Actions / pyright

Argument missing for parameter "prev_location" (reportCallIssue)
if mode_control['offline']:
node_to_follow, leader = None, None
else:
Expand Down Expand Up @@ -1712,7 +1713,8 @@
if failover:
if self.is_paused() and failover.leader and failover.candidate:
logger.info('Updating failover key after acquiring leader lock...')
self.dcs.manual_failover('', failover.candidate, failover.scheduled_at, version=failover.version)
self.dcs.manual_failover('', failover.candidate, failover.scheduled_at,
version=failover.version)
else:
logger.info('Cleaning up failover key after acquiring leader lock...')
self.dcs.manual_failover('', '')
Expand Down
Loading
Loading