On 10 September 2014 14:47, Alvaro Herrera <alvherre@2ndquadrant.com> wrote:
> Thomas Munro wrote:
>
>> @@ -2022,7 +2030,7 @@ EvalPlanQualFetch(EState *estate, Relation relation, int lockmode, bool noWait,
>> */
>> test = heap_lock_tuple(relation, &tuple,
>> estate->es_output_cid,
>> - lockmode, noWait,
>> + lockmode, wait_policy,
>> false, &buffer, &hufd);
>> /* We now have two pins on the buffer, get rid of one */
>> ReleaseBuffer(buffer);
>
> Doesn't this heap_lock_tuple() need to check for a WouldBlock result?
> Not sure that this is the same case that you were trying to test in
> heap_lock_updated_tuple; I think this requires an update chain (so that
> EPQFetch is invoked) and some tuple later in the chain is locked by a
> third transaction.
You're right, that case was clearly lacking. The new patch, attached,
releases the buffer and returns NULL in that case. But I have no idea
how to reach it in an isolation test! skip-locked-4.spec gets pretty
close, it creates the right kind of update chain to get into
EvalPlanQualFetch and then enter the conditional block beginning:
if (TransactionIdIsValid(SnapshotDirty.xmax))
But to reach the case you mentioned, it would need to get past that
(xmax is not a valid transaction) but then the tuple would need to be
locked by another session before heap_lock_tuple is called a few lines
below. That's a race scenario that I don't believe we can create
using advisory lock tricks in an isolation test.
> I attach some additional minor suggestions to your patch. Please feel
> free to reword comments differently if you think my wording isn't an
> improvements (or I've maked an english mistakes).
Thanks, these are incorporated in the new version (also rebased).
Best regards,
Thomas Munro