From ae53260030902e94a6c70e1a726fde28271b8485 Mon Sep 17 00:00:00 2001 From: Polina Bungina <27892524+hughcapet@users.noreply.github.com> Date: Fri, 29 Mar 2024 12:54:40 +0100 Subject: [PATCH] Extend behave tests with nostream feature (#3036) Check state and permanent logical replication slots behaviour --- features/environment.py | 21 ++++++++++++--------- features/nostream_node.feature | 18 ++++++++++++++++++ features/standby_cluster.feature | 3 ++- features/steps/basic_replication.py | 10 +++++++--- 4 files changed, 39 insertions(+), 13 deletions(-) create mode 100644 features/nostream_node.feature diff --git a/features/environment.py b/features/environment.py index db10c93d..4ed28c57 100644 --- a/features/environment.py +++ b/features/environment.py @@ -256,10 +256,18 @@ class PatroniController(AbstractController): 'parameters': { 'wal_keep_segments': 100, 'archive_mode': 'on', - 'archive_command': (PatroniPoolController.ARCHIVE_RESTORE_SCRIPT - + ' --mode archive ' - + '--dirname {} --filename %f --pathname %p').format( - os.path.join(self._work_directory, 'data', 'wal_archive')) + 'archive_command': + (PatroniPoolController.ARCHIVE_RESTORE_SCRIPT + + ' --mode archive ' + + '--dirname {} --filename %f --pathname %p').format( + os.path.join(self._work_directory, 'data', + f'wal_archive{str(self._citus_group or "")}')).replace('\\', '/'), + 'restore_command': + (PatroniPoolController.ARCHIVE_RESTORE_SCRIPT + + ' --mode restore ' + + '--dirname {} --filename %f --pathname %p').format( + os.path.join(self._work_directory, 'data', + f'wal_archive{str(self._citus_group or "")}')).replace('\\', '/') } } } @@ -928,11 +936,6 @@ class PatroniPoolController(object): custom_config = { 'scope': cluster_name, 'postgresql': { - 'recovery_conf': { - 'restore_command': (self.ARCHIVE_RESTORE_SCRIPT + ' --mode restore ' - + '--dirname {} --filename %f --pathname %p') - .format(os.path.join(self.patroni_path, 'data', 'wal_archive').replace('\\', '/')) - }, 'create_replica_methods': ['no_leader_bootstrap'], 'no_leader_bootstrap': self.backup_restore_config({'no_leader': '1'}) } diff --git a/features/nostream_node.feature b/features/nostream_node.feature new file mode 100644 index 00000000..e049a706 --- /dev/null +++ b/features/nostream_node.feature @@ -0,0 +1,18 @@ +Feature: nostream node + +Scenario: check nostream node is recovering from archive + When I start postgres0 + And I configure and start postgres1 with a tag nostream true + Then "members/postgres1" key in DCS has replication_state=in archive recovery after 10 seconds + And replication works from postgres0 to postgres1 after 30 seconds + +@slot-advance +Scenario: check permanent logical replication slots are not copied + When I issue a PATCH request to http://127.0.0.1:8008/config with {"postgresql": {"parameters": {"wal_level": "logical"}}, "slots":{"test_logical":{"type":"logical","database":"postgres","plugin":"test_decoding"}}} + Then I receive a response code 200 + When I run patronictl.py restart batman postgres0 --force + Then postgres0 has a logical replication slot named test_logical with the test_decoding plugin after 10 seconds + When I configure and start postgres2 with a tag replicatefrom postgres1 + Then "members/postgres2" key in DCS has replication_state=streaming after 10 seconds + And postgres1 does not have a replication slot named test_logical + And postgres2 does not have a replication slot named test_logical diff --git a/features/standby_cluster.feature b/features/standby_cluster.feature index 97c27203..53f8bbac 100644 --- a/features/standby_cluster.feature +++ b/features/standby_cluster.feature @@ -26,7 +26,7 @@ Feature: standby cluster Scenario: Detach exiting node from the cluster When I shut down postgres1 Then postgres0 is a leader after 10 seconds - And "members/postgres0" key in DCS has role=master after 3 seconds + And "members/postgres0" key in DCS has role=master after 5 seconds When I issue a GET request to http://127.0.0.1:8008/ Then I receive a response code 200 @@ -47,6 +47,7 @@ Feature: standby cluster And there is a postgres1_cb.log with "on_role_change standby_leader batman1" in postgres1 data directory When I start postgres2 in a cluster batman1 Then postgres2 role is the replica after 24 seconds + And postgres2 is replicating from postgres1 after 10 seconds And table foo is present on postgres2 after 20 seconds When I issue a GET request to http://127.0.0.1:8010/patroni Then I receive a response code 200 diff --git a/features/steps/basic_replication.py b/features/steps/basic_replication.py index e0d6e5b8..6cb0ac42 100644 --- a/features/steps/basic_replication.py +++ b/features/steps/basic_replication.py @@ -46,11 +46,17 @@ def kill_postgres(context, name): return context.pctl.stop(name, kill=True, postgres=True) +def get_wal_name(context, pg_name): + version = context.pctl.query(pg_name, "SHOW server_version_num").fetchone()[0] + return 'xlog' if int(version) / 10000 < 10 else 'wal' + + @step('I add the table {table_name:w} to {pg_name:w}') def add_table(context, table_name, pg_name): # parse the configuration file and get the port try: context.pctl.query(pg_name, "CREATE TABLE public.{0}()".format(table_name)) + context.pctl.query(pg_name, "SELECT pg_switch_{0}()".format(get_wal_name(context, pg_name))) except pg.Error as e: assert False, "Error creating table {0} on {1}: {2}".format(table_name, pg_name, e) @@ -59,9 +65,7 @@ def add_table(context, table_name, pg_name): def toggle_wal_replay(context, action, pg_name): # pause or resume the wal replay process try: - version = context.pctl.query(pg_name, "SHOW server_version_num").fetchone()[0] - wal_name = 'xlog' if int(version) / 10000 < 10 else 'wal' - context.pctl.query(pg_name, "SELECT pg_{0}_replay_{1}()".format(wal_name, action)) + context.pctl.query(pg_name, "SELECT pg_{0}_replay_{1}()".format(get_wal_name(context, pg_name), action)) except pg.Error as e: assert False, "Error during {0} wal recovery on {1}: {2}".format(action, pg_name, e)