You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Haroon Rafique <ha...@utoronto.ca> on 2003/03/03 19:09:41 UTC

Apache::DBI on mp2

My setup is as follows:

Apache/2.0.44 (Gentoo/Linux) mod_perl/1.99_08 Perl/v5.8.0

mod_perl was built from CVS.

I was interested in getting Apache::DBI to run under mp2. I did read 
Ask's message at 
http://marc.theaimsgroup.com/?l=apache-modperl&m=104225578207460&w=2
which leads me to my question. What would it take to get connect_on_init 
to run under mp2?

With the following patch I was able to get connect_on_init to work under 
mp2. Remember that my objective was to JUST get it to run. This is NOT 
release quality code. I'm happy to report that it works for me, so far. 
Anyone else who is running mp2 (no compat mode) willing to give it a try?
Of course, then the gurus can come in and clean up the code so that it 
works under either mp1 or mp2.

diff -u DBI.pm /usr/lib/perl5/site_perl/5.8.0/Apache/DBI.pm 
--- DBI.pm      2003-02-17 08:04:19.000000000 -0500
+++ /usr/lib/perl5/site_perl/5.8.0/Apache/DBI.pm        2003-03-03 
12:03:06.000000000 -0500
@@ -7,6 +7,8 @@
 use DBI ();
 use Carp qw(carp);
 
+use Apache::ServerUtil ();
+
 require_version DBI 1.00;
 
 $Apache::DBI::VERSION = '0.91';
@@ -32,9 +34,8 @@
     # provide a handler which creates all connections during server 
startup
 
     # TODO - Should check for mod_perl 2 and do the right thing there
