Re: Race condition between PREPARE TRANSACTION and COMMIT PREPARED (was Re: [HACKERS] Problem with txid_snapshot_in/out() functionality)

2014-05-15 Thread Robert Haas
On Thu, May 15, 2014 at 10:38 AM, Andres Freund wrote: >> . async.c and namespace.c does the same, and it hasn't been a >> problem. > > Well, it doesn't seem unreasonable to have C code using > PG_ENSURE_ERROR_CLEANUP/PG_END_ENSURE_ERROR_CLEANUP around a 2pc commit > to me. That'll break with this

Re: Race condition between PREPARE TRANSACTION and COMMIT PREPARED (was Re: [HACKERS] Problem with txid_snapshot_in/out() functionality)

2014-05-15 Thread Andres Freund
On 2014-05-15 17:21:28 +0300, Heikki Linnakangas wrote: > >Is it guaranteed that all paths have called LWLockReleaseAll() > >before calling the proc exit hooks? Otherwise we might end up waiting > >for ourselves... > > Hmm. AbortTransaction() will release locks before we get here, but the > before

Re: Race condition between PREPARE TRANSACTION and COMMIT PREPARED (was Re: [HACKERS] Problem with txid_snapshot_in/out() functionality)

2014-05-15 Thread Heikki Linnakangas
On 05/06/2014 02:44 PM, Andres Freund wrote: On 2014-05-05 13:41:00 +0300, Heikki Linnakangas wrote: +/* + * Exit hook to unlock the global transaction entry we're working on. + */ +static void +AtProcExit_Twophase(int code, Datum arg) +{ + /* same logic as abort */ + AtAbort_Twophas

Re: Race condition between PREPARE TRANSACTION and COMMIT PREPARED (was Re: [HACKERS] Problem with txid_snapshot_in/out() functionality)

2014-05-06 Thread Andres Freund
Hi, On 2014-05-05 13:41:00 +0300, Heikki Linnakangas wrote: > I came up with the attached fix for this. Currently, the entry is implicitly > considered dead or unlocked if the locking_xid transaction is no longer > active, but this patch essentially turns locking_xid into a simple boolean, > and m

Re: Race condition between PREPARE TRANSACTION and COMMIT PREPARED (was Re: [HACKERS] Problem with txid_snapshot_in/out() functionality)

2014-05-05 Thread Heikki Linnakangas
On 04/14/2014 09:48 PM, Heikki Linnakangas wrote: On 04/14/2014 07:51 PM, Tom Lane wrote: I'd prefer to leave the prepare sequence alone and instead find a way to reject COMMIT PREPARED until after the source transaction is safely clear of the race conditions. The upthread idea of looking at vx

Re: Race condition between PREPARE TRANSACTION and COMMIT PREPARED (was Re: [HACKERS] Problem with txid_snapshot_in/out() functionality)

2014-04-14 Thread Heikki Linnakangas
On 04/14/2014 07:51 PM, Tom Lane wrote: I'd prefer to leave the prepare sequence alone and instead find a way to reject COMMIT PREPARED until after the source transaction is safely clear of the race conditions. The upthread idea of looking at vxid instead of xid might help, except that I see we

Re: Race condition between PREPARE TRANSACTION and COMMIT PREPARED (was Re: [HACKERS] Problem with txid_snapshot_in/out() functionality)

2014-04-14 Thread Andres Freund
On 2014-04-14 13:47:35 -0400, Tom Lane wrote: > Andres Freund writes: > > I wonder if the most natural way to express this wouldn't be to have a > > heavyweight lock for every 2pc xact > > 'slot'. ResourceOwnerRelease(RESOURCE_RELEASE_LOCKS) should be scheduled > > correctly to make error handling

Re: Race condition between PREPARE TRANSACTION and COMMIT PREPARED (was Re: [HACKERS] Problem with txid_snapshot_in/out() functionality)

2014-04-14 Thread Tom Lane
Andres Freund writes: > I wonder if the most natural way to express this wouldn't be to have a > heavyweight lock for every 2pc xact > 'slot'. ResourceOwnerRelease(RESOURCE_RELEASE_LOCKS) should be scheduled > correctly to make error handling for this work. That seems like not a bad idea. Could

Re: Race condition between PREPARE TRANSACTION and COMMIT PREPARED (was Re: [HACKERS] Problem with txid_snapshot_in/out() functionality)

2014-04-14 Thread Andres Freund
On 2014-04-14 12:51:02 -0400, Tom Lane wrote: > The whole thing feels like we are solving the wrong problem, anyway. > IIUC, the complaint arises because we are allowing COMMIT PREPARED > to occur before the source transaction has reported successful prepare > to its client. Surely that does not n

Re: Race condition between PREPARE TRANSACTION and COMMIT PREPARED (was Re: [HACKERS] Problem with txid_snapshot_in/out() functionality)

2014-04-14 Thread Tom Lane
Heikki Linnakangas writes: >> I think we'll need to transfer of the locks earlier, before the >> transaction is marked as fully prepared. I'll take a closer look at this >> tomorrow. > Here's a patch to do that. It's very straightforward, I just moved the > calls to transfer locks earlier, befor

Re: Race condition between PREPARE TRANSACTION and COMMIT PREPARED (was Re: [HACKERS] Problem with txid_snapshot_in/out() functionality)

2014-04-14 Thread Heikki Linnakangas
On 04/13/2014 11:39 PM, Heikki Linnakangas wrote: However, I just noticed that there's a race condition between PREPARE TRANSACTION and COMMIT/ROLLBACK PREPARED. PostPrepare_Locks runs after the prepared transaction is already marked as fully prepared. That means that by the time we get to PostPr

Race condition between PREPARE TRANSACTION and COMMIT PREPARED (was Re: [HACKERS] Problem with txid_snapshot_in/out() functionality)

2014-04-13 Thread Heikki Linnakangas
On 04/12/2014 05:03 PM, Andres Freund wrote: >If we don't, aren't we letting other backends see non-self-consistent >state in regards to who holds which locks, for example? I think that actually works out ok, because the locks aren't owned by xids/xacts, but procs. Otherwise we'd be in deep trou