Re: Is RecoveryConflictInterrupt() entirely safe in a signal handler?
Michael Paquier <michael@paquier.xyz>
From: Michael Paquier <michael@paquier.xyz>
To: Thomas Munro <thomas.munro@gmail.com>
Cc: Robert Haas <robertmhaas@gmail.com>, Andres Freund <andres@anarazel.de>, Tom Lane <tgl@sss.pgh.pa.us>, pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2022-06-21T07:43:55Z
Lists: pgsql-hackers
On Tue, Jun 21, 2022 at 05:22:05PM +1200, Thomas Munro wrote: > Here's one thing I got a bit confused about along the way, but it > seems the comment was just wrong: > > + /* > + * If we can abort just the current > subtransaction then we are OK > + * to throw an ERROR to resolve the conflict. > Otherwise drop > + * through to the FATAL case. > ... > + if (!IsSubTransaction()) > ... > + ereport(ERROR, > > Surely this was meant to say, "If we're not in a subtransaction then > ...", right? Changed. Indeed, the code does something else than what the comment says, aka generating an ERROR if the process is not in a subtransaction, ignoring already aborted transactions (aborted subtrans go to FATAL) and throwing a FATAL in the other cases. So your change looks right. > I thought of a couple more simplifications for the big switch > statement in ProcessRecoveryConflictInterrupt(). The special case for > DoingCommandRead can be changed to fall through, instead of needing a > separate ereport(FATAL). The extra business with QueryCancelHoldoffCount and DoingCommandRead is the only addition for the snapshot, lock and tablespace conflict handling part. I don't see why a reason why that could be wrong on a close lookup. Anyway, why don't you check QueryCancelPending on top of QueryCancelHoldoffCount? > Now we're down to just one ereport(FATAL), one ereport(ERROR), and a > couple of ways to give up without erroring. I think this makes the > logic a lot easier to follow? Agreed that it looks like a gain in clarity. -- Michael
Commits
-
Fix recovery conflict SIGUSR1 handling.
- 0da096d78e1e 17.0 landed
-
Redesign interrupt/cancel API for regex engine.
- db4f21e4a34b 16.0 landed
-
Update contrib/trgm_regexp's memory management.
- 6db75edb2ecb 16.0 landed
-
Update tsearch regex memory management.
- 4f51429dd7f1 16.0 landed
-
Use MemoryContext API for regex memory management.
- bea3d7e3831f 16.0 landed