Restart pg_usleep when interrupted - Mailing list pgsql-hackers

From Imseih (AWS), Sami
Subject Restart pg_usleep when interrupted
Date
Msg-id 01000190606e3d2a-116ead16-84d2-4449-8d18-5053da66b1f4-000000@email.amazonses.com
Whole thread Raw
Responses Re: Restart pg_usleep when interrupted  (Robert Haas <robertmhaas@gmail.com>)
List pgsql-hackers

Hi,

 

In the proposal by Bertrand [1] to implement vacuum cost delay tracking

in pg_stat_progress_vacuum, it was discovered that the vacuum cost delay

ends early on the leader process of a parallel vacuum due to parallel workers

reporting progress on index vacuuming, which was introduced in 17

with commit [2]. With this patch, everytime a parallel worker

completes a vacuum index, it will send a completion message to the leader.

 

The facility that allows a parallel worker to report progress to the leader was

introduced in commit [3].

 

In the case of the patch being proposed by Bertrand, the number of interrupts

will be much more frequent as parallel workers would send a message to the leader

to update the vacuum delay counters every vacuum_delay_point call.

 

Looking into this, the ideal solution appears to provide the ability for a pg_usleep

call to restart after being interrupted. Thanks to the usage of nanosleep as

of commit[4], this should be trivial to do as nanosleep

provides a remaining time, which can be used to restart the sleep. This

idea was also mentioned in [5].

 

I am attaching a POC patch that does the $SUBJECT. Rather than changing the

existing pg_usleep, the patch introduces a function, pg_usleep_handle_interrupt,

that takes in the sleep duration and a boolean flag to force handling of the

interrupt, or not.

 

This function can replace pg_usleep inside vacuum_delay_point, and could be

useful in other cases in which it’s important to handle interrupts.

 

For Windows, the “force” = “true” flag of the new function uses SleepEx which

from what I can tell based on the code comments is a non-interruptible sleep.

 

Thoughts?

 

[1] https://www.postgresql.org/message-id/ZnbIIUQpFJKAJx2W%40ip-10-97-1-34.eu-west-3.compute.internal

[2] https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=46ebdfe164c61fbac961d1eb7f40e9a684289ae6

[3] https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=f1889729dd3ab0352dc0ccc2ffcc1b1901f8e39f

[4] https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=a948e49e2ef11815be0b211723bfc5b53b7f75a8

[5] https://www.postgresql.org/message-id/24848.1473607575%40sss.pgh.pa.us

 

 

Regards,

 

Sami Imseih

Amazon Web Services (AWS)

 

 

 

 

 

pgsql-hackers by date:

Previous
From: Peter Eisentraut
Date:
Subject: Re: Converting README documentation to Markdown
Next
From: "Imseih (AWS), Sami"
Date:
Subject: Re: Track the amount of time waiting due to cost_delay