Re: Ima::DBI and connections at Apache startup
[prev]
[thread]
[next]
[Date index for 2004/10/06]
> Also, when you write your own db_Main, it breaks dbi_commit and
...
> just call Your::ClassDBI->db_Main()->commit() instead.
I missed the whole dbi_commit thing anyway...
> I hate to introduce mod_perl-specific stuff into Ima::DBI, but it looks
> like that may be the only way to keep the performance high. My approach
> would be check for $ENV{MOD_PERL} and if true create a different kind of
> closure for getting the handle. This closure would store the handle in
> Apache->request()->pnotes() for the duration of the current request,
> making it very fast to fetch and ensuring that it will get cleaned up
> and Apache::DBI will get called again at the start of the next request.
> This ensures that the cleanup_handler for transactions will happen.
Sounds good to me.
> > Another BIG hitch with my plan is that Class::DBI needs to
> > consistently get the same handle from db_Main for transactions
> > to work.
>
> That shouldn't be a problem at all. You always get the same handle in
> the same process when you use connect_cached/Apache::DBI and send the
> same connect string.
That's what I expected, but it didn't seem that way in my tests (below)
AutoCommit seems to be reset at DBI.pm line 640 in 'connect'
after the cache is hit. This would also effect Apache::DBI::connect.
I guess this is to ensure the handle is in the state expected from
the given attributes (& defaults) but it does have the side effect
of breaking transactions when you don't connect with AutoCommit = 1,
and later "begin_work".
I guess "Don't do that" is the answer. Perhaps the reseting
code should warn you if AutoCommit isn't the same.
Will CDBI work out with AutoCommit = 0 for mysql with innodb?
Is there anything to beware?
Brad
# demo of my problem
perl -MDBI -de1
@c = ('XXX','XXX','XXX',{AutoCommit=>1});
DB<2> x $a = DBI->connect_cached(@c);
0 DBI::db=HASH(0x83fb060)
empty hash
DB<3> x $a->{Active}
0 1
DB<4> x $a->{AutoCommit}
0 1
DB<5> x $a->begin_work
0 1
DB<6> x $a->{AutoCommit}
0 ''
DB<7> x $a->rollback
0 1
DB<8> x DBI->connect_cached(@c)->{AutoCommit}
0 1
DB<9> x DBI->connect_cached(@c)->begin_work
0 1
DB<10> x DBI->connect_cached(@c)->{AutoCommit}
0 1
DB<11> x DBI->connect_cached(@c)->rollback
rollback ineffective with AutoCommit enabled at (eval 14)[/usr/share/perl/5.6.1/perl5db.pl:1521] line 2.
Rollback ineffective while AutoCommit is on at (eval 14)[/usr/share/perl/5.6.1/perl5db.pl:1521] line 2.
DBD::mysql::db rollback failed: Rollback ineffective while AutoCommit is on at (eval 14)[/usr/share/perl/5.6.1/perl5db.pl:1521] line 2.
0 ''
DB<12> x DBI->connect_cached(@c)->{Driver}{CachedKids}
0 HASH(0x842f11c)
'XXX:localhost~~XXX~~XXX~~AutoCommit~~PrintError~~Username~~dbi_connect_method~~1~~1~~www-data~~connect_cached' => DBI::db=HASH(0x83fb060)
empty hash
--
Among the maxims on Lord Naoshige's wall there was this one: "Matters
of great concern should be treated lightly." Master Ittei commented,
"Matters of small concern should be treated seriously."
-- Hagakure http://bereft.net/hagakure/
|
(message missing)
|