Re: [PATCHES] WIP 2 interpreters for plperl

Lists: pgsql-hackerspgsql-patches
From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: "Patches (PostgreSQL)" <pgsql-patches(at)postgresql(dot)org>
Subject: WIP 2 interpreters for plperl
Date: 2006-11-05 21:14:17
Message-ID: 454E5429.6060004@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches


I have made some progress with what I think is needed to have two
interpreters for plperl. This is a lot harder than the pltcl case for
two reasons: 1. there are no restrictions on having 2 tcl interpreters,
and 2. tcl does not need to save and restore context as we have to do
with perl. I think I have a conceptual siolution to these two problems,
but what I have is currently segfaulting somewhat myteriously. Tracing a
dynamically loaded library in a postgres backend with a debugger is less
than fun, too. I am attaching what I currently have, liberally sprinkled
with elog(NOTICE) calls as trace writes.

I need to get some other work done today too, so I will return to this
later if I can. In the meanwhile, if anybody cares to cast a fresh set
of eyeballs over this, please do.

cheers

andrew

Attachment Content-Type Size
perldiff text/plain 17.4 KB

From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: "Patches (PostgreSQL)" <pgsql-patches(at)postgresql(dot)org>
Subject: Re: WIP 2 interpreters for plperl
Date: 2006-11-05 22:25:49
Message-ID: 454E64ED.80500@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

I wrote:
>
> I have made some progress with what I think is needed to have two
> interpreters for plperl. This is a lot harder than the pltcl case for
> two reasons: 1. there are no restrictions on having 2 tcl
> interpreters, and 2. tcl does not need to save and restore context as
> we have to do with perl. I think I have a conceptual siolution to
> these two problems, but what I have is currently segfaulting somewhat
> myteriously. Tracing a dynamically loaded library in a postgres
> backend with a debugger is less than fun, too. I am attaching what I
> currently have, liberally sprinkled with elog(NOTICE) calls as trace
> writes.
>
>

With a little more perseverance I found the problem. The attached patch
passes regression. But it now needs plenty of eyeballs and testing.

cheers

andrew

Attachment Content-Type Size
perldiff text/plain 16.0 KB

From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCHES] WIP 2 interpreters for plperl
Date: 2006-11-12 16:03:49
Message-ID: 455745E5.9000505@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches


[moving to -hackers]

I wrote:
>
>>
>> I have made some progress with what I think is needed to have two
>> interpreters for plperl. This is a lot harder than the pltcl case for
>> two reasons: 1. there are no restrictions on having 2 tcl
>> interpreters, and 2. tcl does not need to save and restore context as
>> we have to do with perl. I think I have a conceptual siolution to
>> these two problems, but what I have is currently segfaulting somewhat
>> myteriously. Tracing a dynamically loaded library in a postgres
>> backend with a debugger is less than fun, too. I am attaching what I
>> currently have, liberally sprinkled with elog(NOTICE) calls as trace
>> writes.
>>
>>
>
> With a little more perseverance I found the problem. The attached
> patch passes regression. But it now needs plenty of eyeballs and testing.
>
>

Well, if anyone cast eyeballs over it they kept it secret from me :-(

However, I have now tested the patch with the little script shown below
and it seems to do the Right Thing (tm) in switching context and
restoring it. So I think it can be applied to HEAD, along with an
addition to the docs and a release note.

Since this is a behaviour modification, do we want to apply it to the
back branches? Doing so would certainly be possible, although it would
be non-trivial.

cheers

andrew

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

drop function if exists f1(int);
drop function if exists f2(int);

create function f1(int) returns void language plperl as
$$

my $arg = shift;
elog NOTICE,"in plperl func f1($arg)";
return if ($arg > 5);
$arg++;
spi_exec_query("select f2($arg)");

$$;

create function f2(int) returns void language plperlu as
$$

my $arg = shift;
elog NOTICE,"in plperlu func f2($arg)";
return if ($arg > 5);
$arg++;
spi_exec_query("select f1($arg)");

$$;

select f1(0);
select f2(0);


From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCHES] WIP 2 interpreters for plperl
Date: 2006-11-13 17:16:16
Message-ID: 4558A860.5090006@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

