mirror of
https://github.com/postgres/postgres.git
synced 2026-10-23 13:29:09 +03:00
Handle checksumworker startup wait race
If the background worker for processing databases manages to finish before the launcher starts waiting for it, the launcher would treat it erroneously as an error. Fix by ensureing to check result state in this case. Identified on CI and synthetically reproduced during local testing. Also while, make sure to properly lock the shared memory structure before updating tje result state. Author: Daniel Gustafsson <daniel@yesql.seA Reported-by: Andres Freund <andres@anarazel.de> Discussion: https://postgr.es/m/4fxw37ge47v5baeozla5phymi233hxbcjbwwsfwv3mpg3kyl2z@6jk4nkf6jp4
This commit is contained in:
@@ -797,6 +797,19 @@ ProcessDatabase(DataChecksumsWorkerDatabase *db)
|
||||
status = WaitForBackgroundWorkerStartup(bgw_handle, &pid);
|
||||
if (status == BGWH_STOPPED)
|
||||
{
|
||||
/*
|
||||
* If the worker managed to start, and stop, before we got to waiting
|
||||
* for it we can se a STOPPED status here without it being a failure.
|
||||
*/
|
||||
if (DataChecksumState->success == DATACHECKSUMSWORKER_SUCCESSFUL)
|
||||
{
|
||||
pgstat_report_activity(STATE_IDLE, NULL);
|
||||
LWLockAcquire(DataChecksumsWorkerLock, LW_EXCLUSIVE);
|
||||
DataChecksumState->worker_pid = InvalidPid;
|
||||
LWLockRelease(DataChecksumsWorkerLock);
|
||||
return DataChecksumState->success;
|
||||
}
|
||||
|
||||
ereport(WARNING,
|
||||
errmsg("could not start background worker for enabling data checksums in database \"%s\"",
|
||||
db->dbname),
|
||||
@@ -1595,5 +1608,7 @@ DataChecksumsWorkerMain(Datum arg)
|
||||
/* worker done */
|
||||
pgstat_progress_end_command();
|
||||
|
||||
LWLockAcquire(DataChecksumsWorkerLock, LW_EXCLUSIVE);
|
||||
DataChecksumState->success = DATACHECKSUMSWORKER_SUCCESSFUL;
|
||||
LWLockRelease(DataChecksumsWorkerLock);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user