This repository has been archived by the owner on Oct 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update to 1.4.4 and add patronictl reinit --wait feature
- Loading branch information
Showing
3 changed files
with
96 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
diff --git a/patroni/api.py b/patroni/api.py | ||
index 4b7d835..c6c2b5e 100644 | ||
--- a/patroni/api.py | ||
+++ b/patroni/api.py | ||
@@ -72,6 +72,7 @@ class RestApiHandler(BaseHTTPRequestHandler): | ||
response['watchdog_failed'] = True | ||
if patroni.ha.is_paused(): | ||
response['pause'] = True | ||
+ response['action'] = self.server.patroni.ha.action | ||
self._write_json_response(status_code, response) | ||
|
||
def do_GET(self, write_status_code_only=False): | ||
diff --git a/patroni/ctl.py b/patroni/ctl.py | ||
index 7f97986..fb331a3 100644 | ||
--- a/patroni/ctl.py | ||
+++ b/patroni/ctl.py | ||
@@ -519,20 +519,37 @@ def restart(obj, cluster_name, member_names, force, role, p_any, scheduled, vers | ||
@click.argument('cluster_name') | ||
@click.argument('member_names', nargs=-1) | ||
@option_force | ||
+@click.option('--wait', help='Wait until reinitialization completes', is_flag=True) | ||
@click.pass_obj | ||
-def reinit(obj, cluster_name, member_names, force): | ||
+def reinit(obj, cluster_name, member_names, force, wait): | ||
cluster = get_dcs(obj, cluster_name).get_cluster() | ||
members = get_members(cluster, cluster_name, member_names, None, force, 'reinitialize') | ||
|
||
+ wait_on_members = [] | ||
for member in members: | ||
body = {'force': force} | ||
while True: | ||
r = request_patroni(member, 'post', 'reinitialize', body, auth_header(obj)) | ||
- if not check_response(r, member.name, 'reinitialize') and r.text.endswith(' already in progress') \ | ||
+ started = check_response(r, member.name, 'reinitialize') | ||
+ if not started and r.text.endswith(' already in progress') \ | ||
and not force and click.confirm('Do you want to cancel it and reinitialize anyway?'): | ||
body['force'] = True | ||
continue | ||
break | ||
+ if started and wait: | ||
+ wait_on_members.append(member) | ||
+ | ||
+ last_display = [] | ||
+ while wait_on_members: | ||
+ if wait_on_members != last_display: | ||
+ click.echo('Waiting for reinitialize to complete on: {0}'.format( | ||
+ ", ".join(member.name for member in wait_on_members)) | ||
+ ) | ||
+ last_display[:] = wait_on_members | ||
+ time.sleep(2) | ||
+ for member in wait_on_members: | ||
+ if request_patroni(member, 'get', 'patroni').json().get('action') != 'reinitialize': | ||
+ wait_on_members.remove(member) | ||
|
||
|
||
def _do_failover_or_switchover(obj, action, cluster_name, master, candidate, force, scheduled=None): | ||
diff --git a/patroni/ha.py b/patroni/ha.py | ||
index d8eca50..b06fdb4 100644 | ||
--- a/patroni/ha.py | ||
+++ b/patroni/ha.py | ||
@@ -944,6 +944,13 @@ class Ha(object): | ||
|
||
return self._async_executor.scheduled_action + ' in progress' | ||
|
||
+ @property | ||
+ def action(self): | ||
+ with self._async_executor: | ||
+ if self._async_executor.busy: | ||
+ return self._async_executor.scheduled_action | ||
+ return None | ||
+ | ||
@staticmethod | ||
def sysid_valid(sysid): | ||
# sysid does tv_sec << 32, where tv_sec is the number of seconds sine 1970, | ||
diff --git a/tests/test_api.py b/tests/test_api.py | ||
index d4f0d97..25513e5 100644 | ||
--- a/tests/test_api.py | ||
+++ b/tests/test_api.py | ||
@@ -91,6 +91,8 @@ class MockHa(object): | ||
def is_paused(): | ||
return True | ||
|
||
+ action = None | ||
+ | ||
|
||
class MockPatroni(object): | ||
|