summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/backend/storage/ipc/procarray.c51
1 files changed, 43 insertions, 8 deletions
diff --git a/src/backend/storage/ipc/procarray.c b/src/backend/storage/ipc/procarray.c
index 04bf18ceec..ebef69671f 100644
--- a/src/backend/storage/ipc/procarray.c
+++ b/src/backend/storage/ipc/procarray.c
@@ -520,16 +520,28 @@ void
ProcArrayDisplay(int trace_level)
{
ProcArrayStruct *arrayP = procArray;
- int index;
+ int index, i;
+ StringInfoData buf;
for (index = 0; index < arrayP->numProcs; index++)
{
- PGPROC *RecoveryProc = arrayP->procs[index];
+ PGPROC *proc = arrayP->procs[index];
+ TransactionId xid = proc->xid;
+ int nsubxids = proc->subxids.nxids;
+
+ initStringInfo(&buf);
+ appendStringInfo(&buf, "procarray %d xid %d lsn %X/%X ",
+ index, xid,
+ proc->lsn.xlogid, proc->lsn.xrecoff);
+ if (nsubxids > 0)
+ {
+ appendStringInfo(&buf, "nsubxids %u : ", nsubxids);
- if (TransactionIdIsValid(RecoveryProc->xid))
- elog(trace_level,
- "proc %d proc->xid %d proc->lsn %X/%X", index, RecoveryProc->xid,
- RecoveryProc->lsn.xlogid, RecoveryProc->lsn.xrecoff);
+ for (i = 0; i < nsubxids; i++)
+ appendStringInfo(&buf, "%u ", proc->subxids.xids[i]);
+ }
+
+ elog(trace_level, "%s", buf.data);
}
UnobservedTransactionsDisplay(trace_level);
@@ -572,6 +584,7 @@ ProcArrayUpdateRecoveryTransactions(XLogRecPtr lsn, xl_xact_running_xacts *xlrec
ProcArrayStruct *arrayP = procArray;
int xid_index; /* main loop */
int index;
+ TransactionId oldestRunningXid = xlrec->oldestRunningXid;
if (TransactionIdPrecedes(latestObservedXid, xlrec->latestRunningXid))
{
@@ -584,6 +597,19 @@ ProcArrayUpdateRecoveryTransactions(XLogRecPtr lsn, xl_xact_running_xacts *xlrec
LWLockAcquire(ProcArrayLock, LW_EXCLUSIVE);
+ ProcArrayDisplay(trace_recovery(DEBUG3));
+
+ /*
+ * If there was nothing running use latestCompletedXid as the barrier
+ * value for when we sweep away old transaction entries
+ */
+ if (!TransactionIdIsValid(oldestRunningXid))
+ {
+ Assert(xlrec->xcnt == 0);
+ oldestRunningXid = xlrec->latestCompletedXid;
+ TransactionIdAdvance(oldestRunningXid);
+ }
+
/*
* Scan the proc array for stale recovery PGPROC entries, and
* remove them. This shouldn't happen, except when FATAL error
@@ -596,7 +622,7 @@ ProcArrayUpdateRecoveryTransactions(XLogRecPtr lsn, xl_xact_running_xacts *xlrec
{
PGPROC *p = arrayP->procs[index];
- if (TransactionIdPrecedes(p->xid, xlrec->oldestRunningXid) && p->pid == 0)
+ if (TransactionIdPrecedes(p->xid, oldestRunningXid) && p->pid == 0)
{
elog(LOG, "removing stale proc array entry for transaction %d", p->xid);
@@ -732,7 +758,7 @@ ProcArrayUpdateRecoveryTransactions(XLogRecPtr lsn, xl_xact_running_xacts *xlrec
procArray->allowStandbySnapshots = true;
RunningXactIsValid = true;
- ProcArrayDisplay(trace_recovery(DEBUG5));
+ ProcArrayDisplay(trace_recovery(DEBUG3));
LWLockRelease(ProcArrayLock);
@@ -2796,6 +2822,15 @@ UnobservedTransactionsPruneXids(TransactionId limitXid)
UnobservedXids = (TransactionId *) &(procArray->procs[procArray->maxProcs]);
+ /*
+ * If there's nothing to do, leave quickly
+ */
+ if (procArray->numUnobservedXids == 0)
+ return;
+
+ /*
+ * If we can remove the whole array in one go, do it
+ */
if (TransactionIdFollowsOrEquals(limitXid, UnobservedXids[procArray->numUnobservedXids]))
{
UnobservedTransactionsClearXids();