Inconsistent bgworker behaviour

Поиск
Список
Период
Сортировка
От Beena Emerson
Тема Inconsistent bgworker behaviour
Дата
Msg-id CAOG9ApERAYKscHQcReyH_F=fAc_1uStJz2uzCON+=_1k9A-ctw@mail.gmail.com
обсуждение исходный текст
Ответы Re: Inconsistent bgworker behaviour  (Craig Ringer <craig@2ndquadrant.com>)
Список pgsql-general

Hello,

I have been working on a  module which launches background workers for a list of databases provided by a configuration parameter(say m_databases). This configuration parameter can be edited and reloaded.
It has a launcher which manages all the workers launched by the module.  The worker.bgw_notify_pid of the workers are set to the launcher pid.

The number of background workers that can be launched is restricted by max_worker_processes.

Consider the following scenario:
max_worker_processes = 3
m_databases='db1, db2'

The server is started.

The m_databases is updated to
m_databases='db3, db2'

$ pg_ctl reload

The expected behavior is that the db1 worker should be terminated and db3 worker should be launched. However I found that this behavior is not consistent. In few runs, when the databases parameter is edited and reloaded, the new worker is launched before the old ones are terminated causing an error.

I have used the following code on the launcher to ensure that the old unnecessary background workers are terminated before the new background workers are launched for newly added databases.
for (i = 0; i < workers_launched; i++)
{
        if (!is_inlist(new_dblist, workers[i]->dbname))
        {
            /* Ensure that the background worker is terminated before regitsering
             * new workers to avoid crossing the limit of max_worker_processes
             */
            ResetLatch(&MyProc->procLatch);
            TerminateBackgroundWorker(workers[i]->handle);
            WaitLatch(&MyProc->procLatch, WL_LATCH_SET, 0);
        }
}
.
.
. (launch new workers)
.

The Latch is set when the SIGUSR1 signal is received. IIUC correctly, the launcher gets the SIGUSR1 when the bgworker process has exited. No new worker is launched or terminated in between still the code does not work as expected for all the runs.

Any help will be appreciated.

Thank you,

Beena

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

Предыдущее
От: deans
Дата:
Сообщение: BDR Error restarted
Следующее
От: Jiří Hlinka
Дата:
Сообщение: Central management for regular tasks on multiple databases