mirror of
https://github.com/postgres/postgres.git
synced 2025-12-06 00:02:13 +03:00
Clean up latch related code.
The larger part of this patch replaces usages of MyProc->procLatch
with MyLatch. The latter works even early during backend startup,
where MyProc->procLatch doesn't yet. While the affected code
shouldn't run in cases where it's not initialized, it might get copied
into places where it might. Using MyLatch is simpler and a bit faster
to boot, so there's little point to stick with the previous coding.
While doing so I noticed some weaknesses around newly introduced uses
of latches that could lead to missed events, and an omitted
CHECK_FOR_INTERRUPTS() call in worker_spi.
As all the actual bugs are in v10 code, there doesn't seem to be
sufficient reason to backpatch this.
Author: Andres Freund
Discussion:
https://postgr.es/m/20170606195321.sjmenrfgl2nu6j63@alap3.anarazel.de
https://postgr.es/m/20170606210405.sim3yl6vpudhmufo@alap3.anarazel.de
Backpatch: -
This commit is contained in:
@@ -208,10 +208,15 @@ WaitForReplicationWorkerAttach(LogicalRepWorker *worker,
|
||||
WL_LATCH_SET | WL_TIMEOUT | WL_POSTMASTER_DEATH,
|
||||
1000L, WAIT_EVENT_BGWORKER_STARTUP);
|
||||
|
||||
/* emergency bailout if postmaster has died */
|
||||
if (rc & WL_POSTMASTER_DEATH)
|
||||
proc_exit(1);
|
||||
|
||||
ResetLatch(MyLatch);
|
||||
if (rc & WL_LATCH_SET)
|
||||
{
|
||||
ResetLatch(MyLatch);
|
||||
CHECK_FOR_INTERRUPTS();
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
@@ -440,10 +445,8 @@ logicalrep_worker_stop(Oid subid, Oid relid)
|
||||
|
||||
LWLockRelease(LogicalRepWorkerLock);
|
||||
|
||||
CHECK_FOR_INTERRUPTS();
|
||||
|
||||
/* Wait for signal. */
|
||||
rc = WaitLatch(&MyProc->procLatch,
|
||||
rc = WaitLatch(MyLatch,
|
||||
WL_LATCH_SET | WL_TIMEOUT | WL_POSTMASTER_DEATH,
|
||||
1000L, WAIT_EVENT_BGWORKER_STARTUP);
|
||||
|
||||
@@ -451,7 +454,11 @@ logicalrep_worker_stop(Oid subid, Oid relid)
|
||||
if (rc & WL_POSTMASTER_DEATH)
|
||||
proc_exit(1);
|
||||
|
||||
ResetLatch(&MyProc->procLatch);
|
||||
if (rc & WL_LATCH_SET)
|
||||
{
|
||||
ResetLatch(MyLatch);
|
||||
CHECK_FOR_INTERRUPTS();
|
||||
}
|
||||
|
||||
/* Check worker status. */
|
||||
LWLockAcquire(LogicalRepWorkerLock, LW_SHARED);
|
||||
@@ -492,7 +499,7 @@ logicalrep_worker_stop(Oid subid, Oid relid)
|
||||
CHECK_FOR_INTERRUPTS();
|
||||
|
||||
/* Wait for more work. */
|
||||
rc = WaitLatch(&MyProc->procLatch,
|
||||
rc = WaitLatch(MyLatch,
|
||||
WL_LATCH_SET | WL_TIMEOUT | WL_POSTMASTER_DEATH,
|
||||
1000L, WAIT_EVENT_BGWORKER_SHUTDOWN);
|
||||
|
||||
@@ -500,7 +507,11 @@ logicalrep_worker_stop(Oid subid, Oid relid)
|
||||
if (rc & WL_POSTMASTER_DEATH)
|
||||
proc_exit(1);
|
||||
|
||||
ResetLatch(&MyProc->procLatch);
|
||||
if (rc & WL_LATCH_SET)
|
||||
{
|
||||
ResetLatch(MyLatch);
|
||||
CHECK_FOR_INTERRUPTS();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -876,7 +887,7 @@ ApplyLauncherMain(Datum main_arg)
|
||||
}
|
||||
|
||||
/* Wait for more work. */
|
||||
rc = WaitLatch(&MyProc->procLatch,
|
||||
rc = WaitLatch(MyLatch,
|
||||
WL_LATCH_SET | WL_TIMEOUT | WL_POSTMASTER_DEATH,
|
||||
wait_time,
|
||||
WAIT_EVENT_LOGICAL_LAUNCHER_MAIN);
|
||||
@@ -885,13 +896,17 @@ ApplyLauncherMain(Datum main_arg)
|
||||
if (rc & WL_POSTMASTER_DEATH)
|
||||
proc_exit(1);
|
||||
|
||||
if (rc & WL_LATCH_SET)
|
||||
{
|
||||
ResetLatch(MyLatch);
|
||||
CHECK_FOR_INTERRUPTS();
|
||||
}
|
||||
|
||||
if (got_SIGHUP)
|
||||
{
|
||||
got_SIGHUP = false;
|
||||
ProcessConfigFile(PGC_SIGHUP);
|
||||
}
|
||||
|
||||
ResetLatch(&MyProc->procLatch);
|
||||
}
|
||||
|
||||
LogicalRepCtx->launcher_pid = 0;
|
||||
|
||||
Reference in New Issue
Block a user