LISTEN and "tuple concurrently updated" - Mailing list pgsql-hackers

From Gavin Sherry
Subject LISTEN and "tuple concurrently updated"
Date
Msg-id Pine.LNX.4.58.0309151851410.16678@linuxworld.com.au
Whole thread Raw
Responses Re: LISTEN and "tuple concurrently updated"
Re: LISTEN and "tuple concurrently updated"
List pgsql-hackers
Hi all,

A user on IRC came across the following "tuple concurrently updated" error
when using LISTEN/NOTIFY intensively. The user managed to isolate the
problem and SQL generating the problem. A few sessions are required to
generate the error.

T1:
---
begin;
listen test;
commit;

T2:
---
begin;
notify test;
commit;

T1:
---
begin;
-- got notify
unlisten test;


T3:
---
begin;
notify test;
commit;
-- blocks

T1:
---
commit;

T3 then receives:

WARNING:  AbortTransaction and not in in-progress state
ERROR:  tuple concurrently updated

A brief look into this:

heap_update() in T3 (called by AtCommit_Notify()) calls
HeapTupleSatisfiesUpdate(). This returns HeapTupleBeingUpdated. Once we
issue COMMIT; in T1 updates pg_listen and the tuple T3 is trying to
update no longer exists.

I've attached a patch which solves this problem. Basically, T1 will now
just hold AccessExclusiveLock on pg_listen for the rest of the
transaction. I've also modified AsyncExistsPendingNotify() to step through
pg_listen which allows T3's NOTIFY to block until T1 commits. This is not
really necessary due to the semantics of LISTEN/NOTIFY -- it is not an
error if a record exists in pg_listen already.

Thanks,

Gavin

pgsql-hackers by date:

Previous
From: "Zeugswetter Andreas SB SD"
Date:
Subject: Re: AIX 4.2.1 CVS head and SSL
Next
From: "Andrew Dunstan"
Date:
Subject: Linux memory handling improvement