8000 Start Hot Standby faster when initial snapshot is incomplete. · postwait/postgres@ff8451a · GitHub
[go: up one dir, main page]

Skip to content

Commit ff8451a

Browse files
Start Hot Standby faster when initial snapshot is incomplete.
If the initial snapshot had overflowed then we can start whenever the latest snapshot is empty, not overflowed or as we did already, start when the xmin on primary was higher than xmax of our starting snapshot, which proves we have full snapshot data. Bug report by Chris Redekop
1 parent 2f55c53 commit ff8451a

File tree

1 file changed

+32
-20
lines changed
  • src/backend/storage/ipc
    • < 8000 div id=":R5ntddab:" class="PRIVATE_TreeView-item-content prc-TreeView-TreeViewItemContent-f0r0b">procarray.c

1 file changed

+32
-20
lines changed

src/backend/storage/ipc/procarray.c

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -475,9 +475,10 @@ ProcArrayApplyRecoveryInfo(RunningTransactions running)
475475
return;
476476

477477
/*
478-
* If our initial RunningTransactionsData had an overflowed snapshot then we knew
479-
* we were missing some subxids from our snapshot. We can use this data as
480-
* an initial snapshot, but we cannot yet mark it valid. We know that the
478+
* If our initial RunningTransactionsData had an overflowed snapshot then
479+
* we knew we were missing some subxids from our snapshot. If we continue
480+
* to see overflowed snapshots then we might never be able to start up,
481+
* so we make another test to see if our snapshot is now valid. We know
481482
* missing subxids are equal to or earlier than nextXid. After we
482483
* initialise we continue to apply changes during recovery, so once the
483484
* oldestRunningXid is later than the nextXid from the initial snapshot we
@@ -486,21 +487,31 @@ ProcArrayApplyRecoveryInfo(RunningTransactions running)
486487
*/
487488
if (standbyState == STANDBY_SNAPSHOT_PENDING)
488489
{
489-
if (TransactionIdPrecedes(standbySnapshotPendingXmin,
490-
running->oldestRunningXid))
490+
/*
491+
* If the snapshot isn't overflowed or if its empty we can
492+
* reset our pending state and use this snapshot instead.
493+
*/
494+
if (!running->subxid_overflow || running->xcnt == 0)
491495
{
492-
standbyState = STANDBY_SNAPSHOT_READY;
493-
elog(trace_recovery(DEBUG2),
494-
"running xact data now proven complete");
495-
elog(trace_recovery(DEBUG2),
496-
"recovery snapshots are now enabled");
496+
standbyState = STANDBY_INITIALIZED;
497497
}
498498
else
499-
elog(trace_recovery(DEBUG2),
500-
"recovery snapshot waiting for %u oldest active xid on standby is %u",
501-
standbySnapshotPendingXmin,
502-
running->oldestRunningXid);
503-
return;
499+
{
500+
if (TransactionIdPrecedes(standbySnapshotPendingXmin,
501+
running->oldestRunningXid))
502+
{
503+
standbyState = STANDBY_SNAPSHOT_READY;
504+
elog(trace_recovery(DEBUG1),
505+
"recovery snapshots are now enabled");
506+
}
507+
else
508+
elog(trace_recovery(DEBUG1),
509+
"recovery snapshot waiting for non-overflowed snapshot or "
510+
"until oldest active xid on standby is at least %u (now %u)",
511+
standbySnapshotPendingXmin,
512+
running->oldestRunningXid);
513+
return;
514+
}
504515
}
505516

506517
Assert(standbyState == STANDBY_INITIALIZED);
@@ -606,7 +617,6 @@ ProcArrayApplyRecoveryInfo(RunningTransactions running)
606617
standbyState = STANDBY_SNAPSHOT_READY;
607618

608619
standbySnapshotPendingXmin = InvalidTransactionId;
609-
procArray->lastOverflowedXid = InvalidTransactionId;
610620
}
611621

612622
/*
@@ -630,13 +640,15 @@ ProcArrayApplyRecoveryInfo(RunningTransactions running)
630640

631641
LWLockRelease(ProcArrayLock);
632642

633-
elog(trace_recovery(DEBUG2), "running transaction data initialized");
634643
KnownAssignedXidsDisplay(trace_recovery(DEBUG3));
635644
if (standbyState == STANDBY_SNAPSHOT_READY)
636-
elog(trace_recovery(DEBUG2), "recovery snapshots are now enabled");
645+
elog(trace_recovery(DEBUG1), "recovery snapshots are now enabled");
637646
else
638-
ereport(LOG,
639-
(errmsg("consistent state delayed because recovery snapshot incomplete")));
647+
elog(trace_recovery(DEBUG1),
648+
"recovery snapshot waiting for non-overflowed snapshot or "
649+
"until oldest active xid on standby is at least %u (now %u)",
650+
standbySnapshotPendingXmin,
651+
running->oldestRunningXid);
640652
}
641653

642654
/*

0 commit comments

Comments
 (0)
0