-    carp "Apache.pm was not loaded\n" and return unless 
$INC{'Apache.pm'};
-    if(!@ChildConnect and Apache->can('push_handlers')) {
-        Apache->push_handlers(PerlChildInitHandler => \&childinit);
+    if(!@ChildConnect) {
+        Apache->server->push_handlers(PerlChildInitHandler => 
\&childinit);
     }
     # store connections
     push @ChildConnect, [@_];
@@ -89,9 +90,9 @@
     # this PerlCleanupHandler is supposed to initiate a rollback after 
the script has finished if AutoCommit is off.
     my $needCleanup = ($Idx =~ /AutoCommit[^\d]+0/) ? 1 : 0;
     # TODO - Fix mod_perl 2.0 here
-    if(!$Rollback{$Idx} and $needCleanup and 
Apache->can('push_handlers')) {
+    if(!$Rollback{$Idx} and $needCleanup) {
         print STDERR "$prefix push PerlCleanupHandler \n" if 
$Apache::DBI::DEBUG > 1;
-        Apache->push_handlers("PerlCleanupHandler", \&cleanup);
+        Apache->server->push_handlers("PerlCleanupHandler", \&cleanup);
         # make sure, that the rollback is called only once for every 
         # request, even if the script calls connect more than once
         $Rollback{$Idx} = 1;


--
Haroon Rafique
<ha...@utoronto.ca>


Re: Apache::DBI on mp2

Posted by Stas Bekman <st...@stason.org>.
Ask Bjoern Hansen wrote:
> On Wed, 5 Mar 2003, Stas Bekman wrote:
> 
> 
>>Great. I've already committed that patch.
>>
>>Perhaps Ask could load 'Apache::compat' inside Apache::DBI if mp2 is used. Or
>>to use the mp2 API if mp2 is used.
> 
> 
> That seems like it'll be an easy solution.  I thought loading
> Apache::compat would have global side effects though?  (i.e. for
> people trying to make their system run without Apache::compat).

Please scratch that idea than ;) Though it can be documented, including the 
"Apache::compat warning" ;)

And instead simply add the code to handle it differently if $mod_perl::VERSION 
 >= 1.99, using the 2.0 API.



__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


Re: Apache::DBI on mp2

Posted by Ask Bjoern Hansen <as...@develooper.com>.
On Wed, 5 Mar 2003, Stas Bekman wrote:

> Great. I've already committed that patch.
>
> Perhaps Ask could load 'Apache::compat' inside Apache::DBI if mp2 is used. Or
> to use the mp2 API if mp2 is used.

That seems like it'll be an easy solution.  I thought loading
Apache::compat would have global side effects though?  (i.e. for
people trying to make their system run without Apache::compat).


  - ask

-- 
ask bjoern hansen, http://www.askbjoernhansen.com/ !try; do();

Re: Apache::DBI on mp2

Posted by Stas Bekman <st...@stason.org>.
Haroon Rafique wrote:
> On Today at 11:16am, SB=>Stas Bekman <st...@stason.org> wrote:
> 
> SB> FWIW, we are discussing the internal DBI pooling mechanism at the
> SB> dbi-dev list and having already a sort-of-working prototype. So
> SB> hopefully there will be no need for Apache::DBI in the near future, as
> SB> DBI will be able to handle pooling internally. However it may take
> SB> some time, as the drivers will have to adjust to support the new
> SB> functionality.
> SB> 
> SB> You can see the thread here:
> SB> http://archive.develooper.com/dbi-dev@perl.org/index.html#02118
> SB> 
> SB> Some working examples are attached to this message:
> SB> http://archive.develooper.com/dbi-dev@perl.org/msg02134.html
> SB> 
> 
> Stas,
> 
> Thanks for your response.
> 
> I will try and keep up with the developments in the above-mentioned
> threads. However, for now, I'll focus on your alternate solution as
> mentioned below. If I find some free time (what are the chances?) I may
> also give DBI::Pool a try under mp2.

I've already tried it and it works ;) However DBI::Pool won't have a life on 
its own and will be integrated into DBI itself and its DBD drivers.

> SB> [..snip..]
> SB> 
> SB> If you apply the following patch (will commit it soon) against the modperl-2.0 
> SB> source, you will be able to use connect_on_init unmodified, assuming that 
> SB> Apache::compat was loaded before Apache::DBI. Let me know whether it works for 
> SB> you.
> SB> 
> 
> I'm happy to report that the patch to lib/Apache/compat.pm works. I did
> not even have to use CVS versions of any of the packages.
> 
> Apache/2.0.44 (Gentoo/Linux) mod_perl/1.99_08 Perl/v5.8.0
> 
> I simply patched:
> /usr/lib/perl5/vendor_perl/5.8.0/i686-linux/Apache2/Apache/compat.pm
> with your patch and connect_on_init works unmodified. And as mentioned in 
> your email, I do have Apache::compat loaded before Apache::DBI.

Great. I've already committed that patch.

Perhaps Ask could load 'Apache::compat' inside Apache::DBI if mp2 is used. Or 
to use the mp2 API if mp2 is used.

__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


Re: Apache::DBI on mp2

Posted by Haroon Rafique <ha...@utoronto.ca>.
On Today at 11:16am, SB=>Stas Bekman <st...@stason.org> wrote:

SB> FWIW, we are discussing the internal DBI pooling mechanism at the
SB> dbi-dev list and having already a sort-of-working prototype. So
SB> hopefully there will be no need for Apache::DBI in the near future, as
SB> DBI will be able to handle pooling internally. However it may take
SB> some time, as the drivers will have to adjust to support the new
SB> functionality.
SB> 
SB> You can see the thread here:
SB> http://archive.develooper.com/dbi-dev@perl.org/index.html#02118
SB> 
SB> Some working examples are attached to this message:
SB> http://archive.develooper.com/dbi-dev@perl.org/msg02134.html
SB> 

Stas,

Thanks for your response.

I will try and keep up with the developments in the above-mentioned
threads. However, for now, I'll focus on your alternate solution as
mentioned below. If I find some free time (what are the chances?) I may
also give DBI::Pool a try under mp2.

SB> [..snip..]
SB> 
SB> If you apply the following patch (will commit it soon) against the modperl-2.0 
SB> source, you will be able to use connect_on_init unmodified, assuming that 
SB> Apache::compat was loaded before Apache::DBI. Let me know whether it works for 
SB> you.
SB> 

I'm happy to report that the patch to lib/Apache/compat.pm works. I did
not even have to use CVS versions of any of the packages.

Apache/2.0.44 (Gentoo/Linux) mod_perl/1.99_08 Perl/v5.8.0

I simply patched:
/usr/lib/perl5/vendor_perl/5.8.0/i686-linux/Apache2/Apache/compat.pm
with your patch and connect_on_init works unmodified. And as mentioned in 
your email, I do have Apache::compat loaded before Apache::DBI.

Cheers,
--
Haroon Rafique
<ha...@utoronto.ca>


Re: Apache::DBI on mp2

Posted by Stas Bekman <st...@stason.org>.
Ask Bjoern Hansen wrote:
> On Fri, 7 Mar 2003, Stas Bekman wrote:
> 
> 
>>>If the physical connection is still there, would the database server
>>>do a rollback?
>>
>>If earlier the rollback worked correctly with
>>$dbh ||= connect();, this will work the same, since it performs the same
>>operation, but rips off only parts of $dbh, because of the constraints of
>>sharing Perl datastructures and underlying C structs.
> 
> 
> Apache::DBI explicitly calls $dbh->rollback (when things are
> configured so it makes sense).  Or maybe I am completely
> misunderstanding you.

All I was saying is, that whatever worked for Apache::DBI will work for 
internal pooling.

>>>ps. yes, your DBI::Pool work is great.  Thank you.  :-)
>>
>>My pleasure. Thanks for the kind words. It's quite challenging, though you
>>stop getting excited about segfaults and ddd (gdb frontend) is nowadays my
>>best friend ;)
> 
> 
> :-)  You are quite the masochist if you ever got excited about
> segfaults.  I only recall segfaults making me slam my head into the
> wall to conceal the pain.

