Initializing LWLock Array from Server Code - Mailing list pgsql-hackers

From Souvik Bhattacherjee
Subject Initializing LWLock Array from Server Code
Date
Msg-id CAANrPSd+4=3dwvTz=_wW=hbF_LVB7wfS3FzSLzu5UfdifXSmNg@mail.gmail.com
Whole thread Raw
List 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(const char *tranche_name, int num_lwlocks);
LWLockPadded *GetNamedLWLockTranche(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()

  return; /* too late */

which implies that IsUnderPostmaster must be false and lock_named_request_allowed should be true. Thus, I had invoked RequestNamedLWLockTranche before the first call to LWLockShmemSize which sets lock_named_request_allowed = true and  GetNamedLWLockTranche later. This works in the single user mode but fails when I start the server explicitly through postgres -D ...

pgsql-hackers by date:

Previous
From: Justin Pryzby
Date:
Subject: Re: clean up docs for v12
Next
From: Andres Freund
Date:
Subject: Re: Regression test PANICs with master-standby setup on same machine