diff options
author | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2014-05-15 16:37:50 +0300 |
---|---|---|
committer | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2014-05-15 17:03:08 +0300 |
commit | 8c19b807c49aaaa18d1a166df5649ec2c04df320 (patch) | |
tree | a514a26718fa983e430b2c61e000209bd413447c /src/include/access/twophase.h | |
parent | 360ec00a57964ce27c4ee064b7313d55dbf2fb9f (diff) | |
download | postgresql-8c19b807c49aaaa18d1a166df5649ec2c04df320.tar.gz postgresql-8c19b807c49aaaa18d1a166df5649ec2c04df320.zip |
Fix race condition in preparing a transaction for two-phase commit.
To lock a prepared transaction's shared memory entry, we used to mark it
with the XID of the backend. When the XID was no longer active according
to the proc array, the entry was implicitly considered as not locked
anymore. However, when preparing a transaction, the backend's proc array
entry was cleared before transfering the locks (and some other state) to
the prepared transaction's dummy PGPROC entry, so there was a window where
another backend could finish the transaction before it was in fact fully
prepared.
To fix, rewrite the locking mechanism of global transaction entries. Instead
of an XID, just have simple locked-or-not flag in each entry (we store the
locking backend's backend id rather than a simple boolean, but that's just
for debugging purposes). The backend is responsible for explicitly unlocking
the entry, and to make sure that that happens, install a callback to unlock
it on abort or process exit.
Backpatch to all supported versions.
Diffstat (limited to 'src/include/access/twophase.h')
-rw-r--r-- | src/include/access/twophase.h | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/src/include/access/twophase.h b/src/include/access/twophase.h index 799bf8bf38e..25ec622f4fd 100644 --- a/src/include/access/twophase.h +++ b/src/include/access/twophase.h @@ -31,6 +31,9 @@ extern int max_prepared_xacts; extern Size TwoPhaseShmemSize(void); extern void TwoPhaseShmemInit(void); +extern void AtAbort_Twophase(void); +extern void PostPrepare_Twophase(void); + extern PGPROC *TwoPhaseGetDummyProc(TransactionId xid); extern BackendId TwoPhaseGetDummyBackendId(TransactionId xid); |