Skip Menu |

This queue is for tickets about the Tie-Hash-DBD CPAN distribution.

Report information
The Basics
Id: 63961
Status: resolved
Priority: 0/
Queue: Tie-Hash-DBD

People
Owner: Nobody in particular
Requestors: GAISSMAI [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: 0.05
Fixed in: 0.09



Hi Mr. Brand, thanks a lot for Tie::Hash::DBD. I use it for web session handling, storing the session records in a SQLite-DB. After inspecting your code, I didn't find an API to make Tie::Hash::DBD AutoCommit-ing. Currently I use the following workaround: $tied_obj->{dbh}{AutoCommit} = 1; But anyway, the STORE and DELETE routine aren't ready for concurrent usage. I miss transactions around the following code-blocks: sub STORE { my ($self, $key, $value) = @_; my $k = $self->{asc} ? unpack "H*", $key : $key; my $v = $self->_stream ($value); Show quoted text
>>> TRANSACTION BEGIN
$self->EXISTS ($key) ? $self->{upd}->execute ($v, $k) : $self->{ins}->execute ($k, $v); Show quoted text
>>> TRANSACTION COMMIT
} # STORE sub DELETE { my ($self, $key) = @_; $self->{asc} and $key = unpack "H*", $key; Show quoted text
>>> TRANSACTION BEGIN
$self->{sel}->execute ($key); my $r = $self->{sel}->fetch or Show quoted text
>>> TRANSACTION COMMIT
return; $self->{del}->execute ($key); Show quoted text
>>> TRANSACTION COMMIT
$self->_unstream ($r->[0]); } # DELETE Similar is necessary if you access the tied hash via: each, keys or values sub FIRSTKEY { my $self = shift; Show quoted text
>>> TRANSACTION BEGIN
$self->{key} = $self->{dbh}->selectcol_arrayref ("select $self->{f_k} from $self->{tbl}"); @{$self->{key}} or Show quoted text
>>> TRANSACTION COMMIT)
return; if ($self->{asc}) { $_ = pack "H*", $_ for @{$self->{key}}; } pop @{$self->{key}}; } # FIRSTKEY sub NEXTKEY { my $self = shift; @{$self->{key}} or Show quoted text
>>> TRANSACTION COMMIT
return; pop @{$self->{key}}; } # FIRSTKEY What do you mean, would this be possible. Perhaps as a new Tie::Hash::DBD::Transactional ???? Best Regards Charly Gaissmaier
Subject: Re: [rt.cpan.org #63961]
Date: Thu, 16 Dec 2010 09:24:49 +0100
To: bug-Tie-Hash-DBD [...] rt.cpan.org
From: "H.Merijn Brand" <h.m.brand [...] xs4all.nl>
Show quoted text
> thanks a lot for Tie::Hash::DBD. I use it for web session handling, > storing the session records in a SQLite-DB. > > After inspecting your code, I didn't find an API to make Tie::Hash::DBD > AutoCommit-ing. Currently I use the following workaround:
There isn't any. On purpose. Show quoted text
> $tied_obj->{dbh}{AutoCommit} = 1;
Did you measure the speed difference? I could enable dbh attributes to the tie initiator, somewhat like tie my %hash, "Tie::Hash::DBD", $dbh, { tbl => "t_tie_analysis", key => "h_key", fld => "h_value", str => "Storable", RaiseError => 0, AutoCommit => 1, }; Show quoted text
> But anyway, the STORE and DELETE routine aren't ready > for concurrent usage.
Correct, and they are not meant/designed to be. It could be done though, but *I* would for sure not want so for the speed penalty is huge. Show quoted text
> I miss transactions around the following code-blocks: > > [ code snipped ] > > What do you mean, would this be possible. Perhaps as a new > Tie::Hash::DBD::Transactional ????
Yes, could be possible, though subclassing would be rather awkward because you cannot inject commit code in the SUPER methods, so now the only possible workaround is to make autocommit and/or explicit commits an option. FWIW IIRC the autocommit is always "on" when you specify the table name yourself. This was created to allow persistence, but using it to - optional - also set AutoCommit would be ok with me. -- H.Merijn Brand http://tux.nl Perl Monger http://amsterdam.pm.org/ using 5.00307 through 5.12 and porting perl5.13.x on HP-UX 10.20, 11.00, 11.11, 11.23 and 11.31, OpenSuSE 10.1, 11.0 .. 11.3 and AIX 5.2 and 5.3. http://mirrors.develooper.com/hpux/ http://www.test-smoke.org/ http://qa.perl.org http://www.goldmark.org/jeff/stupid-disclaimers/
Subject: Re: [rt.cpan.org #63961]
Date: Thu, 16 Dec 2010 11:02:55 +0100
To: bug-Tie-Hash-DBD [...] rt.cpan.org
From: Karl Gaissmaier <karl.gaissmaier [...] uni-ulm.de>
Hello Mr. Brand, ... Show quoted text
>> After inspecting your code, I didn't find an API to make Tie::Hash::DBD >> AutoCommit-ing. Currently I use the following workaround:
> > There isn't any. On purpose. >
>> $tied_obj->{dbh}{AutoCommit} = 1;
> > Did you measure the speed difference?
Yes, I did, and it's huge. But better a slower speed than wrong data. If it's possible to have the option to choose, and the featurism isn't to high, would be a nice option for your users. Show quoted text
> > I could enable dbh attributes to the tie initiator, somewhat like > > tie my %hash, "Tie::Hash::DBD", $dbh, { > tbl => "t_tie_analysis", > key => "h_key", > fld => "h_value", > str => "Storable", > > RaiseError => 0, > AutoCommit => 1, > }; >
Sounds useful, but the problem with transactions around STORE, DELETE, FISRT- and NEXT-KEY still exists. Could this also be set as an option would be great. Show quoted text
> Correct, and they are not meant/designed to be. It could be done > though, but *I* would for sure not want so for the speed penalty > is huge.
sure, but not in all use cases is the speed the dominant factor. ... Show quoted text
>> What do you mean, would this be possible. Perhaps as a new >> Tie::Hash::DBD::Transactional ????
> > Yes, could be possible, though subclassing would be rather awkward > because you cannot inject commit code in the SUPER methods, so now > the only possible workaround is to make autocommit and/or explicit > commits an option.
sounds great Show quoted text
> > FWIW IIRC the autocommit is always "on" when you specify the table > name yourself. This was created to allow persistence, but using it > to - optional - also set AutoCommit would be ok with me.
really? I didn't see this behavior with SQLite. Please check it, but perhaps I'm just wrong. Best Regards and thanks a lot for your reply! Charly Gaissmaier
Am Do 16. Dez 2010, 03:25:01, h.m.brand@xs4all.nl schrieb: ... Show quoted text
> > But anyway, the STORE and DELETE routine aren't ready > > for concurrent usage.
> > Correct, and they are not meant/designed to be. It could be done > though, but *I* would for sure not want so for the speed penalty > is huge. >
I use Tie::Hash::DBD now in production. It's used as a session backend of a Captive Portal with heavy usage and I see the concurrency problems already: +++ column 'client' is not unique at /usr/lib/perl5/vendor_perl/5.12.1/Tie/Hash/DBD.pm line 196 This is the critical path in STORE, where EXISTS decides between INSERT or UPDATE. Since this codeblock isn't within a transaction, sometimes it failes with this error message. Best Regards Charly
Subject: Re: [rt.cpan.org #63961] Wish: AutoCommit or transaction control
Date: Sat, 15 Jan 2011 17:09:00 +0100
To: bug-Tie-Hash-DBD [...] rt.cpan.org
From: "H.Merijn Brand" <h.m.brand [...] xs4all.nl>
On Tue, 11 Jan 2011 04:51:06 -0500, "Karl Gaissmaier via RT" <bug-Tie-Hash-DBD@rt.cpan.org> wrote: Show quoted text
> I use Tie::Hash::DBD now in production. It's used as a session backend > of a Captive Portal with heavy usage and I see the concurrency problems > already: > > +++ column 'client' is not unique at > /usr/lib/perl5/vendor_perl/5.12.1/Tie/Hash/DBD.pm line 196 > > This is the critical path in STORE, where EXISTS decides between INSERT > or UPDATE. Since this codeblock isn't within a transaction, sometimes it > failes with this error message.
Can you mail me off-RT, so I can send you a snapshot for feedback? hmbrand at cpan dot org -- H.Merijn Brand http://tux.nl Perl Monger http://amsterdam.pm.org/ using 5.00307 through 5.12 and porting perl5.13.x on HP-UX 10.20, 11.00, 11.11, 11.23 and 11.31, OpenSuSE 10.1, 11.0 .. 11.3 and AIX 5.2 and 5.3. http://mirrors.develooper.com/hpux/ http://www.test-smoke.org/ http://qa.perl.org http://www.goldmark.org/jeff/stupid-disclaimers/