Commit 2505ce0b authored by Andres Freund's avatar Andres Freund

Remove remnants of ImmediateInterruptOK handling.

Now that nothing sets ImmediateInterruptOK to true anymore, we can
remove all the supporting code.

Reviewed-By: Heikki Linnakangas
parent d0699571
...@@ -165,8 +165,6 @@ proc_exit_prepare(int code) ...@@ -165,8 +165,6 @@ proc_exit_prepare(int code)
InterruptPending = false; InterruptPending = false;
ProcDiePending = false; ProcDiePending = false;
QueryCancelPending = false; QueryCancelPending = false;
/* And let's just make *sure* we're not interrupted ... */
ImmediateInterruptOK = false;
InterruptHoldoffCount = 1; InterruptHoldoffCount = 1;
CritSectionCount = 0; CritSectionCount = 0;
......
...@@ -2648,13 +2648,6 @@ die(SIGNAL_ARGS) ...@@ -2648,13 +2648,6 @@ die(SIGNAL_ARGS)
{ {
InterruptPending = true; InterruptPending = true;
ProcDiePending = true; ProcDiePending = true;
/*
* If we're waiting for input or a lock so that it's safe to
* interrupt, service the interrupt immediately
*/
if (ImmediateInterruptOK)
ProcessInterrupts();
} }
/* If we're still here, waken anything waiting on the process latch */ /* If we're still here, waken anything waiting on the process latch */
...@@ -2688,13 +2681,6 @@ StatementCancelHandler(SIGNAL_ARGS) ...@@ -2688,13 +2681,6 @@ StatementCancelHandler(SIGNAL_ARGS)
{ {
InterruptPending = true; InterruptPending = true;
QueryCancelPending = true; QueryCancelPending = true;
/*
* If we're waiting for input or a lock so that it's safe to
* interrupt, service the interrupt immediately
*/
if (ImmediateInterruptOK)
ProcessInterrupts();
} }
/* If we're still here, waken anything waiting on the process latch */ /* If we're still here, waken anything waiting on the process latch */
...@@ -2835,13 +2821,6 @@ RecoveryConflictInterrupt(ProcSignalReason reason) ...@@ -2835,13 +2821,6 @@ RecoveryConflictInterrupt(ProcSignalReason reason)
*/ */
if (reason == PROCSIG_RECOVERY_CONFLICT_DATABASE) if (reason == PROCSIG_RECOVERY_CONFLICT_DATABASE)
RecoveryConflictRetryable = false; RecoveryConflictRetryable = false;
/*
* If we're waiting for input or a lock so that it's safe to
* interrupt, service the interrupt immediately.
*/
if (ImmediateInterruptOK)
ProcessInterrupts();
} }
/* /*
...@@ -2875,7 +2854,6 @@ ProcessInterrupts(void) ...@@ -2875,7 +2854,6 @@ ProcessInterrupts(void)
{ {
ProcDiePending = false; ProcDiePending = false;
QueryCancelPending = false; /* ProcDie trumps QueryCancel */ QueryCancelPending = false; /* ProcDie trumps QueryCancel */
ImmediateInterruptOK = false; /* not idle anymore */
LockErrorCleanup(); LockErrorCleanup();
/* As in quickdie, don't risk sending to client during auth */ /* As in quickdie, don't risk sending to client during auth */
if (ClientAuthInProgress && whereToSendOutput == DestRemote) if (ClientAuthInProgress && whereToSendOutput == DestRemote)
...@@ -2914,7 +2892,6 @@ ProcessInterrupts(void) ...@@ -2914,7 +2892,6 @@ ProcessInterrupts(void)
if (ClientConnectionLost) if (ClientConnectionLost)
{ {
QueryCancelPending = false; /* lost connection trumps QueryCancel */ QueryCancelPending = false; /* lost connection trumps QueryCancel */
ImmediateInterruptOK = false; /* not idle anymore */
LockErrorCleanup(); LockErrorCleanup();
/* don't send to client, we already know the connection to be dead. */ /* don't send to client, we already know the connection to be dead. */
whereToSendOutput = DestNone; whereToSendOutput = DestNone;
...@@ -2932,7 +2909,6 @@ ProcessInterrupts(void) ...@@ -2932,7 +2909,6 @@ ProcessInterrupts(void)
if (RecoveryConflictPending && DoingCommandRead) if (RecoveryConflictPending && DoingCommandRead)
{ {
QueryCancelPending = false; /* this trumps QueryCancel */ QueryCancelPending = false; /* this trumps QueryCancel */
ImmediateInterruptOK = false; /* not idle anymore */
RecoveryConflictPending = false; RecoveryConflictPending = false;
LockErrorCleanup(); LockErrorCleanup();
pgstat_report_recovery_conflict(RecoveryConflictReason); pgstat_report_recovery_conflict(RecoveryConflictReason);
...@@ -2970,7 +2946,6 @@ ProcessInterrupts(void) ...@@ -2970,7 +2946,6 @@ ProcessInterrupts(void)
*/ */
if (get_timeout_indicator(LOCK_TIMEOUT, true)) if (get_timeout_indicator(LOCK_TIMEOUT, true))
{ {
ImmediateInterruptOK = false; /* not idle anymore */
(void) get_timeout_indicator(STATEMENT_TIMEOUT, true); (void) get_timeout_indicator(STATEMENT_TIMEOUT, true);
LockErrorCleanup(); LockErrorCleanup();
ereport(ERROR, ereport(ERROR,
...@@ -2979,7 +2954,6 @@ ProcessInterrupts(void) ...@@ -2979,7 +2954,6 @@ ProcessInterrupts(void)
} }
if (get_timeout_indicator(STATEMENT_TIMEOUT, true)) if (get_timeout_indicator(STATEMENT_TIMEOUT, true))
{ {
ImmediateInterruptOK = false; /* not idle anymore */
LockErrorCleanup(); LockErrorCleanup();
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_QUERY_CANCELED), (errcode(ERRCODE_QUERY_CANCELED),
...@@ -2987,7 +2961,6 @@ ProcessInterrupts(void) ...@@ -2987,7 +2961,6 @@ ProcessInterrupts(void)
} }
if (IsAutoVacuumWorkerProcess()) if (IsAutoVacuumWorkerProcess())
{ {
ImmediateInterruptOK = false; /* not idle anymore */
LockErrorCleanup(); LockErrorCleanup();
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_QUERY_CANCELED), (errcode(ERRCODE_QUERY_CANCELED),
...@@ -2995,7 +2968,6 @@ ProcessInterrupts(void) ...@@ -2995,7 +2968,6 @@ ProcessInterrupts(void)
} }
if (RecoveryConflictPending) if (RecoveryConflictPending)
{ {
ImmediateInterruptOK = false; /* not idle anymore */
RecoveryConflictPending = false; RecoveryConflictPending = false;
LockErrorCleanup(); LockErrorCleanup();
pgstat_report_recovery_conflict(RecoveryConflictReason); pgstat_report_recovery_conflict(RecoveryConflictReason);
...@@ -3012,7 +2984,6 @@ ProcessInterrupts(void) ...@@ -3012,7 +2984,6 @@ ProcessInterrupts(void)
*/ */
if (!DoingCommandRead) if (!DoingCommandRead)
{ {
ImmediateInterruptOK = false; /* not idle anymore */
LockErrorCleanup(); LockErrorCleanup();
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_QUERY_CANCELED), (errcode(ERRCODE_QUERY_CANCELED),
......
...@@ -412,7 +412,6 @@ errfinish(int dummy,...) ...@@ -412,7 +412,6 @@ errfinish(int dummy,...)
{ {
ErrorData *edata = &errordata[errordata_stack_depth]; ErrorData *edata = &errordata[errordata_stack_depth];
int elevel; int elevel;
bool save_ImmediateInterruptOK;
MemoryContext oldcontext; MemoryContext oldcontext;
ErrorContextCallback *econtext; ErrorContextCallback *econtext;
...@@ -420,18 +419,6 @@ errfinish(int dummy,...) ...@@ -420,18 +419,6 @@ errfinish(int dummy,...)
CHECK_STACK_DEPTH(); CHECK_STACK_DEPTH();
elevel = edata->elevel; elevel = edata->elevel;
/*
* Ensure we can't get interrupted while performing error reporting. This
* is needed to prevent recursive entry to functions like syslog(), which
* may not be re-entrant.
*
* Note: other places that save-and-clear ImmediateInterruptOK also do
* HOLD_INTERRUPTS(), but that should not be necessary here since we don't
* call anything that could turn on ImmediateInterruptOK.
*/
save_ImmediateInterruptOK = ImmediateInterruptOK;
ImmediateInterruptOK = false;
/* /*
* Do processing in ErrorContext, which we hope has enough reserved space * Do processing in ErrorContext, which we hope has enough reserved space
* to report an error. * to report an error.
...@@ -463,10 +450,6 @@ errfinish(int dummy,...) ...@@ -463,10 +450,6 @@ errfinish(int dummy,...)
* itself be inside a holdoff section. If necessary, such a handler * itself be inside a holdoff section. If necessary, such a handler
* could save and restore InterruptHoldoffCount for itself, but this * could save and restore InterruptHoldoffCount for itself, but this
* should make life easier for most.) * should make life easier for most.)
*
* Note that we intentionally don't restore ImmediateInterruptOK here,
* even if it was set at entry. We definitely don't want that on
* while doing error cleanup.
*/ */
InterruptHoldoffCount = 0; InterruptHoldoffCount = 0;
QueryCancelHoldoffCount = 0; QueryCancelHoldoffCount = 0;
...@@ -573,15 +556,9 @@ errfinish(int dummy,...) ...@@ -573,15 +556,9 @@ errfinish(int dummy,...)
} }
/* /*
* We reach here if elevel <= WARNING. OK to return to caller, so restore * Check for cancel/die interrupt first --- this is so that the user can
* caller's setting of ImmediateInterruptOK. * stop a query emitting tons of notice or warning messages, even if it's
*/ * in a loop that otherwise fails to check for interrupts.
ImmediateInterruptOK = save_ImmediateInterruptOK;
/*
* But check for cancel/die interrupt first --- this is so that the user
* can stop a query emitting tons of notice or warning messages, even if
* it's in a loop that otherwise fails to check for interrupts.
*/ */
CHECK_FOR_INTERRUPTS(); CHECK_FOR_INTERRUPTS();
} }
......
...@@ -30,7 +30,6 @@ volatile bool InterruptPending = false; ...@@ -30,7 +30,6 @@ volatile bool InterruptPending = false;
volatile bool QueryCancelPending = false; volatile bool QueryCancelPending = false;
volatile bool ProcDiePending = false; volatile bool ProcDiePending = false;
volatile bool ClientConnectionLost = false; volatile bool ClientConnectionLost = false;
volatile bool ImmediateInterruptOK = false;
volatile uint32 InterruptHoldoffCount = 0; volatile uint32 InterruptHoldoffCount = 0;
volatile uint32 QueryCancelHoldoffCount = 0; volatile uint32 QueryCancelHoldoffCount = 0;
volatile uint32 CritSectionCount = 0; volatile uint32 CritSectionCount = 0;
......
...@@ -259,27 +259,12 @@ static void ...@@ -259,27 +259,12 @@ static void
handle_sig_alarm(SIGNAL_ARGS) handle_sig_alarm(SIGNAL_ARGS)
{ {
int save_errno = errno; int save_errno = errno;
bool save_ImmediateInterruptOK = ImmediateInterruptOK;
/* /*
* We may be executing while ImmediateInterruptOK is true (e.g., when * Bump the holdoff counter, to make sure nothing we call will process
* mainline is waiting for a lock). If SIGINT or similar arrives while * interrupts directly. No timeout handler should do that, but these
* this code is running, we'd lose control and perhaps leave our data * failures are hard to debug, so better be sure.
* structures in an inconsistent state. Disable immediate interrupts, and */
* just to be real sure, bump the holdoff counter as well. (The reason
* for this belt-and-suspenders-too approach is to make sure that nothing
* bad happens if a timeout handler calls code that manipulates
* ImmediateInterruptOK.)
*
* Note: it's possible for a SIGINT to interrupt handle_sig_alarm before
* we manage to do this; the net effect would be as if the SIGALRM event
* had been silently lost. Therefore error recovery must include some
* action that will allow any lost interrupt to be rescheduled. Disabling
* some or all timeouts is sufficient, or if that's not appropriate,
* reschedule_timeouts() can be called. Also, the signal blocking hazard
* described below applies here too.
*/
ImmediateInterruptOK = false;
HOLD_INTERRUPTS(); HOLD_INTERRUPTS();
/* /*
...@@ -332,24 +317,7 @@ handle_sig_alarm(SIGNAL_ARGS) ...@@ -332,24 +317,7 @@ handle_sig_alarm(SIGNAL_ARGS)
} }
} }
/*
* Re-allow query cancel, and then try to service any cancel request that
* arrived meanwhile (this might in particular include a cancel request
* fired by one of the timeout handlers). Since we are in a signal
* handler, we mustn't call ProcessInterrupts unless ImmediateInterruptOK
* is set; if it isn't, the cancel will happen at the next mainline
* CHECK_FOR_INTERRUPTS.
*
* Note: a longjmp from here is safe so far as our own data structures are
* concerned; but on platforms that block a signal before calling the
* handler and then un-block it on return, longjmping out of the signal
* handler leaves SIGALRM still blocked. Error cleanup is responsible for
* unblocking any blocked signals.
*/
RESUME_INTERRUPTS(); RESUME_INTERRUPTS();
ImmediateInterruptOK = save_ImmediateInterruptOK;
if (save_ImmediateInterruptOK)
CHECK_FOR_INTERRUPTS();
errno = save_errno; errno = save_errno;
} }
......
...@@ -84,7 +84,6 @@ extern PGDLLIMPORT volatile bool ProcDiePending; ...@@ -84,7 +84,6 @@ extern PGDLLIMPORT volatile bool ProcDiePending;
extern volatile bool ClientConnectionLost; extern volatile bool ClientConnectionLost;
/* these are marked volatile because they are examined by signal handlers: */ /* these are marked volatile because they are examined by signal handlers: */
extern PGDLLIMPORT volatile bool ImmediateInterruptOK;
extern PGDLLIMPORT volatile uint32 InterruptHoldoffCount; extern PGDLLIMPORT volatile uint32 InterruptHoldoffCount;
extern PGDLLIMPORT volatile uint32 QueryCancelHoldoffCount; extern PGDLLIMPORT volatile uint32 QueryCancelHoldoffCount;
extern PGDLLIMPORT volatile uint32 CritSectionCount; extern PGDLLIMPORT volatile uint32 CritSectionCount;
......
...@@ -60,13 +60,9 @@ test_shm_mq_main(Datum main_arg) ...@@ -60,13 +60,9 @@ test_shm_mq_main(Datum main_arg)
* *
* We want CHECK_FOR_INTERRUPTS() to kill off this worker process just as * We want CHECK_FOR_INTERRUPTS() to kill off this worker process just as
* it would a normal user backend. To make that happen, we establish a * it would a normal user backend. To make that happen, we establish a
* signal handler that is a stripped-down version of die(). We don't have * signal handler that is a stripped-down version of die().
* any equivalent of the backend's command-read loop, where interrupts can
* be processed immediately, so make sure ImmediateInterruptOK is turned
* off.
*/ */
pqsignal(SIGTERM, handle_sigterm); pqsignal(SIGTERM, handle_sigterm);
ImmediateInterruptOK = false;
BackgroundWorkerUnblockSignals(); BackgroundWorkerUnblockSignals();
/* /*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment