Initializing LWLock Array from Server Code

From: Souvik Bhattacherjee <kivuosb(at)gmail(dot)com>
To: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Initializing LWLock Array from Server Code
Date: 2019-04-26 18:58:20
Message-ID: CAANrPSd+4=3dwvTz=_wW=hbF_LVB7wfS3FzSLzu5UfdifXSmNg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

I have created a shared hash table in partitioned mode inside the postgres
server code. In order to guard the partitions, I'm trying to initialize an
array of LWLocks. The code that I'm trying to use for that is

void RequestNamedLWLockTranche
<https://doxygen.postgresql.org/lwlock_8h.html#a77298cebf29062e88e529beb3851219b>
(const char *tranche_name, int num_lwlocks);
LWLockPadded <https://doxygen.postgresql.org/unionLWLockPadded.html> *
GetNamedLWLockTranche
<https://doxygen.postgresql.org/lwlock_8h.html#a15c956090fa42be94e075a1cf6bdfd8e>
(const char *tranche_name);

I'm not sure where exactly should this code be called from the server code.
So I had placed it in

void CreateSharedMemoryAndSemaphores(bool makePrivate, int port);

within ipic.c. However, I'm getting the following error message when
starting the database:

FATAL: requested tranche is not registered

So at this point, I'm a little confused as to where the methods should be
called from inside the server code. Any pointers would be appreciated.

Thanks,
-SB

PS: I saw that that are two variables controlling access to
RequestNamedLWLockTranche
<https://doxygen.postgresql.org/lwlock_8h.html#a77298cebf29062e88e529beb3851219b>
()

if (IsUnderPostmaster
<https://doxygen.postgresql.org/globals_8c.html#a6e9dda2cdd786e5cba0d83b2deb577ec>
|| !lock_named_request_allowed
<https://doxygen.postgresql.org/lwlock_8c.html#aa9d4ba31a9dbab8fee08d6f0f649eb64>
)
return; /* too late */

which implies that IsUnderPostmaster must be false and
lock_named_request_allowed should be true. Thus, I had invoked
RequestNamedLWLockTranche
<https://doxygen.postgresql.org/lwlock_8h.html#a77298cebf29062e88e529beb3851219b>
before the first call to LWLockShmemSize
<https://doxygen.postgresql.org/lwlock_8c.html#af312a0706333345e2be792a7718b6c43>
which sets lock_named_request_allowed = true and GetNamedLWLockTranche
<https://doxygen.postgresql.org/lwlock_8h.html#a15c956090fa42be94e075a1cf6bdfd8e>
later. This works in the single user mode but fails when I start the server
explicitly through postgres -D ...

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2019-04-26 19:25:10 Re: Regression test PANICs with master-standby setup on same machine
Previous Message Tom Lane 2019-04-26 18:57:49 Re: BUG #15672: PostgreSQL 11.1/11.2 crashed after dropping a partition table