Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit b4d0e53

Browse files
author
Vladimir Ershov
committed
fix blocking while bgworker init connection while pg_class locked
1 parent 3f0f5b6 commit b4d0e53

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

src/scheduler_executor.c

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -85,29 +85,33 @@ void executor_worker_main(Datum arg)
8585

8686
CurrentResourceOwner = ResourceOwnerCreate(NULL, "pgpro_scheduler_executor");
8787
init_worker_mem_ctx("ExecutorMemoryContext");
88+
pqsignal(SIGTERM, handle_sigterm);
89+
pqsignal(SIGHUP, worker_spi_sighup);
90+
/* must be called before connection initialization otherwise infint wait
91+
* could happend if bgworker starts while one of 7th critical tables
92+
* being locked
93+
*/
94+
BackgroundWorkerUnblockSignals();
8895

8996
seg = dsm_attach(DatumGetInt32(arg));
9097
if(seg == NULL)
9198
ereport(ERROR,
9299
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
93100
errmsg("executor unable to map dynamic shared memory segment")));
94101
shared = dsm_segment_address(seg);
95-
parent = BackendPidGetProc(MyBgworkerEntry->bgw_notify_pid);
96102

97103
if(shared->status != SchdExecutorInit)
98104
{
99105
ereport(ERROR,
100106
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
101107
errmsg("executor corrupted dynamic shared memory segment")));
102108
}
109+
BackgroundWorkerInitializeConnection(shared->database, NULL);
103110

111+
parent = BackendPidGetProc(MyBgworkerEntry->bgw_notify_pid);
104112
SetConfigOption("application_name", "pgp-s executor", PGC_USERSET, PGC_S_SESSION);
105113
pgstat_report_activity(STATE_RUNNING, "initialize");
106-
BackgroundWorkerInitializeConnection(shared->database, NULL);
107114

108-
pqsignal(SIGTERM, handle_sigterm);
109-
pqsignal(SIGHUP, worker_spi_sighup);
110-
BackgroundWorkerUnblockSignals();
111115

112116
worker_jobs_limit = read_worker_job_limit();
113117

@@ -667,6 +671,10 @@ void at_executor_worker_main(Datum arg)
667671

668672
CurrentResourceOwner = ResourceOwnerCreate(NULL, "pgpro_scheduler_at_executor");
669673
init_worker_mem_ctx("ExecutorMemoryContext");
674+
pqsignal(SIGTERM, handle_sigterm);
675+
pqsignal(SIGHUP, worker_spi_sighup);
676+
BackgroundWorkerUnblockSignals();
677+
670678
seg = dsm_attach(DatumGetInt32(arg));
671679
if(seg == NULL)
672680
ereport(ERROR,
@@ -683,13 +691,9 @@ void at_executor_worker_main(Datum arg)
683691
}
684692
shared->start_at = GetCurrentTimestamp();
685693

694+
BackgroundWorkerInitializeConnection(shared->database, NULL);
686695
SetConfigOption("application_name", "pgp-s at executor", PGC_USERSET, PGC_S_SESSION);
687696
pgstat_report_activity(STATE_RUNNING, "initialize");
688-
BackgroundWorkerInitializeConnection(shared->database, NULL);
689-
690-
pqsignal(SIGTERM, handle_sigterm);
691-
pqsignal(SIGHUP, worker_spi_sighup);
692-
BackgroundWorkerUnblockSignals();
693697

694698

695699
while(1)

src/scheduler_manager.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1784,10 +1784,15 @@ void manager_worker_main(Datum arg)
17841784

17851785
snprintf(database, NAMEDATALEN, "%s", MyBgworkerEntry->bgw_extra);
17861786
snprintf(buffer, 1024, "pgp-s manager [%s]", database);
1787-
SetConfigOption("application_name", buffer, PGC_USERSET, PGC_S_SESSION);
1787+
1788+
pqsignal(SIGHUP, worker_spi_sighup);
1789+
pqsignal(SIGTERM, worker_spi_sigterm);
1790+
BackgroundWorkerUnblockSignals();
1791+
17881792

17891793
BackgroundWorkerInitializeConnection(database, NULL);
17901794
elog(LOG, "Started scheduler manager for '%s'", database);
1795+
SetConfigOption("application_name", buffer, PGC_USERSET, PGC_S_SESSION);
17911796

17921797
if(!checkSchedulerNamespace())
17931798
{
@@ -1800,10 +1805,6 @@ void manager_worker_main(Datum arg)
18001805
SetCurrentStatementStartTimestamp();
18011806
pgstat_report_activity(STATE_RUNNING, "initialize.");
18021807

1803-
pqsignal(SIGHUP, worker_spi_sighup);
1804-
pqsignal(SIGTERM, worker_spi_sigterm);
1805-
BackgroundWorkerUnblockSignals();
1806-
18071808
parent_shared = dsm_segment_address(seg);
18081809
pgstat_report_activity(STATE_RUNNING, "initialize context");
18091810
changeChildBgwState(shared, SchdManagerConnected);

0 commit comments

Comments
 (0)