Re: Injection points: some tools to wait and wake

From: "Andrey M(dot) Borodin" <x4mmm(at)yandex-team(dot)ru>
To: Michael Paquier <michael(at)paquier(dot)xyz>
Cc: Postgres hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Ashutosh Bapat <ashutosh(dot)bapat(at)gmail(dot)com>
Subject: Re: Injection points: some tools to wait and wake
Date: 2024-02-20 14:32:38
Message-ID: 48FBD260-D49D-43CA-B05D-BBB03235236E@yandex-team.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> On 20 Feb 2024, at 02:21, Michael Paquier <michael(at)paquier(dot)xyz> wrote:
>
> On Mon, Feb 19, 2024 at 11:54:20AM +0300, Andrey M. Borodin wrote:
>> 1. injection_points_wake() will wake all of waiters. But it's not
>> suitable for complex tests. I think there must be a way to wake only
>> specific waiter by injection point name.
>
> I don't disagree with that, but I don't have a strong argument for
> implementing that until there is an explicit need for it in core. It
> is also possible to plug in your own module, outside of core, if you
> are looking for something more specific. The backend APIs allow that.

In [0] I want to create a test for edge case of reading recent multixact. External module does not allow to have a test within repository.
In that test I need to sync backends in 3 steps (backend 1 starts to wait in injection point, backend 2 starts to sleep in other point, backend 1 is released and observe 3rd injection point). "wake them all" implementation allows only 2-step synchronization.
I will try to simplify test to 2-step, but it would be much easier to implement if injection points could be awaken independently.

>> 2. Alexander Korotkov's stopevents could be used in isolation
>> tests. This kind of tests is perfect for describing complex race
>> conditions. (as a side note, I'd be happy if we could have
>> primary\standby in isolation tests too)
>
> This requires plugging is more into src/test/isolation/, with multiple
> connection strings. This has been suggested in the past.

I think standby isolation tests are just a sugar-on-top feature here.
Wrt injection points, I'd like to see a function to wait until some injection point is observed.
With this function at hand developer can implement race condition tests as an isolation test.

>> 5. In many cases we need to have injection point under critical
>> section. I propose to have a "prepared injection point". See [0] for
>> example in v2-0003-Test-multixact-CV-sleep.patch
>> + INJECTION_POINT_PREPARE("GetNewMultiXactId-done");
>> +
>> START_CRIT_SECTION();
>>
>> + INJECTION_POINT_RUN_PREPARED();
>
> I don't see how that's different from a wait/wake logic? The only
> thing you've changed is to stop a wait when a point is detached and
> you want to make the stop conditional. Plugging in a condition
> variable is more flexible than a hardcoded sleep in terms of wait,
> while being more responsive.

No, "prepared injection point" is not about wait\wake logic. It's about having injection point in critical section.
Normal injection point will pstrdup(name) and fail. In [0] I need a test that waits after multixact generation before WAL-logging it. It's only possible in a critical section.

Thanks!

Best regards, Andrey Borodin.

[0] https://www.postgresql.org/message-id/0925F9A9-4D53-4B27-A87E-3D83A757B0E0@yandex-team.ru

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Fabrice Chapuis 2024-02-20 14:44:47 pg_restore problem to load constraints with tables
Previous Message Robert Haas 2024-02-20 14:26:10 Re: Have pg_basebackup write "dbname" in "primary_conninfo"?