Re: query cancel issues in contrib/dblink

Lists: pgsql-hackers
From: Itagaki Takahiro <itagaki(dot)takahiro(at)oss(dot)ntt(dot)co(dot)jp>
To: pgsql-hackers(at)postgresql(dot)org
Subject: query cancel issues in contrib/dblink
Date: 2009-06-26 02:41:37
Message-ID: 20090626100150.9ABF.52131E4D@oss.ntt.co.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hi,

contrib/dblink seems to have no treatments for query cancels.
It causes the following issues:

(1) Users need to wait for completion of remote query.
Requests for query cancel won't be delivered to remote servers.

(2) PGresult objects will be memory leak. The result is not released
when query is cancelled; it is released only when dblink function
is called max_calls times.

They are long standing issues (not only in 8.4),
but I hope we will fix them to make dblink more robust.

For (1), asynchronous libpq functions should be used instead of blocking
ones, and wait for the remote query using a loop with CHECK_FOR_INTERRUPTS().
For (2), we might need to store PGresult not only in funcctx->user_fctx
but also in a global list, and free all results in XactCallback if remain.

Comments welcome.

Regards,
---
ITAGAKI Takahiro
NTT Open Source Software Center


From: Merlin Moncure <mmoncure(at)gmail(dot)com>
To: Itagaki Takahiro <itagaki(dot)takahiro(at)oss(dot)ntt(dot)co(dot)jp>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: query cancel issues in contrib/dblink
Date: 2009-06-26 14:00:20
Message-ID: b42b73150906260700h5d09593fx18afb1f9524329a5@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, Jun 25, 2009 at 10:41 PM, Itagaki
Takahiro<itagaki(dot)takahiro(at)oss(dot)ntt(dot)co(dot)jp> wrote:
> Hi,
>
> contrib/dblink seems to have no treatments for query cancels.
> It causes the following issues:
>
> (1) Users need to wait for completion of remote query.
>    Requests for query cancel won't be delivered to remote servers.
>
> (2) PGresult objects will be memory leak. The result is not released
>    when query is cancelled; it is released only when dblink function
>    is called max_calls times.
>
> They are long standing issues (not only in 8.4),
> but I hope we will fix them to make dblink more robust.
>
> For (1), asynchronous libpq functions should be used instead of blocking
> ones, and wait for the remote query using a loop with CHECK_FOR_INTERRUPTS().

How would you structure this loop exactly?

merlin


From: Itagaki Takahiro <itagaki(dot)takahiro(at)oss(dot)ntt(dot)co(dot)jp>
To: pgsql-hackers(at)postgresql(dot)org, Merlin Moncure <mmoncure(at)gmail(dot)com>
Subject: Re: query cancel issues in contrib/dblink
Date: 2009-06-29 03:42:16
Message-ID: 20090629123230.AD52.52131E4D@oss.ntt.co.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers


Merlin Moncure <mmoncure(at)gmail(dot)com> wrote:

> Takahiro<itagaki(dot)takahiro(at)oss(dot)ntt(dot)co(dot)jp> wrote:
> > contrib/dblink seems to have no treatments for query cancels.
> > (1) Users need to wait for completion of remote query.
> > (2) PGresult objects will be memory leak.

Here is a patch to fix the issues. I hope the fixes will be ported
to older versions if possible.

(1) is fixed by using non-blocking APIs in libpq. I think we should
always use non-blocking APIs even if the dblink function itself is
a blocking-function.

(2) is fixed by RegisterXactCallback(AtEOXact_dblink). However, there
might be any better solutions -- for example, ResourceOwner framework.

> > For (1), asynchronous libpq functions should be used instead of blocking
> > ones, and wait for the remote query using a loop with CHECK_FOR_INTERRUPTS().
>
> How would you structure this loop exactly?

Please check execute_query() and wait_for_result() in the patch.

Regards,
---
ITAGAKI Takahiro
NTT Open Source Software Center

Attachment Content-Type Size
dblink.patch application/octet-stream 6.3 KB

From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Joe Conway <mail(at)joeconway(dot)com>, Itagaki Takahiro <itagaki(dot)takahiro(at)oss(dot)ntt(dot)co(dot)jp>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: query cancel issues in contrib/dblink
Date: 2009-09-16 01:43:50
Message-ID: 20090916014350.GW17756@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Joe, Itagaki,

Can you provide an update on this patch? Joe, you were going to
review and possibly commit it. Itagaki, did you have a new version?
Are there any outstanding issues?

Thanks,

Stephen


