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

From Robert Haas
Subject Re: Initializing LWLock Array from Server Code
Date
Msg-id CA+TgmoaszEBoPFxqLkKsXUROwmVoc=pQRiajKpY=LZ=cARdQMA@mail.gmail.com
Whole thread Raw
In response to Initializing LWLock Array from Server Code  (Souvik Bhattacherjee <kivuosb@gmail.com>)
List pgsql-hackers
Replying to myself to resend to the list, since my previous attempt
seems to have been eaten by a grue.

On Mon, Apr 29, 2019 at 1:59 PM Robert Haas <robertmhaas@gmail.com> wrote:
>
> On Fri, Apr 26, 2019 at 2:58 PM Souvik Bhattacherjee <kivuosb@gmail.com> wrote:
> > 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
pointerswould be appreciated.
 
>
> RequestNamedLWLockTranche() changes the behavior of LWLockShmemSize()
> and CreateLWLocks(), so must be called before either of those.
> GetNamedLWLockTranche() must be called after CreateLWLocks().
>
> This machinery works for pg_stat_statements, so see that as an example
> of how to make this work from an extension.  If you're hacking the
> core server code, then look at the places where the corresponding bits
> of pg_stat_statements code get called.  IIRC, _PG_init() gets called
> from process_shared_preload_libraries(), so you might look at the
> placement of the calls to that function.
>
> --
> Robert Haas
> EnterpriseDB: http://www.enterprisedb.com
> The Enterprise PostgreSQL Company



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



pgsql-hackers by date:

Previous
From: Robert Haas
Date:
Subject: Re: POC: Cleaning up orphaned files using undo logs
Next
From: Noah Misch
Date:
Subject: Re: [HACKERS] Weaker shmem interlock w/o postmaster.pid