pgsql: Grab heavyweight tuple lock only before sleeping

Поиск
Список
Период
Сортировка
От Alvaro Herrera
Тема pgsql: Grab heavyweight tuple lock only before sleeping
Дата
Msg-id E1Y4Y9y-0003hz-Ml@gemulon.postgresql.org
обсуждение исходный текст
Список pgsql-committers
Grab heavyweight tuple lock only before sleeping

We were trying to acquire the lock even when we were subsequently
not sleeping in some other transaction, which opens us up unnecessarily
to deadlocks.  In particular, this is troublesome if an update tries to
lock an updated version of a tuple and finds itself doing EvalPlanQual
update chain walking; more than two sessions doing this concurrently
will find themselves sleeping on each other because the HW tuple lock
acquisition in heap_lock_tuple called from EvalPlanQualFetch races with
the same tuple lock being acquired in heap_update -- one of these
sessions sleeps on the other one to finish while holding the tuple lock,
and the other one sleeps on the tuple lock.

Per trouble report from Andrew Sackville-West in
http://www.postgresql.org/message-id/20140731233051.GN17765@andrew-ThinkPad-X230

His scenario can be simplified down to a relatively simple
isolationtester spec file which I don't include in this commit; the
reason is that the current isolationtester is not able to deal with more
than one blocked session concurrently and it blocks instead of raising
the expected deadlock.  In the future, if we improve isolationtester, it
would be good to include the spec file in the isolation schedule.  I
posted it in
http://www.postgresql.org/message-id/20141212205254.GC1768@alvh.no-ip.org

Hat tip to Mark Kirkwood, who helped diagnose the trouble.

Branch
------
REL9_3_STABLE

Details
-------
http://git.postgresql.org/pg/commitdiff/048912386da00d7325e6563875864cf711cc97a5

Modified Files
--------------
src/backend/access/heap/heapam.c |  241 +++++++++++++++++++++++---------------
1 file changed, 144 insertions(+), 97 deletions(-)


В списке pgsql-committers по дате отправления:

Предыдущее
От: Alvaro Herrera
Дата:
Сообщение: pgsql: Grab heavyweight tuple lock only before sleeping
Следующее
От: Alvaro Herrera
Дата:
Сообщение: pgsql: Restrict name list len for domain constraints