amcheck/verify_heapam doesn't check for interrupts

Started by Peter Geogheganover 4 years ago6 messageshackers
Jump to latest

I just noticed that the new heapam amcheck verification code can take
a very long time to respond to cancellations from pg_amcheck -- I saw
that it took over 2 minutes on a large database on my workstation.

It looks like we neglect to call CHECK_FOR_INTERRUPTS() anywhere
inside verify_heapam.c. Is there any reason for this? Can't we just
put a CHECK_FOR_INTERRUPTS() at the top of the outermost loop, inside
verify_heapam()?

Not sure if pg_amcheck itself is a factor here too -- didn't get that far.

Thanks
--
Peter Geoghegan

#2Mark Dilger
mark.dilger@enterprisedb.com
In reply to: Peter Geoghegan (#1)
Re: amcheck/verify_heapam doesn't check for interrupts

On Aug 26, 2021, at 2:38 PM, Peter Geoghegan <pg@bowt.ie> wrote:

It looks like we neglect to call CHECK_FOR_INTERRUPTS() anywhere
inside verify_heapam.c. Is there any reason for this?

Not any good one that I can see.

Can't we just
put a CHECK_FOR_INTERRUPTS() at the top of the outermost loop, inside
verify_heapam()?

I expect we could.

Not sure if pg_amcheck itself is a factor here too -- didn't get that far.

That runs an event loop in the client over multiple checks (heap and/or btree) running in backends, just as reindexdb and vacuumdb do over parallel reindexes and vacuums running in backends. It should be just as safe to ctrl-c out of pg_amcheck as out of those two. They all three use fe_utils/cancel.h's setup_cancel_handler(), so I would expect modifying verify_heapam would be enough.


Mark Dilger
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

In reply to: Mark Dilger (#2)
Re: amcheck/verify_heapam doesn't check for interrupts

On Thu, Aug 26, 2021 at 4:24 PM Mark Dilger
<mark.dilger@enterprisedb.com> wrote:

On Aug 26, 2021, at 2:38 PM, Peter Geoghegan <pg@bowt.ie> wrote:
It looks like we neglect to call CHECK_FOR_INTERRUPTS() anywhere
inside verify_heapam.c. Is there any reason for this?

Not any good one that I can see.

Seems that way. Want to post a patch?

Not sure if pg_amcheck itself is a factor here too -- didn't get that far.

That runs an event loop in the client over multiple checks (heap and/or btree) running in backends, just as reindexdb and vacuumdb do over parallel reindexes and vacuums running in backends. It should be just as safe to ctrl-c out of pg_amcheck as out of those two. They all three use fe_utils/cancel.h's setup_cancel_handler(), so I would expect modifying verify_heapam would be enough.

Right. I checked that out myself, after sending my email from earlier.
We don't have any problems when pg_amcheck happens to be verifying a
B-Tree index -- verify_nbtree.c already has CHECK_FOR_INTERRUPTS() at
a few key points.

--
Peter Geoghegan

#4Mark Dilger
mark.dilger@enterprisedb.com
In reply to: Peter Geoghegan (#3)
Re: amcheck/verify_heapam doesn't check for interrupts

On Aug 26, 2021, at 4:39 PM, Peter Geoghegan <pg@bowt.ie> wrote:

Not any good one that I can see.

Seems that way. Want to post a patch?

Sure. I just posted another unrelated patch for amcheck this morning, so it seems a good day for it :)


Mark Dilger
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

#5Mark Dilger
mark.dilger@enterprisedb.com
In reply to: Mark Dilger (#4)
Re: amcheck/verify_heapam doesn't check for interrupts
Show quoted text

On Aug 26, 2021, at 4:41 PM, Mark Dilger <mark.dilger@enterprisedb.com> wrote:

Seems that way. Want to post a patch?

Sure.

Attachments:

v1-0001-Add-CHECK_FOR_INTERRUPTS-to-verify_heapam.patchapplication/octet-stream; name=v1-0001-Add-CHECK_FOR_INTERRUPTS-to-verify_heapam.patch; x-unix-mode=0644Download+2-1
In reply to: Mark Dilger (#5)
Re: amcheck/verify_heapam doesn't check for interrupts

Patch committed.

Thanks!
--
Peter Geoghegan