Skip to content

Commit 4bf901d

Browse files
author
Vladimir Ershov
committed
Merge commit 'b4d0e53fd72107f5aaec361ab028e78699a36ea6' into PGPROEE9_6_scheduler
fix blocking on init_connection
2 parents 7669343 + b4d0e53 commit 4bf901d

File tree

3 files changed

+21
-16
lines changed

3 files changed

+21
-16
lines changed

contrib/pgpro_scheduler/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)

contrib/pgpro_scheduler/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);

contrib/pgpro_scheduler/test/perl/t/jobExecuteWindow.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ ok($sth->execute()) or (print $DBI::errstr and $dbh->disconnect() and BAIL_OUT);
5454
$sth->finish();
5555

5656

57-
sleep 120;
57+
sleep 60;
5858
$query = "SELECT count(*) FROM test_results";
5959
$sth = $dbh->prepare($query);
6060
ok($sth->execute()) or (print $DBI::errstr and $dbh->disconnect() and BAIL_OUT);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy