Skip to content
This repository has been archived by the owner on Oct 11, 2024. It is now read-only.

Commit

Permalink
Update to 1.4.4 and add patronictl reinit --wait feature
Browse files Browse the repository at this point in the history
  • Loading branch information
ants committed May 23, 2018
1 parent 6d848d9 commit 9d33bd6
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 4 deletions.
2 changes: 1 addition & 1 deletion RPM/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
mkdir -p /root/rpmbuild/SOURCES
tar -czf /root/rpmbuild/SOURCES/patroni-customizations.tar.gz patroni.2.service patroni-watchdog.service postgres-telia.yml
cp *.patch /root/rpmbuild/SOURCES/
curl -L https://github.com/zalando/patroni/archive/v1.4.3.tar.gz -o /root/rpmbuild/SOURCES/patroni-1.4.3.tar.gz
curl -L https://github.com/zalando/patroni/archive/v1.4.4.tar.gz -o /root/rpmbuild/SOURCES/patroni-1.4.4.tar.gz
rpmbuild -bb patroni.spec
mkdir -p rpms
cp /root/rpmbuild/RPMS/x86_64/patroni-*.rpm rpms/
11 changes: 8 additions & 3 deletions RPM/patroni.spec
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
%define INSTALLPATH /opt/app/patroni
%define debug_package %{nil}
Name: patroni
Version: 1.4.3
Release: 2.rhel7
Version: 1.4.4
Release: 1.rhel7
License: MIT
Summary: PostgreSQL high-availability manager
Source: patroni-1.4.3.tar.gz
Source: patroni-1.4.4.tar.gz
Source1: patroni-customizations.tar.gz
Patch0: service-info-only-in-pretty-format.patch
Patch1: patronictl-reinit-wait.patch
BuildRoot: %{_tmppath}/%{buildprefix}-buildroot
Requires: /usr/bin/python2.7, python-psycopg2 >= 2.6.1, postgresql-server, libyaml
BuildRequires: prelink libyaml-devel gcc
Expand All @@ -22,6 +23,7 @@ Packaged version of Patroni HA manager.
%setup
%setup -D -T -a 1
%patch0 -p1
%patch1 -p1

%build
# remove some things
Expand Down Expand Up @@ -80,6 +82,9 @@ rm -rf $RPM_BUILD_ROOT
%attr(664, root, root) /lib/systemd/system/patroni-watchdog.service

%changelog
* Wed May 23 2018 Ants Aasma 1.4.4-1.rhel7
- Update to 1.4.4
- Add patronictl reinit --wait feature

* Thu May 10 2018 Ants Aasma 1.4.3-2.rhel7
- Only display service info output in pretty format.
Expand Down
87 changes: 87 additions & 0 deletions RPM/patronictl-reinit-wait.patch
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):

0 comments on commit 9d33bd6

Please sign in to comment.