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

Commit e8a7579

Browse files
committed
Fix handle
1 parent bcb5972 commit e8a7579

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

jsonbc.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,18 +157,23 @@ jsonbc_shmem_startup_hook(void)
157157

158158
for (i = 0; i < jsonbc_nworkers; i++)
159159
{
160+
size_t queue_size = jsonbc_get_queue_size();
161+
160162
jsonbc_shm_worker *wd = shm_toc_allocate(toc, sizeof(jsonbc_shm_worker));
161163

162164
/* each worker will have two mq, for input and output */
163-
wd->mqin = shm_mq_create(shm_toc_allocate(toc, jsonbc_get_queue_size()),
164-
jsonbc_get_queue_size());
165-
wd->mqout = shm_mq_create(shm_toc_allocate(toc, jsonbc_get_queue_size()),
166-
jsonbc_get_queue_size());
165+
wd->mqin = shm_mq_create(shm_toc_allocate(toc, queue_size), queue_size);
166+
wd->mqout = shm_mq_create(shm_toc_allocate(toc, queue_size), queue_size);
167167

168168
/* init worker context */
169169
pg_atomic_init_flag(&wd->busy);
170170
wd->proc = NULL;
171171

172+
shm_mq_clean_receiver(wd->mqin);
173+
shm_mq_clean_receiver(wd->mqout);
174+
shm_mq_clean_sender(wd->mqin);
175+
shm_mq_clean_sender(wd->mqout);
176+
172177
shm_toc_insert(toc, i + 1, wd);
173178
shm_toc_insert(toc, mqkey++, wd->mqin);
174179
shm_toc_insert(toc, mqkey++, wd->mqout);

jsonbc_worker.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,7 @@ void
338338
worker_main(Datum arg)
339339
{
340340
MemoryContext worker_context;
341+
shm_mq_handle *mqh = NULL;
341342

342343
/* Establish signal handlers before unblocking signals */
343344
pqsignal(SIGTERM, handle_sigterm);
@@ -365,10 +366,11 @@ worker_main(Datum arg)
365366
Size nbytes;
366367
void *data;
367368

368-
shm_mq_handle *mqh;
369369
shm_mq_result resmq;
370370

371-
mqh = shm_mq_attach(worker_state->mqin, NULL, NULL);
371+
if (!mqh)
372+
mqh = shm_mq_attach(worker_state->mqin, NULL, NULL);
373+
372374
resmq = shm_mq_receive(mqh, &nbytes, &data, true);
373375

374376
if (resmq == SHM_MQ_SUCCESS)
@@ -409,7 +411,10 @@ worker_main(Datum arg)
409411
elog(NOTICE, "jsonbc: backend detached early");
410412

411413
shm_mq_detach(mqh);
412-
pfree((void *) iov.data);
414+
MemoryContextReset(worker_context);
415+
416+
/* mark we need new handle */
417+
mqh = NULL;
413418
}
414419

415420
if (shutdown_requested)

0 commit comments

Comments
 (0)