From: Itagaki Takahiro <itagaki(dot)takahiro(at)oss(dot)ntt(dot)co(dot)jp>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Joe Conway <mail(at)joeconway(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: query cancel issues in contrib/dblink
Date: 2009-09-16 04:06:57
Message-ID: 20090916125247.8F34.52131E4D@oss.ntt.co.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers


Stephen Frost <sfrost(at)snowman(dot)net> wrote:

> Can you provide an update on this patch? Joe, you were going to
> review and possibly commit it. Itagaki, did you have a new version?
> Are there any outstanding issues?

Thanks for your reviewing.
Here is an updated version. I fixed some bugs:

* Fix connection leak on cancel. In the previous patch, running
transactions are canceled, but the temporary connection was leaked.
* Discard all pending results on cancel handler. I implemented
PQexec-compatible behavior with async APIs.

Regards,
---
ITAGAKI Takahiro
NTT Open Source Software Center

Attachment Content-Type Size
dblink_20090916.diff application/octet-stream 8.0 KB

From: Joe Conway <mail(at)joeconway(dot)com>
To: Itagaki Takahiro <itagaki(dot)takahiro(at)oss(dot)ntt(dot)co(dot)jp>
Cc: Stephen Frost <sfrost(at)snowman(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: query cancel issues in contrib/dblink
Date: 2009-09-16 06:01:03
Message-ID: 4AB07F1F.1010805@joeconway.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Itagaki Takahiro wrote:
> Stephen Frost <sfrost(at)snowman(dot)net> wrote:
>
>> Can you provide an update on this patch? Joe, you were going to
>> review and possibly commit it. Itagaki, did you have a new version?
>> Are there any outstanding issues?
>
> Thanks for your reviewing.
> Here is an updated version. I fixed some bugs:
>
> * Fix connection leak on cancel. In the previous patch, running
> transactions are canceled, but the temporary connection was leaked.
> * Discard all pending results on cancel handler. I implemented
> PQexec-compatible behavior with async APIs.

Thanks for the update. I am planning to review, but my time will be
extremely limited for the next two weeks. I might find some time this
coming weekend, and will do what I can, but after that it will be 9/28
(after my son's wedding on 9/27) before I get time to look closely.

Joe


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Itagaki Takahiro <itagaki(dot)takahiro(at)oss(dot)ntt(dot)co(dot)jp>
Cc: pgsql-hackers(at)postgresql(dot)org, Merlin Moncure <mmoncure(at)gmail(dot)com>
Subject: Re: query cancel issues in contrib/dblink
Date: 2010-02-24 19:33:37
Message-ID: 201002241933.o1OJXbP09970@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers


What happened to this patch?

---------------------------------------------------------------------------

Itagaki Takahiro wrote:
>
> Merlin Moncure <mmoncure(at)gmail(dot)com> wrote:
>
> > Takahiro<itagaki(dot)takahiro(at)oss(dot)ntt(dot)co(dot)jp> wrote:
> > > contrib/dblink seems to have no treatments for query cancels.
> > > (1) Users need to wait for completion of remote query.
> > > (2) PGresult objects will be memory leak.
>
> Here is a patch to fix the issues. I hope the fixes will be ported
> to older versions if possible.
>
> (1) is fixed by using non-blocking APIs in libpq. I think we should
> always use non-blocking APIs even if the dblink function itself is
> a blocking-function.
>
> (2) is fixed by RegisterXactCallback(AtEOXact_dblink). However, there
> might be any better solutions -- for example, ResourceOwner framework.
>
>
> > > For (1), asynchronous libpq functions should be used instead of blocking
> > > ones, and wait for the remote query using a loop with CHECK_FOR_INTERRUPTS().
> >
> > How would you structure this loop exactly?
>
> Please check execute_query() and wait_for_result() in the patch.
>
> Regards,
> ---
> ITAGAKI Takahiro
> NTT Open Source Software Center
>

[ Attachment, skipping... ]

>
> --
> Sent via pgsql-hackers mailing list (pgsql-hackers(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-hackers

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com
PG East: http://www.enterprisedb.com/community/nav-pg-east-2010.do
+ If your life is a hard drive, Christ can be your backup. +


From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: Itagaki Takahiro <itagaki(dot)takahiro(at)oss(dot)ntt(dot)co(dot)jp>, pgsql-hackers(at)postgresql(dot)org, Merlin Moncure <mmoncure(at)gmail(dot)com>
Subject: Re: query cancel issues in contrib/dblink
Date: 2010-02-24 19:45:24
Message-ID: 603c8f071002241145kc3e1e55r449b5b705c27b252@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Wed, Feb 24, 2010 at 2:33 PM, Bruce Momjian <bruce(at)momjian(dot)us> wrote:
> What happened to this patch?

I'm pretty sure it's the same as this:

https://commitfest.postgresql.org/action/patch_view?id=263

...Robert


From: Takahiro Itagaki <itagaki(dot)takahiro(at)oss(dot)ntt(dot)co(dot)jp>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Bruce Momjian <bruce(at)momjian(dot)us>, pgsql-hackers(at)postgresql(dot)org, Merlin Moncure <mmoncure(at)gmail(dot)com>
Subject: Re: query cancel issues in contrib/dblink
Date: 2010-02-25 00:41:05
Message-ID: 20100225094105.9158.52131E4D@oss.ntt.co.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers


Robert Haas <robertmhaas(at)gmail(dot)com> wrote:

> I'm pretty sure it's the same as this:
> https://commitfest.postgresql.org/action/patch_view?id=263

Yes, (2) are resolved with the patch with a different implementation.

> (2) is fixed by RegisterXactCallback(AtEOXact_dblink). However, there
> might be any better solutions -- for example, ResourceOwner framework.

(1) still exists, but we had a consensus that we don't have to fix it
because we have async functions.

> (1) is fixed by using non-blocking APIs in libpq. I think we should
> always use non-blocking APIs even if the dblink function itself is
> a blocking-function.

Regards,
---
Takahiro Itagaki
NTT Open Source Software Center