I wrote:
>
> [moving to -hackers]
>
> I wrote:
>>
>>>
>>> I have made some progress with what I think is needed to have two
>>> interpreters for plperl. This is a lot harder than the pltcl case
>>> for two reasons: 1. there are no restrictions on having 2 tcl
>>> interpreters, and 2. tcl does not need to save and restore context
>>> as we have to do with perl. I think I have a conceptual siolution to
>>> these two problems, but what I have is currently segfaulting
>>> somewhat myteriously. Tracing a dynamically loaded library in a
>>> postgres backend with a debugger is less than fun, too. I am
>>> attaching what I currently have, liberally sprinkled with
>>> elog(NOTICE) calls as trace writes.
>>>
>>>
>>
>> With a little more perseverance I found the problem. The attached
>> patch passes regression. But it now needs plenty of eyeballs and
>> testing.
>>
>>
>
> Well, if anyone cast eyeballs over it they kept it secret from me :-(
>
>
> However, I have now tested the patch with the little script shown
> below and it seems to do the Right Thing (tm) in switching context and
> restoring it. So I think it can be applied to HEAD, along with an
> addition to the docs and a release note.
>
> Since this is a behaviour modification, do we want to apply it to the
> back branches? Doing so would certainly be possible, although it would
> be non-trivial.
>

I have committed this to HEAD at any rate, so that we can get some
buildfarm testing going.

cheers

andrew


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCHES] WIP 2 interpreters for plperl
Date: 2006-11-20 19:09:41
Message-ID: 8963.1164049781@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Andrew Dunstan <andrew(at)dunslane(dot)net> writes:
>> Since this is a behaviour modification, do we want to apply it to the
>> back branches? Doing so would certainly be possible, although it would
>> be non-trivial.

> I have committed this to HEAD at any rate, so that we can get some
> buildfarm testing going.

My vote is to leave it just in HEAD; there may be someone out there
depending on plperl and plperlu being in the same interpreter, and
breaking their code in a minor release doesn't seem very friendly.

regards, tom lane


From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCHES] WIP 2 interpreters for plperl
Date: 2006-11-20 20:21:49
Message-ID: 45620E5D.4040909@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Tom Lane wrote:
> Andrew Dunstan <andrew(at)dunslane(dot)net> writes:
>
>>> Since this is a behaviour modification, do we want to apply it to the
>>> back branches? Doing so would certainly be possible, although it would
>>> be non-trivial.
>>>
>
>
>> I have committed this to HEAD at any rate, so that we can get some
>> buildfarm testing going.
>>
>
> My vote is to leave it just in HEAD; there may be someone out there
> depending on plperl and plperlu being in the same interpreter, and
> breaking their code in a minor release doesn't seem very friendly.
>
>
>

Fine by me.

cheers

andrew


From: "Jim Buttafuoco" <jim(at)contactbda(dot)com>
To: "'Tom Lane'" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "'Andrew Dunstan'" <andrew(at)dunslane(dot)net>
Cc: "'PostgreSQL-development'" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCHES] WIP 2 interpreters for plperl
Date: 2006-11-20 20:53:58
Message-ID: 200611202054.kAKKs4vG025145@amanda.contactbda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

I might be one of the ones who depends on the same interpreter. In your new
scheme, the _SHARED hash will only be shared between like interpreters,
correct? This is going to force me to switch all of my perl code to use the
plperlu interpreter :(

-----Original Message-----
From: pgsql-hackers-owner(at)postgresql(dot)org
[mailto:pgsql-hackers-owner(at)postgresql(dot)org] On Behalf Of Tom Lane
Sent: Monday, November 20, 2006 2:10 PM
To: Andrew Dunstan
Cc: PostgreSQL-development
Subject: Re: [HACKERS] [PATCHES] WIP 2 interpreters for plperl

Andrew Dunstan <andrew(at)dunslane(dot)net> writes:
>> Since this is a behaviour modification, do we want to apply it to the
>> back branches? Doing so would certainly be possible, although it would
>> be non-trivial.

> I have committed this to HEAD at any rate, so that we can get some
> buildfarm testing going.

My vote is to leave it just in HEAD; there may be someone out there
depending on plperl and plperlu being in the same interpreter, and
breaking their code in a minor release doesn't seem very friendly.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo(at)postgresql(dot)org so that your
message can get through to the mailing list cleanly


From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: Jim Buttafuoco <jim(at)contactbda(dot)com>
Cc: "'Tom Lane'" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "'PostgreSQL-development'" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCHES] WIP 2 interpreters for plperl
Date: 2006-11-20 21:14:34
Message-ID: 45621ABA.8080502@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Jim Buttafuoco wrote:
> I might be one of the ones who depends on the same interpreter. In your new
> scheme, the _SHARED hash will only be shared between like interpreters,
> correct? This is going to force me to switch all of my perl code to use the
> plperlu interpreter :(
>
>

Yes. Sorry, but I can't see any way around it. If anyone can suggest one
then speak up loudly ASAP.

cheers

andrew


From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: Jim Buttafuoco <jim(at)contactbda(dot)com>, 'Tom Lane' <tgl(at)sss(dot)pgh(dot)pa(dot)us>, 'PostgreSQL-development' <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCHES] WIP 2 interpreters for plperl
Date: 2006-11-21 10:13:57
Message-ID: 20061121101357.GA7205@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

