Re: Adding a test for speculative insert abort case

From: Ashwin Agrawal <aagrawal(at)pivotal(dot)io>
To: Melanie Plageman <melanieplageman(at)gmail(dot)com>
Cc: Andres Freund <andres(at)anarazel(dot)de>, Pg Hackers <pgsql-hackers(at)postgresql(dot)org>, Peter Geoghegan <pg(at)bowt(dot)ie>
Subject: Re: Adding a test for speculative insert abort case
Date: 2019-05-16 05:32:34
Message-ID: CALfoeit9pmLuJ2LprVfGmfzPL_3sD-_jByU6Xgj_Gbo=O5DgBw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, May 15, 2019 at 8:36 PM Melanie Plageman <melanieplageman(at)gmail(dot)com>
wrote:

>
> On Wed, May 15, 2019 at 6:50 PM Andres Freund <andres(at)anarazel(dot)de> wrote:
>
>>
>> > I noticed that there is not a test case which would cover the
>> speculative
>> > wait
>> > codepath. This seems much more challenging, however, it does seem like a
>> > worthwhile test to have.
>>
>> Shouldn't be that hard to create, I think. I think acquiring another
>> lock in a second, non-unique, expression index, ought to do the trick?
>> It probably has to be created after the unique index (so it's later in
>> the
>>
>> I would think that the sequence would be s1 and s2 probe the index, s1
> and s2
> insert into the table, s1 updates the index but does not complete the
> speculative insert and clear the token (pause before
> table_complete_speculative). s2 is in speculative wait when attempting to
> update
> the index.
>
> Something like
>
> permutation
> "controller_locks"
> "controller_show"
> "s1_upsert" "s2_upsert"
> "controller_show"
> "controller_unlock_1_1" "controller_unlock_2_1"
> "controller_unlock_1_3" "controller_unlock_2_3"
> "controller_unlock_1_2"
> "s1_magically_pause_before_complete_speculative"
> # put s2 in speculative wait
> "controller_unlock_2_2"
> "s1_magically_unpause_before_complete_speculative"
>
> So, how would another lock on another index keep s1 from clearing the
> speculative token after it has updated the index?
>

The second index would help to hold the session after inserting the tuple
in unique index but before completing the speculative insert. Hence, helps
to create the condition easily. I believe order of index insertion is
helping here that unique index is inserted and then non-unique index is
inserted too.

Attaching patch with the test using the idea Andres mentioned and it works
to excercise the speculative wait.

Attachment Content-Type Size
0001-Add-test-to-validate-speculative-wait-is-performed.patch text/x-patch 7.1 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Ashwin Agrawal 2019-05-16 06:00:38 Re: Pluggable Storage - Andres's take
Previous Message Andres Freund 2019-05-16 03:46:37 Re: Adding a test for speculative insert abort case