diff --git a/pgxn/neon/walproposer.c b/pgxn/neon/walproposer.c index 3befb42030..f6b33e6881 100644 --- a/pgxn/neon/walproposer.c +++ b/pgxn/neon/walproposer.c @@ -1379,7 +1379,12 @@ 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->config->syncSafekeepers) + 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) { /* * Basebackup LSN always points to the beginning of the record (not diff --git a/pgxn/neon/walproposer.h b/pgxn/neon/walproposer.h index 547c1b82ab..81e2d2d5b7 100644 --- a/pgxn/neon/walproposer.h +++ b/pgxn/neon/walproposer.h @@ -675,6 +675,12 @@ 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 4da4d295dc..942f342c9b 100644 --- a/pgxn/neon/walproposer_pg.c +++ b/pgxn/neon/walproposer_pg.c @@ -2040,6 +2040,14 @@ 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) { @@ -2095,6 +2103,7 @@ 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 b1763f8e10..a0de60fc5e 100644 --- a/test_runner/regress/test_replica_promote.py +++ b/test_runner/regress/test_replica_promote.py @@ -5,6 +5,7 @@ This far, only contains a test that we don't break and that the data is persiste """ import psycopg2 +import time from fixtures.neon_fixtures import Endpoint, NeonEnv, wait_replica_caughtup from fixtures.pg_version import PgVersion from pytest import raises