mirror of
https://git.postgresql.org/git/postgresql.git
synced 2025-01-12 18:34:36 +08:00
Remove set_latch_on_sigusr1 flag.
This flag has proven to be a recipe for bugs, and it doesn't seem like it can really buy anything in terms of performance. So let's just *always* set the process latch when we receive SIGUSR1 instead of trying to do it only when needed. Per my recent proposal on pgsql-hackers.
This commit is contained in:
parent
b7aac36245
commit
db0f6cad48
@ -954,13 +954,7 @@ WaitForBackgroundWorkerStartup(BackgroundWorkerHandle *handle, pid_t *pidp)
|
|||||||
{
|
{
|
||||||
BgwHandleStatus status;
|
BgwHandleStatus status;
|
||||||
int rc;
|
int rc;
|
||||||
bool save_set_latch_on_sigusr1;
|
|
||||||
|
|
||||||
save_set_latch_on_sigusr1 = set_latch_on_sigusr1;
|
|
||||||
set_latch_on_sigusr1 = true;
|
|
||||||
|
|
||||||
PG_TRY();
|
|
||||||
{
|
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
@ -984,15 +978,7 @@ WaitForBackgroundWorkerStartup(BackgroundWorkerHandle *handle, pid_t *pidp)
|
|||||||
|
|
||||||
ResetLatch(MyLatch);
|
ResetLatch(MyLatch);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
PG_CATCH();
|
|
||||||
{
|
|
||||||
set_latch_on_sigusr1 = save_set_latch_on_sigusr1;
|
|
||||||
PG_RE_THROW();
|
|
||||||
}
|
|
||||||
PG_END_TRY();
|
|
||||||
|
|
||||||
set_latch_on_sigusr1 = save_set_latch_on_sigusr1;
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1009,13 +995,7 @@ WaitForBackgroundWorkerShutdown(BackgroundWorkerHandle *handle)
|
|||||||
{
|
{
|
||||||
BgwHandleStatus status;
|
BgwHandleStatus status;
|
||||||
int rc;
|
int rc;
|
||||||
bool save_set_latch_on_sigusr1;
|
|
||||||
|
|
||||||
save_set_latch_on_sigusr1 = set_latch_on_sigusr1;
|
|
||||||
set_latch_on_sigusr1 = true;
|
|
||||||
|
|
||||||
PG_TRY();
|
|
||||||
{
|
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
@ -1034,15 +1014,7 @@ WaitForBackgroundWorkerShutdown(BackgroundWorkerHandle *handle)
|
|||||||
|
|
||||||
ResetLatch(&MyProc->procLatch);
|
ResetLatch(&MyProc->procLatch);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
PG_CATCH();
|
|
||||||
{
|
|
||||||
set_latch_on_sigusr1 = save_set_latch_on_sigusr1;
|
|
||||||
PG_RE_THROW();
|
|
||||||
}
|
|
||||||
PG_END_TRY();
|
|
||||||
|
|
||||||
set_latch_on_sigusr1 = save_set_latch_on_sigusr1;
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,14 +59,6 @@ typedef struct
|
|||||||
*/
|
*/
|
||||||
#define NumProcSignalSlots (MaxBackends + NUM_AUXPROCTYPES)
|
#define NumProcSignalSlots (MaxBackends + NUM_AUXPROCTYPES)
|
||||||
|
|
||||||
/*
|
|
||||||
* If this flag is set, the process latch will be set whenever SIGUSR1
|
|
||||||
* is received. This is useful when waiting for a signal from the postmaster.
|
|
||||||
* Spurious wakeups must be expected. Make sure that the flag is cleared
|
|
||||||
* in the error path.
|
|
||||||
*/
|
|
||||||
bool set_latch_on_sigusr1;
|
|
||||||
|
|
||||||
static ProcSignalSlot *ProcSignalSlots = NULL;
|
static ProcSignalSlot *ProcSignalSlots = NULL;
|
||||||
static volatile ProcSignalSlot *MyProcSignalSlot = NULL;
|
static volatile ProcSignalSlot *MyProcSignalSlot = NULL;
|
||||||
|
|
||||||
@ -296,7 +288,6 @@ procsignal_sigusr1_handler(SIGNAL_ARGS)
|
|||||||
if (CheckProcSignal(PROCSIG_RECOVERY_CONFLICT_BUFFERPIN))
|
if (CheckProcSignal(PROCSIG_RECOVERY_CONFLICT_BUFFERPIN))
|
||||||
RecoveryConflictInterrupt(PROCSIG_RECOVERY_CONFLICT_BUFFERPIN);
|
RecoveryConflictInterrupt(PROCSIG_RECOVERY_CONFLICT_BUFFERPIN);
|
||||||
|
|
||||||
if (set_latch_on_sigusr1)
|
|
||||||
SetLatch(MyLatch);
|
SetLatch(MyLatch);
|
||||||
|
|
||||||
latch_sigusr1_handler();
|
latch_sigusr1_handler();
|
||||||
|
@ -962,15 +962,8 @@ static bool
|
|||||||
shm_mq_wait_internal(volatile shm_mq *mq, PGPROC *volatile * ptr,
|
shm_mq_wait_internal(volatile shm_mq *mq, PGPROC *volatile * ptr,
|
||||||
BackgroundWorkerHandle *handle)
|
BackgroundWorkerHandle *handle)
|
||||||
{
|
{
|
||||||
bool save_set_latch_on_sigusr1;
|
|
||||||
bool result = false;
|
bool result = false;
|
||||||
|
|
||||||
save_set_latch_on_sigusr1 = set_latch_on_sigusr1;
|
|
||||||
if (handle != NULL)
|
|
||||||
set_latch_on_sigusr1 = true;
|
|
||||||
|
|
||||||
PG_TRY();
|
|
||||||
{
|
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
BgwHandleStatus status;
|
BgwHandleStatus status;
|
||||||
@ -1012,13 +1005,6 @@ shm_mq_wait_internal(volatile shm_mq *mq, PGPROC *volatile * ptr,
|
|||||||
/* Reset the latch so we don't spin. */
|
/* Reset the latch so we don't spin. */
|
||||||
ResetLatch(MyLatch);
|
ResetLatch(MyLatch);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
PG_CATCH();
|
|
||||||
{
|
|
||||||
set_latch_on_sigusr1 = save_set_latch_on_sigusr1;
|
|
||||||
PG_RE_THROW();
|
|
||||||
}
|
|
||||||
PG_END_TRY();
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -2825,9 +2825,7 @@ RecoveryConflictInterrupt(ProcSignalReason reason)
|
|||||||
/*
|
/*
|
||||||
* Set the process latch. This function essentially emulates signal
|
* Set the process latch. This function essentially emulates signal
|
||||||
* handlers like die() and StatementCancelHandler() and it seems prudent
|
* handlers like die() and StatementCancelHandler() and it seems prudent
|
||||||
* to behave similarly as they do. Alternatively all plain backend code
|
* to behave similarly as they do.
|
||||||
* waiting on that latch, expecting to get interrupted by query cancels et
|
|
||||||
* al., would also need to set set_latch_on_sigusr1.
|
|
||||||
*/
|
*/
|
||||||
SetLatch(MyLatch);
|
SetLatch(MyLatch);
|
||||||
|
|
||||||
|
@ -55,6 +55,5 @@ extern int SendProcSignal(pid_t pid, ProcSignalReason reason,
|
|||||||
BackendId backendId);
|
BackendId backendId);
|
||||||
|
|
||||||
extern void procsignal_sigusr1_handler(SIGNAL_ARGS);
|
extern void procsignal_sigusr1_handler(SIGNAL_ARGS);
|
||||||
extern PGDLLIMPORT bool set_latch_on_sigusr1;
|
|
||||||
|
|
||||||
#endif /* PROCSIGNAL_H */
|
#endif /* PROCSIGNAL_H */
|
||||||
|
@ -255,14 +255,8 @@ static void
|
|||||||
wait_for_workers_to_become_ready(worker_state *wstate,
|
wait_for_workers_to_become_ready(worker_state *wstate,
|
||||||
volatile test_shm_mq_header *hdr)
|
volatile test_shm_mq_header *hdr)
|
||||||
{
|
{
|
||||||
bool save_set_latch_on_sigusr1;
|
|
||||||
bool result = false;
|
bool result = false;
|
||||||
|
|
||||||
save_set_latch_on_sigusr1 = set_latch_on_sigusr1;
|
|
||||||
set_latch_on_sigusr1 = true;
|
|
||||||
|
|
||||||
PG_TRY();
|
|
||||||
{
|
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
int workers_ready;
|
int workers_ready;
|
||||||
@ -293,13 +287,6 @@ wait_for_workers_to_become_ready(worker_state *wstate,
|
|||||||
/* Reset the latch so we don't spin. */
|
/* Reset the latch so we don't spin. */
|
||||||
ResetLatch(MyLatch);
|
ResetLatch(MyLatch);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
PG_CATCH();
|
|
||||||
{
|
|
||||||
set_latch_on_sigusr1 = save_set_latch_on_sigusr1;
|
|
||||||
PG_RE_THROW();
|
|
||||||
}
|
|
||||||
PG_END_TRY();
|
|
||||||
|
|
||||||
if (!result)
|
if (!result)
|
||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
|
Loading…
Reference in New Issue
Block a user