Pass 'master' role to a callback script instead of 'promoted' (#2554)

Co-authored-by: Alexander Kukushkin <cyberdemn@gmail.com>
This commit is contained in:
Polina Bungina
2023-02-08 14:09:51 +01:00
committed by GitHub
parent 1669a49b2d
commit b85f155dbe
4 changed files with 8 additions and 7 deletions

View File

@@ -65,6 +65,7 @@ Feature: basic replication
Then I receive a response returncode 0
And postgres2 role is the primary after 24 seconds
And Response on GET http://127.0.0.1:8010/history contains recovery after 10 seconds
And there is a postgres2_cb.log with "on_role_change master batman" in postgres2 data directory
When I issue a PATCH request to http://127.0.0.1:8010/config with {"synchronous_mode": null, "master_start_timeout": 0}
Then I receive a response code 200
When I add the table bar to postgres2

View File

@@ -201,6 +201,8 @@ class PatroniController(AbstractController):
config['name'] = name
config['postgresql']['data_dir'] = self._data_dir.replace('\\', '/')
config['postgresql']['basebackup'] = [{'checkpoint': 'fast'}]
config['postgresql']['callbacks'] = {
'on_role_change': '{0} features/callback2.py {1}'.format(self._context.pctl.PYTHON, name)}
config['postgresql']['use_unix_socket'] = os.name != 'nt' # windows doesn't yet support unix-domain sockets
config['postgresql']['use_unix_socket_repl'] = os.name != 'nt'
config['postgresql']['pgpass'] = os.path.join(tempfile.gettempdir(), 'pgpass_' + name).replace('\\', '/')

View File

@@ -11,11 +11,8 @@ def start_patroni_with_a_name_value_tag(context, name, tag_name, tag_value):
@then('There is a {label} with "{content}" in {name:w} data directory')
def check_label(context, label, content, name):
label = context.pctl.read_label(name, label)
if label is None:
label = ""
label = label.replace('\n', '\\n')
assert content in label, "\"{0}\" doesn't contain {1}".format(label, content)
value = (context.pctl.read_label(name, label) or '').replace('\n', '\\n')
assert content in value, "\"{0}\" in {1} doesn't contain {2}".format(value, label, content)
@step('I create label with "{content:w}" in {name:w} data directory')

View File

@@ -505,11 +505,12 @@ class Postgresql(object):
if self.callback and cb_name in self.callback:
cmd = self.callback[cb_name]
role = 'master' if self.role == 'promoted' else self.role
try:
cmd = shlex.split(self.callback[cb_name]) + [cb_name, self.role, self.scope]
cmd = shlex.split(self.callback[cb_name]) + [cb_name, role, self.scope]
self._callback_executor.call(cmd)
except Exception:
logger.exception('callback %s %s %s %s failed', cmd, cb_name, self.role, self.scope)
logger.exception('callback %s %s %s %s failed', cmd, cb_name, role, self.scope)
@property
def role(self):