Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0bf1849

Browse files
knizhnikkelvich
authored andcommitted
Handle stop signals in bgworkers
1 parent17f2cab commit0bf1849

File tree

3 files changed

+45
-14
lines changed

3 files changed

+45
-14
lines changed

‎Cluster.pm

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -209,17 +209,17 @@ sub stop
209209
my$nodes =$self->{nodes};
210210
$mode ='fast'unlessdefined$mode;
211211

212-
diag("Dumping logs:");
213-
foreachmy$node (@$nodes) {
214-
diag("##################################################################");
215-
diag($node->{_logfile});
216-
diag("##################################################################");
217-
my$filename =$node->{_logfile};
218-
openmy$fh,'<',$filenameordie"error opening$filename:$!";
219-
my$data =do {local$/; <$fh> };
220-
diag($data);
221-
diag("##################################################################\n\n");
222-
}
212+
#diag("Dumping logs:");
213+
#foreach my $node (@$nodes) {
214+
#diag("##################################################################");
215+
#diag($node->{_logfile});
216+
#diag("##################################################################");
217+
#my $filename = $node->{_logfile};
218+
#open my $fh, '<', $filename or die "error opening $filename: $!";
219+
#my $data = do { local $/; <$fh> };
220+
#diag($data);
221+
#diag("##################################################################\n\n");
222+
#}
223223

224224
my$ok = 1;
225225
diag("stopping cluster${mode}ly");
@@ -233,7 +233,7 @@ sub stop
233233
}
234234
}
235235
}
236-
236+
sleep(2);
237237
return$ok;
238238
}
239239

‎bgwpool.c

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include"postmaster/bgworker.h"
66
#include"storage/s_lock.h"
77
#include"storage/spin.h"
8+
#include"storage/proc.h"
89
#include"storage/pg_sema.h"
910
#include"storage/shmem.h"
1011
#include"datatype/timestamp.h"
@@ -16,23 +17,41 @@
1617
boolMtmIsLogicalReceiver;
1718
intMtmMaxWorkers;
1819

20+
staticBgwPool*pool;
21+
22+
staticvoidBgwShutdownWorker(intsig)
23+
{
24+
BgwPoolStop(pool);
25+
}
26+
1927
staticvoidBgwPoolMainLoop(BgwPool*pool)
2028
{
2129
intsize;
2230
void*work;
2331
staticPortalDatafakePortal;
32+
sigset_tsset;
2433

2534
MtmIsLogicalReceiver= true;
2635

36+
signal(SIGINT,BgwShutdownWorker);
37+
signal(SIGQUIT,BgwShutdownWorker);
38+
signal(SIGTERM,BgwShutdownWorker);
39+
40+
sigfillset(&sset);
41+
sigprocmask(SIG_UNBLOCK,&sset,NULL);
42+
2743
BackgroundWorkerUnblockSignals();
2844
BackgroundWorkerInitializeConnection(pool->dbname,pool->dbuser);
2945
ActivePortal=&fakePortal;
3046
ActivePortal->status=PORTAL_ACTIVE;
3147
ActivePortal->sourceText="";
3248

33-
while(true) {
49+
while(true) {
3450
PGSemaphoreLock(&pool->available);
3551
SpinLockAcquire(&pool->lock);
52+
if (pool->shutdown) {
53+
break;
54+
}
3655
size=*(int*)&pool->queue[pool->head];
3756
Assert(size<pool->size);
3857
work=malloc(size);
@@ -64,6 +83,7 @@ static void BgwPoolMainLoop(BgwPool* pool)
6483
pool->lastPeakTime=0;
6584
SpinLockRelease(&pool->lock);
6685
}
86+
SpinLockRelease(&pool->lock);
6787
}
6888

6989
voidBgwPoolInit(BgwPool*pool,BgwPoolExecutorexecutor,charconst*dbname,charconst*dbuser,size_tqueueSize,size_tnWorkers)
@@ -75,6 +95,7 @@ void BgwPoolInit(BgwPool* pool, BgwPoolExecutor executor, char const* dbname, c
7595
PGSemaphoreReset(&pool->available);
7696
PGSemaphoreReset(&pool->overflow);
7797
SpinLockInit(&pool->lock);
98+
pool->shutdown= false;
7899
pool->producerBlocked= false;
79100
pool->head=0;
80101
pool->tail=0;
@@ -167,7 +188,7 @@ void BgwPoolExecute(BgwPool* pool, void* work, size_t size)
167188
}
168189

169190
SpinLockAcquire(&pool->lock);
170-
while (true) {
191+
while (!pool->shutdown) {
171192
if ((pool->head <=pool->tail&&pool->size-pool->tail<size+4&&pool->head<size)
172193
|| (pool->head>pool->tail&&pool->head-pool->tail<size+4))
173194
{
@@ -204,3 +225,11 @@ void BgwPoolExecute(BgwPool* pool, void* work, size_t size)
204225
SpinLockRelease(&pool->lock);
205226
}
206227

228+
voidBgwPoolStop(BgwPool*pool)
229+
{
230+
SpinLockAcquire(&pool->lock);
231+
pool->shutdown= true;
232+
SpinLockRelease(&pool->lock);
233+
PGSemaphoreUnlock(&pool->available);
234+
PGSemaphoreUnlock(&pool->overflow);
235+
}

‎bgwpool.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ typedef struct
3434
time_tlastPeakTime;
3535
timestamp_tlastDynamicWorkerStartTime;
3636
boolproducerBlocked;
37+
boolshutdown;
3738
chardbname[MAX_DBNAME_LEN];
3839
chardbuser[MAX_DBUSER_LEN];
3940
char*queue;
@@ -51,4 +52,5 @@ extern size_t BgwPoolGetQueueSize(BgwPool* pool);
5152

5253
externtimestamp_tBgwGetLastPeekTime(BgwPool*pool);
5354

55+
externvoidBgwPoolStop(BgwPool*pool);
5456
#endif

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp