Some hacks for replica primotion

This commit is contained in:
Konstantin Knizhnik
2025-05-16 16:22:34 +03:00
parent 41adde29d7
commit b94054dca0
4 changed files with 22 additions and 1 deletions

View File

@@ -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

View File

@@ -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.

View File

@@ -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,

View File

@@ -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