Index: lib/Mail/SpamAssassin/BayesStore/MySQL.pm =================================================================== RCS file: /home/cvs/projects/2006/bnet/mail-cluster/src/packages/spamassassin/spamassassin-3.2.5/lib/Mail/SpamAssassin/BayesStore/MySQL.pm,v retrieving revision 1.1.1.1 diff -d --unified -r1.1.1.1 MySQL.pm --- lib/Mail/SpamAssassin/BayesStore/MySQL.pm 9 Oct 2008 17:27:23 -0000 1.1.1.1 +++ lib/Mail/SpamAssassin/BayesStore/MySQL.pm 16 Oct 2008 14:38:26 -0000 @@ -49,6 +49,8 @@ use constant HAS_DBI => eval { require DBI; }; +use constant DB_RETRIES => 10; + =head1 METHODS =head2 token_expiration @@ -79,13 +81,24 @@ WHERE id = ? AND atime > ?"; - my $rows = $self->{_dbh}->do($sql, undef, $vars[10], $self->{_userid}, $vars[10]); - - unless (defined($rows)) { - dbg("bayes: token_expiration: SQL error: ".$self->{_dbh}->errstr()); - $deleted = 0; - $self->{_dbh}->rollback(); - goto token_expiration_final; + my $rows; + for (my $retry_cnt = 0; $retry_cnt < DB_RETRIES; $retry_cnt++) { + $rows = $self->{_dbh}->do($sql, undef, $vars[10], $self->{_userid}, $vars[10]); + if (defined($rows)) { + # write something if we retried + dbg("bayes: token_expiration: retried 'UPDATE bayes_token' ".$retry_cnt." times") if ($retry_cnt > 0); + last; + } + # check if we should retry + my $errstr = $self->{_dbh}->errstr(); + if ($errstr =~ /try restarting transaction/) { + next; + } + # a real error + dbg("bayes: token_expiration: SQL error: ".$self->{_dbh}->errstr()); + $deleted = 0; + $self->{_dbh}->rollback(); + goto token_expiration_final; } # Check to make sure the expire won't remove too many tokens