Skip to content

Revert IsPrimaryAlive checks #401

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 0 additions & 18 deletions src/backend/access/transam/xlog.c
Original file line number Diff line number Diff line change
Expand Up @@ -5187,24 +5187,6 @@ StartupXLOG(void)
&haveBackupLabel, &haveTblspcMap);
checkPoint = ControlFile->checkPointCopy;

if (ZenithRecoveryRequested)
{
if (wasShutdown)
checkPoint.oldestActiveXid = InvalidTransactionId;
else if (!TransactionIdIsValid(checkPoint.oldestActiveXid))
{
/*
* Pageserver extracts oldestActiveXid from snapshot and running xacts WAL records
* and include it in checkpoint sent in basebackup.
* So oldestActiveXid can be zero only after database initialization when no checkpoints are yet performed
* and not running xacts records was logged.
* In this case it is possible to use FirstNormalTransactionId as safe conservative estimation
* of oldest active transaction XID.
*/
checkPoint.oldestActiveXid = FirstNormalTransactionId;
}
}

/* initialize shared memory variables from the checkpoint record */
ShmemVariableCache->nextXid = checkPoint.nextXid;
ShmemVariableCache->nextOid = checkPoint.nextOid;
Expand Down
33 changes: 1 addition & 32 deletions src/backend/access/transam/xlogrecovery.c
Original file line number Diff line number Diff line change
Expand Up @@ -546,18 +546,6 @@ XLogWaitForReplayOf(XLogRecPtr redoEndRecPtr)
ConditionVariableCancelSleep();
}


/*
* NEON: check if primary node is running.
* Correspondent GUC is received from control plane
*/
static bool
IsPrimaryAlive()
{
const char* val = GetConfigOption("neon.primary_is_running", true, false);
return val != NULL && strcmp(val, "on") == 0;
}

/*
* Prepare the system for WAL recovery, if needed.
*
Expand Down Expand Up @@ -814,26 +802,7 @@ InitWalRecovery(ControlFileData *ControlFile, bool *wasShutdown_ptr,
//EndRecPtr = ControlFile->checkPointCopy.redo;

memcpy(&checkPoint, &ControlFile->checkPointCopy, sizeof(CheckPoint));
// When primary Neon compute node is started, we pretend that it started after a clean shutdown and
// no recovery is needed. We don't need to do WAL replay, the page server does that on a page-by-page basis.
// When a read-only replica is started, PostgreSQL normally waits for a shutdown checkpoint or running-xacts
// record before enabling hot standby, to establish which transactions are still running in the primary,
// and might still commit later. But if we know that the primary is not running - because the control plane
// says so - we can skip that. That avoids having to wait indefinitely if the primary is not running. This is
// particularly important for Neon because we don't start recovery from a checkpoint record, so there's
// no guarantee on when we'll see the next checkpoint or running-xacts record, if ever. so if we know the primary is
// not currently running, also set wasShutdown to 'true'.
if (StandbyModeRequested &&
PrimaryConnInfo != NULL && *PrimaryConnInfo != '\0')
{
if (!IsPrimaryAlive())
wasShutdown = true;
else
wasShutdown = false;
}
else
wasShutdown = true;

wasShutdown = true;

/* Initialize expectedTLEs, like ReadRecord() does */
expectedTLEs = readTimeLineHistory(checkPoint.ThisTimeLineID);
Expand Down