Merge lp:~stub/charms/trusty/postgresql/replication-control into lp:charms/trusty/postgresql

Proposed by Stuart Bishop
Status: Merged
Merged at revision: 129
Proposed branch: lp:~stub/charms/trusty/postgresql/replication-control
Merge into: lp:charms/trusty/postgresql
Prerequisite: lp:~stub/charms/trusty/postgresql/replication-control-charmhelpers
Diff against target: 125 lines (+85/-3)
4 files modified
Makefile (+1/-1)
actions.yaml (+4/-0)
actions/actions.py (+79/-0)
hooks/hooks.py (+1/-2)
To merge this branch: bzr merge lp:~stub/charms/trusty/postgresql/replication-control
Reviewer Review Type Date Requested Status
Marco Ceppi (community) Approve
Cory Johns (community) Approve
Review via email: mp+262968@code.launchpad.net

Commit message

Add replication-pause and replication-resume actions

Description of the change

Add some actions the Landscape team need for their deployment process.

The actions allow you to enable or disable replication on a hot standby. While disabled, replication does not happen and no writes are made to the hot standby - it remains as a snapshot until replication is resumed.

The dependent branch is just the charm-helpers sync, which is rather large.

To post a comment you must log in.
Revision history for this message
Cory Johns (johnsca) wrote :

Looks good. Seems to work exactly as expected.

+1

review: Approve
Revision history for this message
Marco Ceppi (marcoceppi) wrote :

LGTM +1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Makefile'
2--- Makefile 2015-02-24 16:57:31 +0000
3+++ Makefile 2015-06-25 12:08:42 +0000
4@@ -57,7 +57,7 @@
5 @flake8 -v \
6 --exclude hooks/charmhelpers,hooks/_trial_temp \
7 --ignore=E402 \
8- hooks testing tests test.py
9+ hooks actions testing tests test.py
10
11 sync:
12 @bzr cat \
13
14=== added directory 'actions'
15=== removed directory 'actions'
16=== added file 'actions.yaml'
17--- actions.yaml 1970-01-01 00:00:00 +0000
18+++ actions.yaml 2015-06-25 12:08:42 +0000
19@@ -0,0 +1,4 @@
20+replication-pause:
21+ description: Pause replication replay on a hot standby unit.
22+replication-resume:
23+ description: Resume replication replay on a hot standby unit.
24
25=== added file 'actions/actions.py'
26--- actions/actions.py 1970-01-01 00:00:00 +0000
27+++ actions/actions.py 2015-06-25 12:08:42 +0000
28@@ -0,0 +1,79 @@
29+#!/usr/bin/python
30+# Copyright 2015 Canonical Ltd.
31+#
32+# This file is part of the PostgreSQL Charm for Juju.
33+#
34+# This program is free software: you can redistribute it and/or modify
35+# it under the terms of the GNU General Public License version 3, as
36+# published by the Free Software Foundation.
37+#
38+# This program is distributed in the hope that it will be useful, but
39+# WITHOUT ANY WARRANTY; without even the implied warranties of
40+# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
41+# PURPOSE. See the GNU General Public License for more details.
42+#
43+# You should have received a copy of the GNU General Public License
44+# along with this program. If not, see <http://www.gnu.org/licenses/>.
45+import os.path
46+import sys
47+import traceback
48+
49+
50+hooks_dir = os.path.abspath(os.path.join(os.path.dirname(__file__),
51+ '..', 'hooks'))
52+if hooks_dir not in sys.path:
53+ sys.path.append(hooks_dir)
54+
55+from charmhelpers.core import hookenv
56+import hooks
57+
58+
59+def replication_pause(params):
60+ offset = hooks.postgresql_wal_received_offset()
61+ if offset is None:
62+ hookenv.action_fail('Not a hot standby')
63+ return
64+ hookenv.action_set(dict(offset=offset))
65+
66+ cur = hooks.db_cursor(autocommit=True)
67+ cur.execute('SELECT pg_is_xlog_replay_paused()')
68+ if cur.fetchone()[0] is True:
69+ hookenv.action_fail('Already paused')
70+ return
71+ cur.execute('SELECT pg_xlog_replay_pause()')
72+ hookenv.action_set(dict(result='Paused'))
73+
74+
75+def replication_resume(params):
76+ offset = hooks.postgresql_wal_received_offset()
77+ if offset is None:
78+ hookenv.action_fail('Not a hot standby')
79+ return
80+ hookenv.action_set(dict(offset=offset))
81+
82+ cur = hooks.db_cursor(autocommit=True)
83+ cur.execute('SELECT pg_is_xlog_replay_paused()')
84+ if cur.fetchone()[0] is False:
85+ hookenv.action_fail('Already resumed')
86+ return
87+ cur.execute('SELECT pg_xlog_replay_resume()')
88+ hookenv.action_set(dict(result='Resumed'))
89+
90+
91+def main(argv):
92+ action = os.path.basename(argv[0])
93+ params = hookenv.action_get()
94+ try:
95+ if action == 'replication-pause':
96+ replication_pause(params)
97+ elif action == 'replication-resume':
98+ replication_resume(params)
99+ else:
100+ hookenv.action_fail('Action {} not implemented'.format(action))
101+ except Exception:
102+ hookenv.action_fail('Unhandled exception')
103+ hookenv.action_set(dict(traceback=traceback.format_exc()))
104+
105+
106+if __name__ == '__main__':
107+ main(sys.argv)
108
109=== added symlink 'actions/replication-pause'
110=== target is u'actions.py'
111=== added symlink 'actions/replication-resume'
112=== target is u'actions.py'
113=== modified file 'hooks/hooks.py'
114--- hooks/hooks.py 2015-06-25 08:11:29 +0000
115+++ hooks/hooks.py 2015-06-25 12:08:42 +0000
116@@ -980,8 +980,7 @@
117 'locale', 'encoding', 'version', 'cluster_name', 'pgdg']
118
119 for name in unchangeable_config:
120- if (name in local_state
121- and local_state[name] != config_data.get(name, None)):
122+ if config_data._prev_dict is not None and config_data.changed(name):
123 valid = False
124 log("Cannot change {!r} setting after install.".format(name))
125 local_state[name] = config_data.get(name, None)

Subscribers

People subscribed via source and target branches

to all changes: