Some hacks for replica primotion

This commit is contained in:
Konstantin Knizhnik
2025-05-16 16:22:34 +03:00
committed by Mikhail Kot
parent 607813a1cf
commit 6704883ded
4 changed files with 22 additions and 1 deletions

View File

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

@@ -2052,6 +2052,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)
{
@@ -2107,6 +2115,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