Re: libpq object hooks patch

From: Andrew Chernow <ac(at)esilo(dot)com>
To: pgsql-patches(at)postgresql(dot)org
Cc: Merlin Moncure <mmoncure(at)gmail(dot)com>
Subject: Re: libpq object hooks patch
Date: 2008-04-16 01:42:36
Message-ID: 4805598C.2060904@esilo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-patches

Andrew Chernow wrote:
> Here is an updated version of the object hooks patch. It now supports a
> list of hooks for a PGconn, and PGresult. This had to re-introduce the
> concept of hook name. Being that there is now a list, you need a way to
> reference an item of that list.
>
> Also added PQobjectHooks and PQresultObjectHooks, to get a pointer to
> the conn or result hook list. PQmakeResult must allow the ability to
> pass a list of object hooks in. So, PQresultObjectHooks was born.
> pqtypes doesn't need (at least at this time) PQobjectHooks but leaving
> it out felt unbalanced.
>
> Note: PQhookData and PQresultHookData can be removed. There
> functionality can be reproduced by an API user issuing PQobjectHooks or
> PQresultObjectHooks and manually looking for there hook (normaly to get
> at the hook->data). Basically, an API user would do themselves what
> PQhookData is doing.
>
>

Made some changes:

1. Removed the hookName argument to PQaddObjectHooks, since its in the
supplied PQobjectHooks struct. I think the argument was lingering from
a previous patch.

2. Added the ability to install global object hooks:
PQaddGlobalObjectHooks(PGobjectHooks*). The header docs for this
function warns that it should only be used before calling libpq
functions or creating application threads. There are no management
functions for global hooks, like get or remove. If you add global
object hooks, your stuck with them until process death.

3. There is a new internal pqInitObjectHooks(PGconn *) that installs the
global object hooks on new conns in the CONNECTION_OK status. I call
this function within PQconnectPoll (3 different locations). This will
call PQaddObjectHooks(conn) for each global hook (so global hooks are
always at the front of a conn's hook list). pqInitObjectHooks checks to
see if conn->objHooksCount > 0 and if it is, the request is ignored and
the function returns success. This only happens during a PQreset and
PQresetPoll.

// global
PQaddGlobalObjectHooks(&libpq_debugger_hook);

// per-conn
PQaddObjectHooks(conn, &session_manager_hook);

Since the existing list of object hooks is scanned for duplicate names
when adding them, you will never run into duplicate object hooks in a
connection (or in the global list). If the two examples above were both
called by an application, the per-conn call would fail.

--
Andrew Chernow
eSilo, LLC
every bit counts
http://www.esilo.com/

Attachment Content-Type Size
object_hooks.patch text/plain 29.3 KB

In response to

Browse pgsql-patches by date

  From Date Subject
Next Message ITAGAKI Takahiro 2008-04-16 04:22:13 Re: Sorting writes during checkpoint
Previous Message Euler Taveira de Oliveira 2008-04-15 19:26:06 Re: lc_time and localized dates