Re: Can a background worker exist without shared memory access for EXEC_BACKEND cases?

Поиск
Список
Период
Сортировка
От Robert Haas
Тема Re: Can a background worker exist without shared memory access for EXEC_BACKEND cases?
Дата
Msg-id CA+TgmoY2a5pRNOjz=h-jJNt8dO8=PK=kMf5dCUBsb8eiRTrhhw@mail.gmail.com
обсуждение исходный текст
Ответ на Can a background worker exist without shared memory access for EXEC_BACKEND cases?  (Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>)
Ответы Re: Can a background worker exist without shared memory access for EXEC_BACKEND cases?  (Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>)
Список pgsql-hackers
On Fri, Jul 31, 2020 at 11:13 PM Bharath Rupireddy
<bharath.rupireddyforpostgres@gmail.com> wrote:
> memory. MyLatch variable also gets created in shared mode. And having
> no shared memory access for the worker for EXEC_BACKEND cases(in
> StartBackgroundWorker, the shared memory segments get detached), the
> worker fails to receive all the global state from the postmaster.

What exactly do you mean by "all the global state"?

It's certainly true that if you declare some random static variable
and initialize it in the postmaster, and you don't take any special
precautions to propagate that into workers, then on an EXEC_BACKEND
build, it won't be set in the workers. That's why, for example, most
of the *ShmemInit() functions are written like this:

        TwoPhaseState = ShmemInitStruct("Prepared Transaction Table",

 TwoPhaseShmemSize(),
                                                                        &found);
        if (!IsUnderPostmaster)
...initialize the data structure...
        else
                Assert(found);

The assignment to TwoPhaseState is unconditional, because in an
EXEC_BACKEND build that's going to be done in every process, and
otherwise the variable won't be set. But the initialization of the
shared data structure happens conditionally, because that needs to be
done only once.

See also the BackendParameters stuff, which arranges to pass down a
bunch of things to exec'd backends.

I am not necessarily opposed to trying to clarify the documentation
and/or comments here, but "global state" is a fuzzy term that doesn't
really mean anything to me.

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



В списке pgsql-hackers по дате отправления:

Предыдущее
От: Tomas Vondra
Дата:
Сообщение: Re: WIP: WAL prefetch (another approach)
Следующее
От: Konstantin Knizhnik
Дата:
Сообщение: Re: Cache relation sizes?