Re: [PATCHES] libpq events patch (with sgml docs)

Lists: pgsql-hackerspgsql-patches
From: Andrew Chernow <ac(at)esilo(dot)com>
To: "Patches (PostgreSQL)" <pgsql-patches(at)postgresql(dot)org>
Cc: Merlin Moncure <mmoncure(at)gmail(dot)com>
Subject: libpq events patch (with sgml docs)
Date: 2008-09-05 19:14:59
Message-ID: 48C18533.2000204@esilo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

- Added sgml docs.
- Removed the PQpassThroughData and PQresultPassThroughData functions.
- Added an argument to PGEventProc, the passThrough pointer.
- fixed some errors in the code comments due to code shuffles.

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

Attachment Content-Type Size
libpq-events.tgz application/x-compressed 13.2 KB
libpq-events.patch text/plain 51.0 KB

From: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
To: Andrew Chernow <ac(at)esilo(dot)com>
Cc: "Patches (PostgreSQL)" <pgsql-patches(at)postgresql(dot)org>, Merlin Moncure <mmoncure(at)gmail(dot)com>
Subject: Re: libpq events patch (with sgml docs)
Date: 2008-09-05 19:22:15
Message-ID: 20080905192215.GK4353@alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Andrew Chernow escribió:

> ! printfPQExpBuffer(&conn->errorMessage,
> ! libpq_gettext("PGEventProc \"%s\" failed during PGEVT_CONNRESET event\n"),
> ! conn->events[i].name);
> ! else
> ! printfPQExpBuffer(&conn->errorMessage,
> ! libpq_gettext("PGEventProc \"addr:%p\" failed during PGEVT_CONNRESET event\n"),
> ! conn->events[i].proc);
> ! break;

Please don't do this. It creates extra unnecessary work for
translators. Better create a local var, assign either "name" or
"addr:<value>" to it, and then use that in the message.

(For the record, I'd prefer that the name is made mandatory.)

Oh, BTW: don't post to pgsql-patches. It's deprecated. Use
pgsql-hackers instead.

--
Alvaro Herrera http://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.


From: Andrew Chernow <ac(at)esilo(dot)com>
To: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, Merlin Moncure <mmoncure(at)gmail(dot)com>
Subject: Re: [PATCHES] libpq events patch (with sgml docs)
Date: 2008-09-05 19:40:56
Message-ID: 48C18B48.509@esilo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Alvaro Herrera wrote:
> Andrew Chernow escribió:
>
>> ! printfPQExpBuffer(&conn->errorMessage,
>> ! libpq_gettext("PGEventProc \"%s\" failed during PGEVT_CONNRESET event\n"),
>> ! conn->events[i].name);
>> ! else
>> ! printfPQExpBuffer(&conn->errorMessage,
>> ! libpq_gettext("PGEventProc \"addr:%p\" failed during PGEVT_CONNRESET event\n"),
>> ! conn->events[i].proc);
>> ! break;
>
> Please don't do this. It creates extra unnecessary work for
> translators. Better create a local var, assign either "name" or
> "addr:<value>" to it, and then use that in the message.
>
> (For the record, I'd prefer that the name is made mandatory.)
>

The name is now mandatory, no need to toggle the format string anymore.

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

Attachment Content-Type Size
libpq-events.patch text/plain 50.3 KB
libpq-events.tgz application/x-compressed 13.1 KB

From: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
To: Andrew Chernow <ac(at)esilo(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, Merlin Moncure <mmoncure(at)gmail(dot)com>
Subject: Re: [PATCHES] libpq events patch (with sgml docs)
Date: 2008-09-05 19:48:53
Message-ID: 20080905194853.GL4353@alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Andrew Chernow escribió:

> /*
> * PQmakeEmptyPGresult
> * returns a newly allocated, initialized PGresult with given status.
> * If conn is not NULL and status indicates an error, the conn's
> * errorMessage is copied.
> *
> * Note this is exported --- you wouldn't think an application would need
> * to build its own PGresults, but this has proven useful in both libpgtcl
> * and the Perl5 interface, so maybe it's not so unreasonable.
> + *
> + * Updated April 2008 - If conn is not NULL, event states will be copied
> + * from the PGconn to the created PGresult.
> */

Don't do this either. We don't really need to know when the thing was
changed; the comment should just state what the function does. I had
folded the last paragraph into the introductory one, but I think you
lost that part of my change.

> + /* resultalloc the attribute names. The above memcpy has the attr
> + * names pointing at the callers provided attDescs memory.
> + */

"resultalloc"? Why not just "allocate"?

> * PQclear -
> * free's the memory associated with a PGresult
> */

I'd add a comment here stating why the event name is not deallocated;
otherwise it just looks like it's being leaked.

--
Alvaro Herrera http://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.


From: Andrew Chernow <ac(at)esilo(dot)com>
To: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, Merlin Moncure <mmoncure(at)gmail(dot)com>
Subject: Re: [PATCHES] libpq events patch (with sgml docs)
Date: 2008-09-05 20:08:07
Message-ID: 48C191A7.3000205@esilo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Alvaro Herrera wrote:
> Andrew Chernow escribió:
>
>> * and the Perl5 interface, so maybe it's not so unreasonable.
>> + *
>> + * Updated April 2008 - If conn is not NULL, event states will be copied
>> + * from the PGconn to the created PGresult.
>> */
>
> Don't do this either. We don't really need to know when the thing was
>

Changed that and made it one paragraph.

>> + /* resultalloc the attribute names. The above memcpy has the attr
>> + * names pointing at the callers provided attDescs memory.
>> + */
>
> "resultalloc"? Why not just "allocate"?
>

Because resultalloc is what a PGresult uses to allocate its attribute
names (See line 513 of fe-protocol3.c). Also, PQclear frees its memory
blocks, not individual items like attname.

>> * PQclear -
>> * free's the memory associated with a PGresult
>> */
>
> I'd add a comment here stating why the event name is not deallocated;
> otherwise it just looks like it's being leaked.
>
>

The event name is being deallocated.

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

Attachment Content-Type Size
libpq-events.patch text/plain 51.1 KB
libpq-events.tgz application/x-compressed 13.1 KB

From: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
To: Andrew Chernow <ac(at)esilo(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, Merlin Moncure <mmoncure(at)gmail(dot)com>
Subject: Re: [PATCHES] libpq events patch (with sgml docs)
Date: 2008-09-05 20:15:04
Message-ID: 20080905201504.GM4353@alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Andrew Chernow escribió:
> Alvaro Herrera wrote:
>> Andrew Chernow escribió:

>>> * PQclear -
>>> * free's the memory associated with a PGresult
>>> */
>>
>> I'd add a comment here stating why the event name is not deallocated;
>> otherwise it just looks like it's being leaked.
>
> The event name is being deallocated.

Doh! Sorry, you're right. In that case, you're missing a NULL result
check from strdup() in dupEvents() ;-)

--
Alvaro Herrera http://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.


From: Andrew Chernow <ac(at)esilo(dot)com>
To: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, Merlin Moncure <mmoncure(at)gmail(dot)com>
Subject: Re: [PATCHES] libpq events patch (with sgml docs)
Date: 2008-09-05 20:32:25
Message-ID: 48C19759.90402@esilo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Alvaro Herrera wrote:
>
> Doh! Sorry, you're right. In that case, you're missing a NULL result
> check from strdup() in dupEvents() ;-)
>

Missed that one. Good catch :) Update attached.

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

Attachment Content-Type Size
libpq-events.tgz application/x-compressed 13.1 KB
libpq-events.patch text/plain 51.2 KB

From: "David Rowley" <dgrowley(at)gmail(dot)com>
To: "'Alvaro Herrera'" <alvherre(at)commandprompt(dot)com>, "'Andrew Chernow'" <ac(at)esilo(dot)com>
Cc: "'Patches \(PostgreSQL\)'" <pgsql-patches(at)postgresql(dot)org>, "'Merlin Moncure'" <mmoncure(at)gmail(dot)com>
Subject: Re: libpq events patch (with sgml docs)
Date: 2008-09-05 20:48:27
Message-ID: A4AE6A69E22E4E97A8629E610B32D08F@amd64
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Alvaro Herrera wrote:
>Oh, BTW: don't post to pgsql-patches. It's deprecated. Use
> pgsql-hackers instead.

I thought this too until I read
http://wiki.postgresql.org/wiki/Submitting_a_Patch

Which is correct?

David.


From: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
To: David Rowley <dgrowley(at)gmail(dot)com>
Cc: "'Andrew Chernow'" <ac(at)esilo(dot)com>, "'Patches (PostgreSQL)'" <pgsql-patches(at)postgresql(dot)org>, "'Merlin Moncure'" <mmoncure(at)gmail(dot)com>
Subject: Re: libpq events patch (with sgml docs)
Date: 2008-09-05 20:59:36
Message-ID: 20080905205936.GN4353@alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

David Rowley escribió:
> Alvaro Herrera wrote:
> >Oh, BTW: don't post to pgsql-patches. It's deprecated. Use
> > pgsql-hackers instead.
>
> I thought this too until I read
> http://wiki.postgresql.org/wiki/Submitting_a_Patch
>
> Which is correct?

I just updated that page and the developer's FAQ to meet the current
reality.

--
Alvaro Herrera http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Andrew Chernow <ac(at)esilo(dot)com>
Cc: Alvaro Herrera <alvherre(at)commandprompt(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, Merlin Moncure <mmoncure(at)gmail(dot)com>
Subject: Re: [PATCHES] libpq events patch (with sgml docs)
Date: 2008-09-17 02:42:06
Message-ID: 27615.1221619326@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Andrew Chernow <ac(at)esilo(dot)com> writes:
> Missed that one. Good catch :) Update attached.

Looking at this now. Question: why does PQgetResult invoke the
RESULTCREATE event only for non-error results? This seems a rather
odd asymmetry, particularly in view of the fact that a RESULTDESTROY
event will occur for error results. And surely we do not need to
micro-optimize error cases for speed.

regards, tom lane


From: Andrew Chernow <ac(at)esilo(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Alvaro Herrera <alvherre(at)commandprompt(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, Merlin Moncure <mmoncure(at)gmail(dot)com>
Subject: Re: [PATCHES] libpq events patch (with sgml docs)
Date: 2008-09-17 03:00:51
Message-ID: 48D072E3.6010703@esilo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Tom Lane wrote:
> Andrew Chernow <ac(at)esilo(dot)com> writes:
>> Missed that one. Good catch :) Update attached.
>
> Looking at this now. Question: why does PQgetResult invoke the
> RESULTCREATE event only for non-error results?

It didn't seem useful to have the eventproc implementation allocate its private
storage (or do whatever prep work it does), just to have it PQclear'd once the
user gets the dead result back. I guess we figured an error result typically
has a short life-span, not very useful outside of indicating an error.

Is there a use case you think requires the opposite behavior?

> odd asymmetry, particularly in view of the fact that a RESULTDESTROY
> event will occur for error results. And surely we do not need to
> micro-optimize error cases for speed.
>

It is odd. Actually, it looks like a bug to me. PQgetResult is the behavior we
were after, don't trigger the event if the creation failed. Same thing occurs
during a conn reset. Looks like PQclear needs to check resultStatus before it
triggers RESULTDESTROY events.

But before I fix this and put a patch up, please let me know if you prefer the
opposite behavior ... trigger events on success or failure (including connreset).

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


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Andrew Chernow <ac(at)esilo(dot)com>
Cc: Alvaro Herrera <alvherre(at)commandprompt(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, Merlin Moncure <mmoncure(at)gmail(dot)com>
Subject: Re: [PATCHES] libpq events patch (with sgml docs)
Date: 2008-09-17 03:40:17
Message-ID: 28673.1221622817@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Andrew Chernow <ac(at)esilo(dot)com> writes:
> Tom Lane wrote:
>> Looking at this now. Question: why does PQgetResult invoke the
>> RESULTCREATE event only for non-error results?

> It didn't seem useful to have the eventproc implementation allocate its private
> storage (or do whatever prep work it does), just to have it PQclear'd once the
> user gets the dead result back. I guess we figured an error result typically
> has a short life-span, not very useful outside of indicating an error.

Well, you could do a PQresultStatus and skip any prep work if you
actually saw a need to micro-optimize such cases.

> It is odd. Actually, it looks like a bug to me. PQgetResult is the
> behavior we were after, don't trigger the event if the creation
> failed. Same thing occurs during a conn reset. Looks like PQclear
> needs to check resultStatus before it triggers RESULTDESTROY events.

If you did that, then you WOULD have a bug. Consider case where you
successfully init two events, and the third one fails. You'll now
change the result's status to ERROR. If you don't RESULTDESTROY
then the first two events will leak whatever storage they allocated.

The reason I suggested not being conditional about the init call was
to reduce the probability of bugs of similar ilks associated with
an event proc assuming that it could only get a DESTROY call for
something it had seen CREATEd --- for example, if it were frobbing
a reference count for some long-lived data, it could very easily
screw up the reference count that way. I suppose that the risk of
an earlier event proc failing means it has to cope with that case
anyway, but I don't think it's a particularly good idea to have
arbitrary asymmetries increasing the odds of a problem.

regards, tom lane


From: Andrew Chernow <ac(at)esilo(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Alvaro Herrera <alvherre(at)commandprompt(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, Merlin Moncure <mmoncure(at)gmail(dot)com>
Subject: Re: [PATCHES] libpq events patch (with sgml docs)
Date: 2008-09-17 03:59:44
Message-ID: 48D080B0.6070104@esilo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Tom Lane wrote:
>> It is odd. Actually, it looks like a bug to me. PQgetResult is the
>> behavior we were after, don't trigger the event if the creation
>> failed. Same thing occurs during a conn reset. Looks like PQclear
>> needs to check resultStatus before it triggers RESULTDESTROY events.
>
> If you did that, then you WOULD have a bug. Consider case where you
> successfully init two events, and the third one fails. You'll now
> change the result's status to ERROR. If you don't RESULTDESTROY
> then the first two events will leak whatever storage they allocated.
>
> The reason I suggested not being conditional about the init call was
> to reduce the probability of bugs of similar ilks associated with
> an event proc assuming that it could only get a DESTROY call for
> something it had seen CREATEd --- for example, if it were frobbing
> a reference count for some long-lived data, it could very easily
> screw up the reference count that way. I suppose that the risk of
> an earlier event proc failing means it has to cope with that case
> anyway, but I don't think it's a particularly good idea to have
> arbitrary asymmetries increasing the odds of a problem.
>
> regards, tom lane
>
>

Yeah. Good point. I fixed it to always fire events.

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

Attachment Content-Type Size
libpq-events.tgz application/x-compressed 13.1 KB
libpq-events.patch text/plain 51.0 KB

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Andrew Chernow <ac(at)esilo(dot)com>
Cc: Alvaro Herrera <alvherre(at)commandprompt(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, Merlin Moncure <mmoncure(at)gmail(dot)com>
Subject: Re: [PATCHES] libpq events patch (with sgml docs)
Date: 2008-09-17 04:36:53
Message-ID: 454.1221626213@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Andrew Chernow <ac(at)esilo(dot)com> writes:
> Yeah. Good point. I fixed it to always fire events.

Applied with editorial revisions --- I don't think I changed any
functionality, but I fixed a number of corner-case bugs and
editorialized on style a bit.

The general question of symmetry between RESULTCREATE and RESULTDESTROY
callbacks is still bothering me. As committed, PQmakeEmptyPGresult
will copy events into its result, but not fire RESULTCREATE for them
... but they'll get RESULTDESTROY when it's deleted. Is that what we
want? I don't have a lot of faith that PQgetResult is the only place
inside libpq that needs to fire RESULTCREATE, either.

Now, it's questionable how tense we need to be about that as long as
event proc failure aborts calling of later event procs. That means
that procs have to be robust against getting DESTROY with no CREATE
calls in any case. Should we try to make that less uncertain?

regards, tom lane


From: Andrew Chernow <ac(at)esilo(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Alvaro Herrera <alvherre(at)commandprompt(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, Merlin Moncure <mmoncure(at)gmail(dot)com>
Subject: Re: [PATCHES] libpq events patch (with sgml docs)
Date: 2008-09-17 10:45:18
Message-ID: 48D0DFBE.9050900@esilo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

> Now, it's questionable how tense we need to be about that as long as
> event proc failure aborts calling of later event procs. That means
> that procs have to be robust against getting DESTROY with no CREATE
> calls in any case. Should we try to make that less uncertain?
>
>

I attached a patch that adds a 'needDestroy' member to PGEvent It is set when
resultcreate or resultcopy succeeds and checked during a PQclear. That *should*
resolve the issue of "no resultcreate but gets a resultdestroy".

> The general question of symmetry between RESULTCREATE and RESULTDESTROY
> callbacks is still bothering me. As committed, PQmakeEmptyPGresult
> will copy events into its result, but not fire RESULTCREATE for them
> ... but they'll get RESULTDESTROY when it's deleted. Is that what we
> want?

PQmakeEmptyPGResult was given thought. The problem is every internal function
that generates a result calls PQmakeEmptyPGResult, but those cases should not
fire a resultcreate. resultcreate should be called when the result is fully
constructed (tuples and all) so the eventproc gets a useful PGresult.

One solution is to do something like the below:

PGresult *
PQmakeEmptyPGresult(PGconn *conn, ExecStatusType status)
{
return pqMakeEmptyPGresult(conn, status, TRUE);
}

PGresult *
pqMakeEmptyPGresult(PGconn *conn, ExecStatusType status, int fireEvents)
{
// existing function, only change is handling fireEvents
}

I am willing to create a patch for this. Is this an acceptable idea?

> I don't have a lot of faith that PQgetResult is the only place
> inside libpq that needs to fire RESULTCREATE, either.
>

I looked again and I didn't see anything. Is there something your thinking of?
ISTM that PQgetResult is called every where a result is created (outside of
PQmakeEmptyPGresult).

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

Attachment Content-Type Size
pgevent.patch text/x-patch 3.4 KB

From: Andrew Chernow <ac(at)esilo(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Alvaro Herrera <alvherre(at)commandprompt(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, Merlin Moncure <mmoncure(at)gmail(dot)com>
Subject: Re: [PATCHES] libpq events patch (with sgml docs)
Date: 2008-09-17 10:50:16
Message-ID: 48D0E0E8.5070301@esilo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Andrew Chernow wrote:
> > Now, it's questionable how tense we need to be about that as long as
> > event proc failure aborts calling of later event procs. That means
> > that procs have to be robust against getting DESTROY with no CREATE
> > calls in any case. Should we try to make that less uncertain?
> >
> >
>
> I attached a patch that adds a 'needDestroy' member to PGEvent It is
> set when resultcreate or resultcopy succeeds and checked during a
> PQclear. That *should* resolve the issue of "no resultcreate but gets a
> resultdestroy".
>
>

Shoot. I have a booboo in that last patch. Attached is the corrected version.

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

Attachment Content-Type Size
pgevent.patch text/x-patch 3.5 KB

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Andrew Chernow <ac(at)esilo(dot)com>
Cc: Alvaro Herrera <alvherre(at)commandprompt(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, Merlin Moncure <mmoncure(at)gmail(dot)com>
Subject: Re: [PATCHES] libpq events patch (with sgml docs)
Date: 2008-09-17 12:16:52
Message-ID: 8872.1221653812@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Andrew Chernow <ac(at)esilo(dot)com> writes:
>>> Now, it's questionable how tense we need to be about that as long as
>>> event proc failure aborts calling of later event procs. That means
>>> that procs have to be robust against getting DESTROY with no CREATE
>>> calls in any case. Should we try to make that less uncertain?

> I attached a patch that adds a 'needDestroy' member to PGEvent It is
> set when resultcreate or resultcopy succeeds and checked during a
> PQclear. That *should* resolve the issue of "no resultcreate but gets
> a resultdestroy".

Some thought would need to be given to how that interacts with
RESULTCOPY. Presumably on the destination side, RESULTCOPY is the
equivalent of RESULTCREATE, ie, don't DESTROY if you didn't get COPY.
But what of the source side? Arguably you shouldn't invoke COPY on
events that were never initialized in this object.

I also think that a little bit of thought should go into whether or
not to call DESTROY on an event that *did* get a CREATE and failed it.
You could argue that one either way: should a failing CREATE operation
be expected to fully clean up after itself, or should it be expected
to leave things in a state where DESTROY can clean up properly?
I'm not entirely sure, but option A might force duplication of code
between CREATE's failure path and DESTROY. Whichever semantics we
choose needs to be documented.

Also, if we choose option B, then the same would hold for REGISTER
versus CONNDESTROY: failing REGISTER should still mean that you get
a CONNDESTROY. So maybe that's an argument for option A, because
that's how REGISTER works now.

Lastly, the idea that was in the back of my mind was to resolve this
issue by unconditionally calling all the event procs at CREATE time,
not by cutting off the later ones if an earlier one failed. Again,
I do not see a performance argument for skipping the extra steps,
and it seems to me that it might improve symmetry/robustness.
I'm not necessarily wedded to that approach but it bears thinking
about.

regards, tom lane


From: Andrew Chernow <ac(at)esilo(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Alvaro Herrera <alvherre(at)commandprompt(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, Merlin Moncure <mmoncure(at)gmail(dot)com>
Subject: Re: [PATCHES] libpq events patch (with sgml docs)
Date: 2008-09-17 13:20:29
Message-ID: 48D1041D.5070808@esilo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Tom Lane wrote:
>
> Some thought would need to be given to how that interacts with
> RESULTCOPY. Presumably on the destination side, RESULTCOPY is the
> equivalent of RESULTCREATE, ie, don't DESTROY if you didn't get COPY.
> But what of the source side? Arguably you shouldn't invoke COPY on
> events that were never initialized in this object.
>

You are correct. The resultcopy function needs to check if the src
result eventproc was initialized. BUT, that should not be possible
unless someone is not checking return values. Meaning, the only way to
have an uninitialized eventproc in this instance is if something failed
during a resultcreate. Actually, if you call PQmakeEmptyPGResult then
you can also run into this problem. That can be solved by adding an
argument to makeResult as I previously suggested.

> I also think that a little bit of thought should go into whether or
> not to call DESTROY on an event that *did* get a CREATE and failed it.
> You could argue that one either way: should a failing CREATE operation
> be expected to fully clean up after itself, or should it be expected
> to leave things in a state where DESTROY can clean up properly?
> I'm not entirely sure, but option A might force duplication of code
> between CREATE's failure path and DESTROY. Whichever semantics we
> choose needs to be documented.
>

If a resultcreate fails, than I think that resultdestroy should not be
delivered to that eventproc (same for resultcopy). That is how register
works and how I saw this patch working (eventhough it appears I have a
few logical errors). I don't think it makes sense to do it otherwise,
it would be like calling free after a malloc failure.

The needDestroy member should be called resultInitialized. Although the
conn doesn't reference the 'resultInitialized' member, I should
initialize it to FALSE. I did not do this in the last patch ...
register function.

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


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Andrew Chernow <ac(at)esilo(dot)com>
Cc: Alvaro Herrera <alvherre(at)commandprompt(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, Merlin Moncure <mmoncure(at)gmail(dot)com>
Subject: Re: [PATCHES] libpq events patch (with sgml docs)
Date: 2008-09-17 13:36:26
Message-ID: 10839.1221658586@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Andrew Chernow <ac(at)esilo(dot)com> writes:
> Tom Lane wrote:
>> Some thought would need to be given to how that interacts with
>> RESULTCOPY. Presumably on the destination side, RESULTCOPY is the
>> equivalent of RESULTCREATE, ie, don't DESTROY if you didn't get COPY.
>> But what of the source side? Arguably you shouldn't invoke COPY on
>> events that were never initialized in this object.

> You are correct. The resultcopy function needs to check if the src
> result eventproc was initialized. BUT, that should not be possible
> unless someone is not checking return values. Meaning, the only way to
> have an uninitialized eventproc in this instance is if something failed
> during a resultcreate. Actually, if you call PQmakeEmptyPGResult then
> you can also run into this problem. That can be solved by adding an
> argument to makeResult as I previously suggested.

I still think it would be a good idea to expend a couple more lines in
PQcopyResult to cover the case --- the likelihood of there being code
paths that make an empty result and never invoke RESULTCREATE just seems
too high. Defensive programming 'n all that. In any case I'm not
convinced that we should force a RESULTCREATE cycle on external callers
of PQmakeEmptyPGResult. If you guys didn't see a need for it in your
development then it probably doesn't exist.

> If a resultcreate fails, than I think that resultdestroy should not be
> delivered to that eventproc (same for resultcopy). That is how register
> works and how I saw this patch working (eventhough it appears I have a
> few logical errors). I don't think it makes sense to do it otherwise,
> it would be like calling free after a malloc failure.

I can live with that definition, but please document it.

> The needDestroy member should be called resultInitialized.

Yeah, probably, so that you can set it FALSE in conn events and continue
to use memcpy to move things over.

regards, tom lane


From: Andrew Chernow <ac(at)esilo(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Alvaro Herrera <alvherre(at)commandprompt(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, Merlin Moncure <mmoncure(at)gmail(dot)com>
Subject: Re: [PATCHES] libpq events patch (with sgml docs)
Date: 2008-09-17 14:29:23
Message-ID: 48D11443.4010608@esilo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

New patch following our discussion with updated docs.

>> few logical errors). I don't think it makes sense to do it otherwise,
>> it would be like calling free after a malloc failure.
>
> I can live with that definition, but please document it.
>
>

To build on this analogy, PGEVT_CONNRESET is like a realloc. Meaning,
the initial malloc "PGEVT_REGISTER" worked by the realloc
"PGEVT_CONNRESET" didn't ... you still have free "PGEVT_CONNDESTROY" the
initial. Its documented that way. Basically if a register succeeds, a
destroy will always be sent regardless of what happens with a reset.

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

Attachment Content-Type Size
libpq-events.patch text/plain 51.0 KB

From: Andrew Chernow <ac(at)esilo(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Alvaro Herrera <alvherre(at)commandprompt(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, Merlin Moncure <mmoncure(at)gmail(dot)com>
Subject: Re: [PATCHES] libpq events patch (with sgml docs)
Date: 2008-09-17 14:37:37
Message-ID: 48D11631.8070709@esilo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Andrew Chernow wrote:
> New patch following our discussion with updated docs.
>
>>> few logical errors). I don't think it makes sense to do it
>>> otherwise, it would be like calling free after a malloc failure.
>>
>> I can live with that definition, but please document it.
>>
>>
>
> To build on this analogy, PGEVT_CONNRESET is like a realloc. Meaning,
> the initial malloc "PGEVT_REGISTER" worked by the realloc
> "PGEVT_CONNRESET" didn't ... you still have free "PGEVT_CONNDESTROY" the
> initial. Its documented that way. Basically if a register succeeds, a
> destroy will always be sent regardless of what happens with a reset.
>
>

I attached the wrong patch. I'm sorry.

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

Attachment Content-Type Size
pgevents.patch text/plain 11.6 KB

From: Andrew Chernow <ac(at)esilo(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Alvaro Herrera <alvherre(at)commandprompt(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, Merlin Moncure <mmoncure(at)gmail(dot)com>
Subject: Re: [PATCHES] libpq events patch (with sgml docs)
Date: 2008-09-19 13:15:28
Message-ID: 48D3A5F0.2020702@esilo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Are there any plans to commit these libpq-events changes this fest?

http://archives.postgresql.org/pgsql-hackers/2008-09/msg01109.php

I wanted to release an updated libpqtypes but am waiting on the above
patch. If not, I'll release it now.

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


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Andrew Chernow <ac(at)esilo(dot)com>
Cc: Alvaro Herrera <alvherre(at)commandprompt(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, Merlin Moncure <mmoncure(at)gmail(dot)com>
Subject: Re: [PATCHES] libpq events patch (with sgml docs)
Date: 2008-09-19 13:50:42
Message-ID: 23506.1221832242@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Andrew Chernow <ac(at)esilo(dot)com> writes:
> Are there any plans to commit these libpq-events changes this fest?

Sorry about that, I got distracted. Will look at it shortly.

regards, tom lane


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Andrew Chernow <ac(at)esilo(dot)com>
Cc: Alvaro Herrera <alvherre(at)commandprompt(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, Merlin Moncure <mmoncure(at)gmail(dot)com>
Subject: Re: [PATCHES] libpq events patch (with sgml docs)
Date: 2008-09-19 16:11:02
Message-ID: 28666.1221840662@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Andrew Chernow <ac(at)esilo(dot)com> writes:
>> To build on this analogy, PGEVT_CONNRESET is like a realloc. Meaning,
>> the initial malloc "PGEVT_REGISTER" worked by the realloc
>> "PGEVT_CONNRESET" didn't ... you still have free "PGEVT_CONNDESTROY" the
>> initial. Its documented that way. Basically if a register succeeds, a
>> destroy will always be sent regardless of what happens with a reset.

> I attached the wrong patch. I'm sorry.

I had a further thought about this: after applying this patch, it is
essentially useless for the exposed PQmakeEmptyPGresult function to
copy events into the result. If it doesn't give them a RESULTCREATE
call, then they cannot receive RESULTCOPY or RESULTDESTROY either,
so they might as well not be there.

The argument for not having PQmakeEmptyPGresult fire RESULTCREATE still
makes sense, but I am thinking that maybe what we ought to do is expose
a new function named something like PQfireResultCreateEvents() that just
does that. This would allow an application to exactly emulate what
PQgetResult does: make an empty PGresult, fill it, then fire the create
events.

I'll go ahead and apply this patch in a little bit, but if you concur
with the above reasoning, please put together a followon patch to add
such a function.

regards, tom lane


From: Andrew Chernow <ac(at)esilo(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Alvaro Herrera <alvherre(at)commandprompt(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, Merlin Moncure <mmoncure(at)gmail(dot)com>
Subject: Re: [PATCHES] libpq events patch (with sgml docs)
Date: 2008-09-19 18:14:04
Message-ID: 48D3EBEC.1040503@esilo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Tom Lane wrote:
>
> I'll go ahead and apply this patch in a little bit, but if you concur
> with the above reasoning, please put together a followon patch to add
> such a function.
>
> regards, tom lane
>
>

I attached a patch. You have to copy the events in PQmakeEmptyPGResult
because there is no where else to do this, other than copyresult but
that is different because it copies from a result not a conn.

PQmakeEmptyPGResult - must copy events here
PQsetResultAttrs - set attributes
PQsetvalue - set tuple values
PQfireResultCreateEvents(conn,res) - now fire resultcreate event

PQgetResult now calls PQfireResultCreateEvents.

BTW, the event system might be an alternative solution for PGNoticeHooks
(PGEVT_NOTICE).

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

Attachment Content-Type Size
pgevents.patch text/plain 7.3 KB

From: "Merlin Moncure" <mmoncure(at)gmail(dot)com>
To: "Andrew Chernow" <ac(at)esilo(dot)com>
Cc: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "Alvaro Herrera" <alvherre(at)commandprompt(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCHES] libpq events patch (with sgml docs)
Date: 2008-09-19 18:39:27
Message-ID: b42b73150809191139r72a0e87av2cebf8812baae984@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

On Fri, Sep 19, 2008 at 2:14 PM, Andrew Chernow <ac(at)esilo(dot)com> wrote:
>
> BTW, the event system might be an alternative solution for PGNoticeHooks
> (PGEVT_NOTICE).
>

Another possible use of the event hooks -- just spitballing here -- is
to generate an event when a notification comes through (you would
still receive events the old way., by command or PQconsumeInput).
Maybe this would eventually replace the current notification interface
(wasn't this going to be changed anyways?)

merlin


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Andrew Chernow <ac(at)esilo(dot)com>
Cc: Alvaro Herrera <alvherre(at)commandprompt(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, Merlin Moncure <mmoncure(at)gmail(dot)com>
Subject: Re: [PATCHES] libpq events patch (with sgml docs)
Date: 2008-09-19 19:43:58
Message-ID: 23044.1221853438@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

BTW, why are all the conn parameters to events declared "const"? Isn't
the reason for passing them in mainly to give the event proc a chance
to issue queries?

regards, tom lane


From: Andrew Chernow <ac(at)esilo(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Alvaro Herrera <alvherre(at)commandprompt(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, Merlin Moncure <mmoncure(at)gmail(dot)com>
Subject: Re: [PATCHES] libpq events patch (with sgml docs)
Date: 2008-09-19 19:50:38
Message-ID: 48D4028E.4060306@esilo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Tom Lane wrote:
> BTW, why are all the conn parameters to events declared "const"? Isn't

Because it looked prettier? Kidding. No idea, do you want me to change
that or do you want to?

> the reason for passing them in mainly to give the event proc a chance
> to issue queries?
>
>

Partly. You also want to give the eventproc a chance to issue a
PQinstanceData call, so it can copy stuff to the created result.

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


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Andrew Chernow <ac(at)esilo(dot)com>
Cc: Alvaro Herrera <alvherre(at)commandprompt(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, Merlin Moncure <mmoncure(at)gmail(dot)com>
Subject: Re: [PATCHES] libpq events patch (with sgml docs)
Date: 2008-09-19 19:54:39
Message-ID: 24143.1221854079@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Andrew Chernow <ac(at)esilo(dot)com> writes:
> Tom Lane wrote:
>> BTW, why are all the conn parameters to events declared "const"? Isn't

> Because it looked prettier? Kidding. No idea, do you want me to change
> that or do you want to?

I'll fix it; it's hardly worth passing a patch around for.

regards, tom lane


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Andrew Chernow <ac(at)esilo(dot)com>
Cc: Alvaro Herrera <alvherre(at)commandprompt(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, Merlin Moncure <mmoncure(at)gmail(dot)com>
Subject: Re: [PATCHES] libpq events patch (with sgml docs)
Date: 2008-09-19 20:08:11
Message-ID: 25135.1221854891@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Andrew Chernow <ac(at)esilo(dot)com> writes:
> I attached a patch. You have to copy the events in PQmakeEmptyPGResult
> because there is no where else to do this, other than copyresult but
> that is different because it copies from a result not a conn.

Applied ...

> PQgetResult now calls PQfireResultCreateEvents.

... except I didn't do that because the error handling didn't seem
appropriate. Since PQmakeEmptyPGResult allows a null conn,
PQfireResultCreateEvents ought to as well. So I just made it return
false on failure.

regards, tom lane


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Merlin Moncure" <mmoncure(at)gmail(dot)com>
Cc: "Andrew Chernow" <ac(at)esilo(dot)com>, "Alvaro Herrera" <alvherre(at)commandprompt(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCHES] libpq events patch (with sgml docs)
Date: 2008-09-19 20:14:16
Message-ID: 25233.1221855256@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

"Merlin Moncure" <mmoncure(at)gmail(dot)com> writes:
> On Fri, Sep 19, 2008 at 2:14 PM, Andrew Chernow <ac(at)esilo(dot)com> wrote:
>> BTW, the event system might be an alternative solution for PGNoticeHooks
>> (PGEVT_NOTICE).

> Another possible use of the event hooks -- just spitballing here -- is
> to generate an event when a notification comes through (you would
> still receive events the old way., by command or PQconsumeInput).

Seems rather pointless; you'd just be adding multiple ways to do things
we can do perfectly well now.

> Maybe this would eventually replace the current notification interface
> (wasn't this going to be changed anyways?)

No, I don't think anyone was unhappy with the libpq API for it.

regards, tom lane