pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgsql: Fix race condition in preparing a transaction for two-phase comm
6+ messages / 1 participants
[nested] [flat]

* pgsql: Fix race condition in preparing a transaction for two-phase comm
@ 2014-05-15 14:18 Heikki Linnakangas <heikki.linnakangas@iki.fi>
  0 siblings, 0 replies; 6+ messages in thread

From: Heikki Linnakangas @ 2014-05-15 14:18 UTC (permalink / raw)
  To: pgsql-committers

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.

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/bb38fb0d43c8d7ff54072bfd8bd63154e536b384

Modified Files
--------------
src/backend/access/transam/twophase.c |  169 ++++++++++++++++++++++++---------
src/backend/access/transam/xact.c     |   19 +++-
src/include/access/twophase.h         |    3 +
3 files changed, 144 insertions(+), 47 deletions(-)


-- 
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers


^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* pgsql: Fix race condition in preparing a transaction for two-phase comm
@ 2014-05-15 14:18 Heikki Linnakangas <heikki.linnakangas@iki.fi>
  0 siblings, 0 replies; 6+ messages in thread

From: Heikki Linnakangas @ 2014-05-15 14:18 UTC (permalink / raw)
  To: pgsql-committers

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.

Branch
------
REL9_3_STABLE

Details
-------
http://git.postgresql.org/pg/commitdiff/48fc8962f9f1ec456735500795ba894c5da9e89a

Modified Files
--------------
src/backend/access/transam/twophase.c |  169 ++++++++++++++++++++++++---------
src/backend/access/transam/xact.c     |   19 +++-
src/include/access/twophase.h         |    3 +
3 files changed, 144 insertions(+), 47 deletions(-)


-- 
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers


^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* pgsql: Fix race condition in preparing a transaction for two-phase comm
@ 2014-05-15 14:18 Heikki Linnakangas <heikki.linnakangas@iki.fi>
  0 siblings, 0 replies; 6+ messages in thread

From: Heikki Linnakangas @ 2014-05-15 14:18 UTC (permalink / raw)
  To: pgsql-committers

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.

Branch
------
REL9_2_STABLE

Details
-------
http://git.postgresql.org/pg/commitdiff/d8dbeb048287f478f11eeab005ddd1e9df65a4d9

Modified Files
--------------
src/backend/access/transam/twophase.c |  169 ++++++++++++++++++++++++---------
src/backend/access/transam/xact.c     |   19 +++-
src/include/access/twophase.h         |    3 +
3 files changed, 144 insertions(+), 47 deletions(-)


-- 
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers


^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* pgsql: Fix race condition in preparing a transaction for two-phase comm
@ 2014-05-15 14:18 Heikki Linnakangas <heikki.linnakangas@iki.fi>
  0 siblings, 0 replies; 6+ messages in thread

From: Heikki Linnakangas @ 2014-05-15 14:18 UTC (permalink / raw)
  To: pgsql-committers

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.

Branch
------
REL9_1_STABLE

Details
-------
http://git.postgresql.org/pg/commitdiff/8c19b807c49aaaa18d1a166df5649ec2c04df320

Modified Files
--------------
src/backend/access/transam/twophase.c |  169 ++++++++++++++++++++++++---------
src/backend/access/transam/xact.c     |   19 +++-
src/include/access/twophase.h         |    3 +
3 files changed, 144 insertions(+), 47 deletions(-)


-- 
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers


^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* pgsql: Fix race condition in preparing a transaction for two-phase comm
@ 2014-05-15 14:18 Heikki Linnakangas <heikki.linnakangas@iki.fi>
  0 siblings, 0 replies; 6+ messages in thread

From: Heikki Linnakangas @ 2014-05-15 14:18 UTC (permalink / raw)
  To: pgsql-committers

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.

Branch
------
REL9_0_STABLE

Details
-------
http://git.postgresql.org/pg/commitdiff/82a83ec6841dc598af5a47a45989fd969e3099a5

Modified Files
--------------
src/backend/access/transam/twophase.c |  169 ++++++++++++++++++++++++---------
src/backend/access/transam/xact.c     |   19 +++-
src/include/access/twophase.h         |    3 +
3 files changed, 144 insertions(+), 47 deletions(-)


-- 
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers


^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* pgsql: Fix race condition in preparing a transaction for two-phase comm
@ 2014-05-15 14:18 Heikki Linnakangas <heikki.linnakangas@iki.fi>
  0 siblings, 0 replies; 6+ messages in thread

From: Heikki Linnakangas @ 2014-05-15 14:18 UTC (permalink / raw)
  To: pgsql-committers

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.

Branch
------
REL8_4_STABLE

Details
-------
http://git.postgresql.org/pg/commitdiff/045fbbdc4495aa38dcf36b37ae6db5b50d5e5c3a

Modified Files
--------------
src/backend/access/transam/twophase.c |  169 ++++++++++++++++++++++++---------
src/backend/access/transam/xact.c     |   19 +++-
src/include/access/twophase.h         |    3 +
3 files changed, 144 insertions(+), 47 deletions(-)


-- 
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers


^ permalink  raw  reply  [nested|flat] 6+ messages in thread


end of thread, other threads:[~2014-05-15 14:18 UTC | newest]

Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2014-05-15 14:18 pgsql: Fix race condition in preparing a transaction for two-phase comm Heikki Linnakangas <heikki.linnakangas@iki.fi>
2014-05-15 14:18 pgsql: Fix race condition in preparing a transaction for two-phase comm Heikki Linnakangas <heikki.linnakangas@iki.fi>
2014-05-15 14:18 pgsql: Fix race condition in preparing a transaction for two-phase comm Heikki Linnakangas <heikki.linnakangas@iki.fi>
2014-05-15 14:18 pgsql: Fix race condition in preparing a transaction for two-phase comm Heikki Linnakangas <heikki.linnakangas@iki.fi>
2014-05-15 14:18 pgsql: Fix race condition in preparing a transaction for two-phase comm Heikki Linnakangas <heikki.linnakangas@iki.fi>
2014-05-15 14:18 pgsql: Fix race condition in preparing a transaction for two-phase comm Heikki Linnakangas <heikki.linnakangas@iki.fi>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox