diff --git a/pgxn/neon/walproposer.c b/pgxn/neon/walproposer.c index f6b33e6881..02d6d18f0c 100644 --- a/pgxn/neon/walproposer.c +++ b/pgxn/neon/walproposer.c @@ -1379,12 +1379,7 @@ ProcessPropStartPos(WalProposer *wp) * we must bail out, as clog and other non rel data is inconsistent. */ walprop_shared = wp->api.get_shmem_state(wp); - if (wp->api.get_shmem_state(wp)->bgw_started) - { - /* Replica promotion */ - wp->api.set_redo_start_lsn(wp, wp->propTermStartLsn); - } - else if (!wp->config->syncSafekeepers) + if (!wp->config->syncSafekeepers && !wp->api.get_shmem_state(wp)->bgw_started) { /* * Basebackup LSN always points to the beginning of the record (not diff --git a/pgxn/neon/walproposer.h b/pgxn/neon/walproposer.h index 81e2d2d5b7..547c1b82ab 100644 --- a/pgxn/neon/walproposer.h +++ b/pgxn/neon/walproposer.h @@ -675,12 +675,6 @@ typedef struct walproposer_api */ XLogRecPtr (*get_redo_start_lsn) (WalProposer *wp); - /* - * Get a basebackup LSN. Used to cross-validate with the latest available - * LSN on the safekeepers. - */ - void (*set_redo_start_lsn) (WalProposer *wp, XLogRecPtr lsn); - /* * Finish sync safekeepers with the given LSN. This function should not * return and should exit the program. diff --git a/pgxn/neon/walproposer_pg.c b/pgxn/neon/walproposer_pg.c index 942f342c9b..41ecfc8414 100644 --- a/pgxn/neon/walproposer_pg.c +++ b/pgxn/neon/walproposer_pg.c @@ -2040,13 +2040,6 @@ walprop_pg_get_redo_start_lsn(WalProposer *wp) return GetRedoStartLsn(); } -static void -walprop_pg_set_redo_start_lsn(WalProposer *wp, XLogRecPtr lsn) -{ -#if PG_VERSION_NUM >= 150000 - SetRedoStartLsn(lsn); -#endif -} static bool walprop_pg_strong_random(WalProposer *wp, void *buf, size_t len) @@ -2103,7 +2096,6 @@ static const walproposer_api walprop_pg = { .wait_event_set = walprop_pg_wait_event_set, .strong_random = walprop_pg_strong_random, .get_redo_start_lsn = walprop_pg_get_redo_start_lsn, - .set_redo_start_lsn = walprop_pg_set_redo_start_lsn, .finish_sync_safekeepers = walprop_pg_finish_sync_safekeepers, .process_safekeeper_feedback = walprop_pg_process_safekeeper_feedback, .log_internal = walprop_pg_log_internal, diff --git a/test_runner/regress/test_replica_promote.py b/test_runner/regress/test_replica_promote.py index a0de60fc5e..962f132d56 100644 --- a/test_runner/regress/test_replica_promote.py +++ b/test_runner/regress/test_replica_promote.py @@ -5,12 +5,14 @@ This far, only contains a test that we don't break and that the data is persiste """ import psycopg2 +import pytest import time from fixtures.neon_fixtures import Endpoint, NeonEnv, wait_replica_caughtup from fixtures.pg_version import PgVersion +from fixtures.log_helper import log from pytest import raises - +@pytest.mark.timeout(6000) def test_replica_promotes(neon_simple_env: NeonEnv, pg_version: PgVersion): """ Test that a replica safely promotes, and can commit data updates which @@ -79,18 +81,32 @@ def test_replica_promotes(neon_simple_env: NeonEnv, pg_version: PgVersion): secondary_cur.execute(f"alter system set neon.safekeepers='{safekeepers}'") secondary_cur.execute("select pg_reload_conf()"); - new_primary_conn = secondary.connect() + new_primary = secondary + old_primary = primary + + new_primary_conn = new_primary.connect() new_primary_cur = new_primary_conn.cursor() new_primary_cur.execute("INSERT INTO t (payload) SELECT generate_series(101, 200)") new_primary_cur.execute("select count(*) from t") assert new_primary_cur.fetchone() == (200,) + new_primary_cur.execute("select pg_current_wal_flush_lsn()") + lsn = new_primary_cur.fetchall()[0][0] + log.info(f"New primary flush LSN={lsn}") - secondary.stop(mode="immediate") + new_primary.stop(mode="immediate") + new_primary.hot_standby = False + new_primary.start() - primary.start() + with new_primary.connect() as new_primary_conn: + new_primary_cur = new_primary_conn.cursor() + new_primary_cur.execute("select count(*) from t") + assert new_primary_cur.fetchone() == (200,) - with primary.connect() as primary_conn: - primary_cur = primary_conn.cursor() - primary_cur.execute("select count(*) from t") - assert primary_cur.fetchone() == (200,) + new_primary.stop() + old_primary.start() + + with old_primary.connect() as old_primary_conn: + old_primary_cur = old_primary_conn.cursor() + old_primary_cur.execute("select count(*) from t") + assert old_primary_cur.fetchone() == (200,)