I meant in the way that when something is repeated too many times it's not the 
same anymore ;) so s/excited/annoyed/ will do ;)

__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


Re: Apache::DBI on mp2

Posted by Ask Bjoern Hansen <as...@develooper.com>.
On Fri, 7 Mar 2003, Stas Bekman wrote:

> > If the physical connection is still there, would the database server
> > do a rollback?
>
> If earlier the rollback worked correctly with
> $dbh ||= connect();, this will work the same, since it performs the same
> operation, but rips off only parts of $dbh, because of the constraints of
> sharing Perl datastructures and underlying C structs.

Apache::DBI explicitly calls $dbh->rollback (when things are
configured so it makes sense).  Or maybe I am completely
misunderstanding you.

> > ps. yes, your DBI::Pool work is great.  Thank you.  :-)
>
> My pleasure. Thanks for the kind words. It's quite challenging, though you
> stop getting excited about segfaults and ddd (gdb frontend) is nowadays my
> best friend ;)

:-)  You are quite the masochist if you ever got excited about
segfaults.  I only recall segfaults making me slam my head into the
wall to conceal the pain.


 - ask

-- 
ask bjoern hansen, http://www.askbjoernhansen.com/ !try; do();

Re: Apache::DBI on mp2

Posted by Stas Bekman <st...@stason.org>.
Ask Bjoern Hansen wrote:
> On Thu, 6 Mar 2003, Stas Bekman wrote:
> 
> 
>>re: rollback, the DBD drivers will perform the normal disconnect(), but
>>without doing the physical disconnect, and normal DESTROY, without destroying
>>the datastructures which maintain the physical connection, so there shouldn't
>>be much to change for this feature.
> 
> 
> If the physical connection is still there, would the database server
> do a rollback?

If earlier the rollback worked correctly with
$dbh ||= connect();, this will work the same, since it performs the same 
operation, but rips off only parts of $dbh, because of the constraints of 
sharing Perl datastructures and underlying C structs.

> ps. yes, your DBI::Pool work is great.  Thank you.  :-)

My pleasure. Thanks for the kind words. It's quite challenging, though you 
stop getting excited about segfaults and ddd (gdb frontend) is nowadays my 
best friend ;)

__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


Re: Apache::DBI on mp2

Posted by Ask Bjoern Hansen <as...@develooper.com>.
On Thu, 6 Mar 2003, Stas Bekman wrote:

> re: rollback, the DBD drivers will perform the normal disconnect(), but
> without doing the physical disconnect, and normal DESTROY, without destroying
> the datastructures which maintain the physical connection, so there shouldn't
> be much to change for this feature.

If the physical connection is still there, would the database server
do a rollback?


 - ask

ps. yes, your DBI::Pool work is great.  Thank you.  :-)

-- 
ask bjoern hansen, http://www.askbjoernhansen.com/ !try; do();

Re: Apache::DBI on mp2

Posted by Stas Bekman <st...@stason.org>.
Perrin Harkins wrote:
> Stas Bekman wrote:
> 
>> FWIW, we are discussing the internal DBI pooling mechanism at the 
>> dbi-dev list and having already a sort-of-working prototype. So 
>> hopefully there will be no need for Apache::DBI in the near future, as 
>> DBI will be able to handle pooling internally. However it may take 
>> some time, as the drivers will have to adjust to support the new 
>> functionality.
>>
>> You can see the thread here:
>> http://archive.develooper.com/dbi-dev@perl.org/index.html#02118
>>
>> Some working examples are attached to this message:
>> http://archive.develooper.com/dbi-dev@perl.org/msg02134.html
> 
> This is totally cool, Stas!  Nice work.  I look forward to answering 
> "yes" when people ask if mod_perl has database connections pooling.

