Re: parallel mode and parallel contexts - Mailing list pgsql-hackers

From Robert Haas
Subject Re: parallel mode and parallel contexts
Date
Msg-id CA+TgmoagwFJyKVkt7b9m=vLiHM16De3rbykTVyQ5f46qiSHJFw@mail.gmail.com
Whole thread Raw
In response to Re: parallel mode and parallel contexts  (Amit Kapila <amit.kapila16@gmail.com>)
Responses Re: parallel mode and parallel contexts
List pgsql-hackers
On Thu, Jan 15, 2015 at 7:00 AM, Amit Kapila <amit.kapila16@gmail.com> wrote:
> On Tue, Jan 13, 2015 at 1:33 AM, Robert Haas <robertmhaas@gmail.com> wrote:
>> On Thu, Jan 8, 2015 at 6:52 AM, Amit Kapila <amit.kapila16@gmail.com>
>> wrote:
>> > + seg = dsm_attach(DatumGetInt32(main_arg));
>> >
>> > Here, I think DatumGetUInt32() needs to be used instead of
>> > DatumGetInt32() as the segment handle is uint32.
>>
>> OK, I'll change that in the next version.
>>
>
> No issues, I have another question related to below code:
>
> +HandleParallelMessages(void)
> +{
> ..
> ..
> + for (i = 0; i < pcxt->nworkers; ++i)
> + {
> + /*
> + * Read messages for as long as we have an error queue; if we
> + * have hit (or hit while reading) ReadyForQuery, this will go to
> + * NULL.
> + */
> + while (pcxt->worker[i].error_mqh != NULL)
> + {
> + shm_mq_result res;
> +
> + CHECK_FOR_INTERRUPTS();
> +
> + res = shm_mq_receive(pcxt->worker[i].error_mqh, &nbytes,
> + &data, true);
> + if (res == SHM_MQ_SUCCESS)
>
> Here we are checking the error queue for all the workers and this loop
> will continue untill all have sent ReadyForQuery() message ('Z') which
> will make this loop continue till all workers have finished their work.
> Assume situation where first worker has completed the work and sent
> 'Z' message and second worker is still sending some tuples, now above
> code will keep on waiting for 'Z' message from second worker and won't
> allow to receive tuples sent by second worker till it send 'Z' message.
>
> As each worker send its own 'Z' message after completion, so ideally
> the above code should receive the message only for worker which has
> sent the message.  I think for that it needs worker information who has
> sent the message.

Are you talking about HandleParallelMessages() or
WaitForParallelWorkersToFinish()?  The former doesn't wait for
anything; it just handles any messages that are available now.  The
latter does wait for all workers to finish, but the intention is that
you only call it when you're ready to wind up the entire parallel
operation, so that's OK.

-- 
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company



pgsql-hackers by date:

Previous
From: Greg Stark
Date:
Subject: Re: pg_rewind in contrib
Next
From: Andres Freund
Date:
Subject: Re: pg_rewind in contrib