BackendPidGetProc doesn't return PGPROC for background worker?

Started by Pavel Stehuleover 10 years ago6 messages
#1Pavel Stehule
pavel.stehule@gmail.com

Hi

I am trying to start bgworker from bgworker and create communication
between these process. I have a code based on test_shm_mq. This code fails
because BackendPidGetProc doesn't find related bgworker process, although
the registrant process is living

registrant = BackendPidGetProc(MyBgworkerEntry->bgw_notify_pid)

Is expected behave?

Regards

Pavel

#2Amit Langote
Langote_Amit_f8@lab.ntt.co.jp
In reply to: Pavel Stehule (#1)
Re: BackendPidGetProc doesn't return PGPROC for background worker?

On 2015-05-15 AM 05:01, Pavel Stehule wrote:

I am trying to start bgworker from bgworker and create communication
between these process. I have a code based on test_shm_mq. This code fails
because BackendPidGetProc doesn't find related bgworker process, although
the registrant process is living

One reason for this may be that the worker was not started with the flag
BGWORKER_SHMEM_ACCESS which is necessary to perform InitProcess() that would
initialize a PGPROC entry for it. But if you'd used the same method for
initializing workers as test_shm_mq_setup(), then it should have.

Thanks,
Amit

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#3Amit Langote
Langote_Amit_f8@lab.ntt.co.jp
In reply to: Amit Langote (#2)
Re: BackendPidGetProc doesn't return PGPROC for background worker?

On 2015-05-15 AM 10:39, Amit Langote wrote:

On 2015-05-15 AM 05:01, Pavel Stehule wrote:

I am trying to start bgworker from bgworker and create communication
between these process. I have a code based on test_shm_mq. This code fails
because BackendPidGetProc doesn't find related bgworker process, although
the registrant process is living

One reason for this may be that the worker was not started with the flag
BGWORKER_SHMEM_ACCESS which is necessary to perform InitProcess() that would
initialize a PGPROC entry for it. But if you'd used the same method for
initializing workers as test_shm_mq_setup(), then it should have.

It seems in addition, a BackgroundWorkerInitializeConnection() is also
necessary for the PGPROC entry of the worker to be visible to others. I do not
see that done anywhere in test_shm_mq(); so perhaps that's missing?

Thanks,
Amit

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#4Amit Langote
Langote_Amit_f8@lab.ntt.co.jp
In reply to: Amit Langote (#3)
Re: BackendPidGetProc doesn't return PGPROC for background worker?

On 2015-05-15 AM 10:59, Amit Langote wrote:

On 2015-05-15 AM 10:39, Amit Langote wrote:

On 2015-05-15 AM 05:01, Pavel Stehule wrote:

I am trying to start bgworker from bgworker and create communication
between these process. I have a code based on test_shm_mq. This code fails
because BackendPidGetProc doesn't find related bgworker process, although
the registrant process is living

One reason for this may be that the worker was not started with the flag
BGWORKER_SHMEM_ACCESS which is necessary to perform InitProcess() that would
initialize a PGPROC entry for it. But if you'd used the same method for
initializing workers as test_shm_mq_setup(), then it should have.

It seems in addition, a BackgroundWorkerInitializeConnection() is also
necessary for the PGPROC entry of the worker to be visible to others. I do not
see that done anywhere in test_shm_mq(); so perhaps that's missing?

And these conditions apply to the bgworker that started another bgworker, that
is the registrant bgworker. I think such a pattern does not exist in existing
code. That is, normally all workers are started by a user backend that has a
valid shared PGPROC entry.

Thanks,
Amit

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#5Pavel Stehule
pavel.stehule@gmail.com
In reply to: Amit Langote (#2)
Re: BackendPidGetProc doesn't return PGPROC for background worker?

2015-05-15 3:39 GMT+02:00 Amit Langote <Langote_Amit_f8@lab.ntt.co.jp>:

On 2015-05-15 AM 05:01, Pavel Stehule wrote:

I am trying to start bgworker from bgworker and create communication
between these process. I have a code based on test_shm_mq. This code

fails

because BackendPidGetProc doesn't find related bgworker process, although
the registrant process is living

One reason for this may be that the worker was not started with the flag
BGWORKER_SHMEM_ACCESS which is necessary to perform InitProcess() that
would
initialize a PGPROC entry for it. But if you'd used the same method for
initializing workers as test_shm_mq_setup(), then it should have.

I have it

Show quoted text

Thanks,
Amit

#6Amit Langote
Langote_Amit_f8@lab.ntt.co.jp
In reply to: Pavel Stehule (#5)
Re: BackendPidGetProc doesn't return PGPROC for background worker?

On 2015-05-15 PM 02:13, Pavel Stehule wrote:

2015-05-15 3:39 GMT+02:00 Amit Langote <Langote_Amit_f8@lab.ntt.co.jp>:

One reason for this may be that the worker was not started with the flag
BGWORKER_SHMEM_ACCESS which is necessary to perform InitProcess() that
would
initialize a PGPROC entry for it. But if you'd used the same method for
initializing workers as test_shm_mq_setup(), then it should have.

I have it

See my other (the last) email. You said you created a bgworker from bgworker,
so if the parent bgworker did not perform
BackgroundWorkerInitializeConnection, then it would not be found in ProcArray.

Thanks,
Amit

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers