diff options
| author | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2010-12-07 09:23:30 +0100 |
|---|---|---|
| committer | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2010-12-07 09:35:14 +0100 |
| commit | 799d0b4b9ede51c629149185e4058c52117cd231 (patch) | |
| tree | e688da8bd83705befabb34f38888e734b9dea87f /src/backend/storage/ipc/standby.c | |
| parent | a65b29794a394afdea78a3ee367ca8fd373788e3 (diff) | |
Fix bugs in the hot standby known-assigned-xids tracking logic. If there's
an old transaction running in the master, and a lot of transactions have
started and finished since, and a WAL-record is written in the gap between
the creating the running-xacts snapshot and WAL-logging it, recovery will fail
with "too many KnownAssignedXids" error. This bug was reported by
Joachim Wieland on Nov 19th.
In the same scenario, when fewer transactions have started so that all the
xids fit in KnownAssignedXids despite the first bug, a more serious bug
arises. We incorrectly initialize the clog code with the oldest still running
transaction, and when we see the WAL record belonging to a transaction with
an XID larger than one that committed already before the checkpoint we're
recovering from, we zero the clog page containing the already committed
transaction, leading to data loss.
In hindsight, trying to track xids in the known-assigned-xids array before
seeing the running-xacts record was too complicated. To fix that, hold
XidGenLock while the running-xacts snapshot is taken and WAL-logged. That
ensures that no transaction can begin or end in that gap, so that in recvoery
we know that the snapshot contains all transactions running at that point in
WAL.
Diffstat (limited to 'src/backend/storage/ipc/standby.c')
| -rw-r--r-- | src/backend/storage/ipc/standby.c | 11 |
1 files changed, 3 insertions, 8 deletions
diff --git a/src/backend/storage/ipc/standby.c b/src/backend/storage/ipc/standby.c index ca094a01b40..2f9fe8ab8eb 100644 --- a/src/backend/storage/ipc/standby.c +++ b/src/backend/storage/ipc/standby.c @@ -671,7 +671,7 @@ StandbyReleaseAllLocks(void) /* * StandbyReleaseOldLocks * Release standby locks held by XIDs < removeXid, as long - * as their not prepared transactions. + * as they're not prepared transactions. */ void StandbyReleaseOldLocks(TransactionId removeXid) @@ -848,14 +848,9 @@ LogStandbySnapshot(TransactionId *oldestActiveXid, TransactionId *nextXid) * record we write, because standby will open up when it sees this. */ running = GetRunningTransactionData(); - - /* - * The gap between GetRunningTransactionData() and - * LogCurrentRunningXacts() is what most of the fuss is about here, so - * artifically extending this interval is a great way to test the little - * used parts of the code. - */ LogCurrentRunningXacts(running); + /* GetRunningTransactionData() acquired XidGenLock, we must release it */ + LWLockRelease(XidGenLock); *oldestActiveXid = running->oldestRunningXid; *nextXid = running->nextXid; |
