Re: Initializing LWLock Array from Server Code

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Souvik Bhattacherjee <kivuosb(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Initializing LWLock Array from Server Code
Date: 2019-05-01 00:35:04
Message-ID: CA+TgmoaszEBoPFxqLkKsXUROwmVoc=pQRiajKpY=LZ=cARdQMA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)gmail(dot)com> wrote:
>
> On Fri, Apr 26, 2019 at 2:58 PM Souvik Bhattacherjee <kivuosb(at)gmail(dot)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 pointers would 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

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Noah Misch 2019-05-01 00:57:11 Re: [HACKERS] Weaker shmem interlock w/o postmaster.pid
Previous Message Robert Haas 2019-05-01 00:32:28 Re: POC: Cleaning up orphaned files using undo logs