;)

actually it's going to be: "if perl has database connections pooling", which 
will include mod_perl by definition.

Also, the pooling mechanism should work transparently w/ and w/o threads on 
the user level.

> By the way, to completely get rid of Apache::DBI this would need to 
> cover the safety functionality in there as well, i.e. the pinging and 
> the part where it rolls back any pending transactions when a a handle is 
> returned to the pool.

Certainly. Quite a few features are missing. The first step was (is) to make 
the dbh shared between threads (which is far from trivial). The rest should be 
just a matter of coding.

re: rollback, the DBD drivers will perform the normal disconnect(), but 
without doing the physical disconnect, and normal DESTROY, without destroying 
the datastructures which maintain the physical connection, so there shouldn't 
be much to change for this feature.

Only the ping() is needed to be added to connect().

__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


Re: Apache::DBI on mp2

Posted by Perrin Harkins <pe...@elem.com>.
Stas Bekman wrote:
> FWIW, we are discussing the internal DBI pooling mechanism at the 
> dbi-dev list and having already a sort-of-working prototype. So 
> hopefully there will be no need for Apache::DBI in the near future, as 
> DBI will be able to handle pooling internally. However it may take some 
> time, as the drivers will have to adjust to support the new functionality.
> 
> You can see the thread here:
> http://archive.develooper.com/dbi-dev@perl.org/index.html#02118
> 
> Some working examples are attached to this message:
> http://archive.develooper.com/dbi-dev@perl.org/msg02134.html

This is totally cool, Stas!  Nice work.  I look forward to answering 
"yes" when people ask if mod_perl has database connections pooling.

By the way, to completely get rid of Apache::DBI this would need to 
cover the safety functionality in there as well, i.e. the pinging and 
the part where it rolls back any pending transactions when a a handle is 
returned to the pool.

- Perrin


Re: Apache::DBI on mp2

Posted by Stas Bekman <st...@stason.org>.
FWIW, we are discussing the internal DBI pooling mechanism at the dbi-dev list 
and having already a sort-of-working prototype. So hopefully there will be no 
need for Apache::DBI in the near future, as DBI will be able to handle pooling 
internally. However it may take some time, as the drivers will have to adjust 
to support the new functionality.

You can see the thread here:
http://archive.develooper.com/dbi-dev@perl.org/index.html#02118

Some working examples are attached to this message:
http://archive.develooper.com/dbi-dev@perl.org/msg02134.html

Haroon Rafique wrote:
> My setup is as follows:
> 
> Apache/2.0.44 (Gentoo/Linux) mod_perl/1.99_08 Perl/v5.8.0
> 
> mod_perl was built from CVS.
> 
> I was interested in getting Apache::DBI to run under mp2. I did read 
> Ask's message at 
> http://marc.theaimsgroup.com/?l=apache-modperl&m=104225578207460&w=2
> which leads me to my question. What would it take to get connect_on_init 
> to run under mp2?
> 
> With the following patch I was able to get connect_on_init to work under 
> mp2. Remember that my objective was to JUST get it to run. This is NOT 
> release quality code. I'm happy to report that it works for me, so far. 
> Anyone else who is running mp2 (no compat mode) willing to give it a try?
> Of course, then the gurus can come in and clean up the code so that it 
> works under either mp1 or mp2.

If you apply the following patch (will commit it soon) against the modperl-2.0 
source, you will be able to use connect_on_init unmodified, assuming that 
Apache::compat was loaded before Apache::DBI. Let me know whether it works for 
you.

Index: lib/Apache/compat.pm
===================================================================
RCS file: /home/cvs/modperl-2.0/lib/Apache/compat.pm,v
retrieving revision 1.81
diff -u -r1.81 compat.pm
--- lib/Apache/compat.pm        19 Feb 2003 23:55:23 -0000      1.81
+++ lib/Apache/compat.pm        3 Mar 2003 23:49:19 -0000
@@ -125,6 +125,16 @@
      die $err if $err;
  }

+sub push_handlers {
+    shift;
+    Apache->server->push_handlers(@_);
+}
+
+sub set_handlers {
+    shift;
+    Apache->server->set_handlers(@_);
+}
+
  package Apache::Constants;

  use Apache::Const ();




__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com