diff options
author | Simon Riggs | 2009-02-25 15:18:02 +0000 |
---|---|---|
committer | Simon Riggs | 2009-02-25 15:18:02 +0000 |
commit | f177ba34ad0f842e8592527a51c78a913df11f9e (patch) | |
tree | d06d2b6698d98e94d86d12d6eecbc07208ee7362 | |
parent | 6e52f2d4e02327f4546d8a407b73790aad987276 (diff) |
Improve sweep away of stale recovery procs, tune prune unobservedxids and use some more informative debug messages.dev_hot_standby
-rw-r--r-- | src/backend/storage/ipc/procarray.c | 51 |
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(); |