From: | Kevin Grittner <kgrittn(at)postgresql(dot)org> |
---|---|
To: | pgsql-committers(at)postgresql(dot)org |
Subject: | pgsql: Fix serialization anomalies due to race conditions on INSERT. |
Date: | 2015-10-31 19:50:14 |
Message-ID: | E1ZscAI-0001R5-4Z@gemulon.postgresql.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-committers |
Fix serialization anomalies due to race conditions on INSERT.
On insert the CheckForSerializableConflictIn() test was performed
before the page(s) which were going to be modified had been locked
(with an exclusive buffer content lock). If another process
acquired a relation SIReadLock on the heap and scanned to a page on
which an insert was going to occur before the page was so locked,
a rw-conflict would be missed, which could allow a serialization
anomaly to be missed. The window between the check and the page
lock was small, so the bug was generally not noticed unless there
was high concurrency with multiple processes inserting into the
same table.
This was reported by Peter Bailis as bug #11732, by Sean Chittenden
as bug #13667, and by others.
The race condition was eliminated in heap_insert() by moving the
check down below the acquisition of the buffer lock, which had been
the very next statement. Because of the loop locking and unlocking
multiple buffers in heap_multi_insert() a check was added after all
inserts were completed. The check before the start of the inserts
was left because it might avoid a large amount of work to detect a
serialization anomaly before performing the all of the inserts and
the related WAL logging.
While investigating this bug, other SSI bugs which were even harder
to hit in practice were noticed and fixed, an unnecessary check
(covered by another check, so redundant) was removed from
heap_update(), and comments were improved.
Back-patch to all supported branches.
Kevin Grittner and Thomas Munro
Branch
------
REL9_3_STABLE
Details
-------
http://git.postgresql.org/pg/commitdiff/18479293cbc531209dbdf68f94cd7f86b5290a80
Modified Files
--------------
src/backend/access/heap/heapam.c | 91 ++++++++++++++++++++++++----------
src/backend/storage/lmgr/predicate.c | 9 ++--
2 files changed, 69 insertions(+), 31 deletions(-)
From | Date | Subject | |
---|---|---|---|
Next Message | Kevin Grittner | 2015-11-02 12:30:07 | pgsql: Add RMV to list of commands taking AE lock. |
Previous Message | Tom Lane | 2015-10-30 23:14:38 | pgsql: Implement lookbehind constraints in our regular-expression engin |