On Mon, Nov 20, 2006 at 04:14:34PM -0500, Andrew Dunstan wrote:
> Jim Buttafuoco wrote:
> >I might be one of the ones who depends on the same interpreter. In your
> >new
> >scheme, the _SHARED hash will only be shared between like interpreters,
> >correct? This is going to force me to switch all of my perl code to use
> >the
> >plperlu interpreter :(
>
> Yes. Sorry, but I can't see any way around it. If anyone can suggest one
> then speak up loudly ASAP.

Since the stuff plperlu should be small and self contained, you just
need to set it up so all the data needed by the plperlu function is
passed as a parameter. I suppose we'd need to look at the use case to
see if this is a real obsticle.

I suppose you're not permitted to call other perl functions directly
with \%_SHARED as a parameter, right?

Have a nice day,
--
Martijn van Oosterhout <kleptog(at)svana(dot)org> http://svana.org/kleptog/
> From each according to his ability. To each according to his ability to litigate.


From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: Martijn van Oosterhout <kleptog(at)svana(dot)org>
Cc: Jim Buttafuoco <jim(at)contactbda(dot)com>, "'Tom Lane'" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "'PostgreSQL-development'" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCHES] WIP 2 interpreters for plperl
Date: 2006-11-21 14:04:58
Message-ID: 4563078A.1060503@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Martijn van Oosterhout wrote:
> On Mon, Nov 20, 2006 at 04:14:34PM -0500, Andrew Dunstan wrote:
>
>> Jim Buttafuoco wrote:
>>
>>> I might be one of the ones who depends on the same interpreter. In your
>>> new
>>> scheme, the _SHARED hash will only be shared between like interpreters,
>>> correct? This is going to force me to switch all of my perl code to use
>>> the
>>> plperlu interpreter :(
>>>
>> Yes. Sorry, but I can't see any way around it. If anyone can suggest one
>> then speak up loudly ASAP.
>>
>
> Since the stuff plperlu should be small and self contained, you just
> need to set it up so all the data needed by the plperlu function is
> passed as a parameter. I suppose we'd need to look at the use case to
> see if this is a real obsticle.
>
> I suppose you're not permitted to call other perl functions directly
> with \%_SHARED as a parameter, right?
>
>
>

\%_SHARED only has meaning in the context of a given perl interpreter.
If we use it in another interpreter it will point to the middle of
nowhere. It's the equivalent of one program passing a pointer to another
program. I thought of playing clever games with a tied interface
(perldoc perltie for more info), but then we'd still have troubles with
things like:

my $xxx=2;
$_SHARED{foo} = { bar => [1,2,3], baz=> sub { return ++$xxx; } };

The only thing I have seen that looked remotely promising is the
non-standard Safe::World module, which if it lives up to its promise
might allow us to go back to using a single interpreter. But I have not
had time to investigate further, and I don't thing we can rely on a
module almost no standard installation will have, unless we want to ship
it ourselves. It doesn't seem to have been worked on since 2004. It is
certainly too late to think of anything like that for 8.2, I think - it
would need significant analysis and testing which I do not currently
have time for, and release is just around the corner, we fervently hope.

cheers

andrew