Re: regression, deadlock in high frequency single-row UPDATE

From: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
To: Mark Kirkwood <mark(dot)kirkwood(at)catalyst(dot)net(dot)nz>
Cc: Andrew Sackville-West <awest(at)janrain(dot)com>, pgsql-bugs(at)postgresql(dot)org, Paulo Tanimoto <paulo(at)janrain(dot)com>
Subject: Re: regression, deadlock in high frequency single-row UPDATE
Date: 2014-12-11 17:22:56
Message-ID: 20141211172256.GB20615@alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Alvaro Herrera wrote:

> I'm going to experiment with that idea and see if it leads to a
> solution. I tried the other idea yesterday (to keep the HW tuple lock
> we acquire in heap_lock_tuple until heap_update is done) but aside from
> being very complicated and bug-prone, it doesn't solve the problem
> anyway.

Here's a preliminary patch. It does solve the deadlock in my simplified
test case. If Andrew can confirm that it fixes his original problem
too, that'd be good.

Before this can be committed I need an isolationtester spec file that
reproduces the problem. Now that I understand why it happens it should
be easy to produce: just have a transaction that does BEGIN, then the
insert, and keeps the transaction open; enough other sessions run the
UPDATE until the problem pops up. (Also, comments on
Would_MultiXactIdWait_Block need work.)

FWIW this code should also have slightly better performance than the
original coding, since the heavyweight tuple lock acquisition is skipped
in some cases. Not sure if that is measurable, though. Maybe in
extreme cases such as the one in #8470 ...

--
Álvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

Attachment Content-Type Size
deadlock.patch text/x-diff 9.2 KB

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Alvaro Herrera 2014-12-11 17:32:37 Re: BUG #12204: Getting wrong results from full text search
Previous Message prasanna 2014-12-11 14:13:51 BUG #12205: Getting wrong results from full text search