Commit 68312cf9 authored by lpsolit%gmail.com's avatar lpsolit%gmail.com

Bug 403834: Replace table locks with database transactions in tokens, votes, and…

Bug 403834: Replace table locks with database transactions in tokens, votes, and sanitycheck - Patch by Emmanuel Seyman <eseyman@linagora.com> r/a=mkanat
parent 9d6205cd
...@@ -106,7 +106,7 @@ unless ($user->in_group('editcomponents')) { ...@@ -106,7 +106,7 @@ unless ($user->in_group('editcomponents')) {
if ($cgi->param('rebuildvotecache')) { if ($cgi->param('rebuildvotecache')) {
Status('vote_cache_rebuild_start'); Status('vote_cache_rebuild_start');
$dbh->bz_lock_tables('bugs WRITE', 'votes READ'); $dbh->bz_start_transaction();
$dbh->do(q{UPDATE bugs SET votes = 0}); $dbh->do(q{UPDATE bugs SET votes = 0});
my $sth_update = $dbh->prepare(q{UPDATE bugs my $sth_update = $dbh->prepare(q{UPDATE bugs
SET votes = ? SET votes = ?
...@@ -117,7 +117,7 @@ if ($cgi->param('rebuildvotecache')) { ...@@ -117,7 +117,7 @@ if ($cgi->param('rebuildvotecache')) {
while (my ($id, $v) = $sth->fetchrow_array) { while (my ($id, $v) = $sth->fetchrow_array) {
$sth_update->execute($v, $id); $sth_update->execute($v, $id);
} }
$dbh->bz_unlock_tables(); $dbh->bz_commit_transaction();
Status('vote_cache_rebuild_end'); Status('vote_cache_rebuild_end');
} }
...@@ -262,11 +262,7 @@ if ($cgi->param('rescanallBugMail')) { ...@@ -262,11 +262,7 @@ if ($cgi->param('rescanallBugMail')) {
if ($cgi->param('remove_invalid_bug_references')) { if ($cgi->param('remove_invalid_bug_references')) {
Status('bug_reference_deletion_start'); Status('bug_reference_deletion_start');
$dbh->bz_lock_tables('attachments WRITE', 'bug_group_map WRITE', $dbh->bz_start_transaction();
'bugs_activity WRITE', 'cc WRITE',
'dependencies WRITE', 'duplicates WRITE',
'flags WRITE', 'keywords WRITE',
'longdescs WRITE', 'votes WRITE', 'bugs READ');
foreach my $pair ('attachments/', 'bug_group_map/', 'bugs_activity/', 'cc/', foreach my $pair ('attachments/', 'bug_group_map/', 'bugs_activity/', 'cc/',
'dependencies/blocked', 'dependencies/dependson', 'dependencies/blocked', 'dependencies/dependson',
...@@ -286,7 +282,7 @@ if ($cgi->param('remove_invalid_bug_references')) { ...@@ -286,7 +282,7 @@ if ($cgi->param('remove_invalid_bug_references')) {
} }
} }
$dbh->bz_unlock_tables(); $dbh->bz_commit_transaction();
Status('bug_reference_deletion_end'); Status('bug_reference_deletion_end');
} }
...@@ -297,7 +293,7 @@ if ($cgi->param('remove_invalid_bug_references')) { ...@@ -297,7 +293,7 @@ if ($cgi->param('remove_invalid_bug_references')) {
if ($cgi->param('remove_invalid_attach_references')) { if ($cgi->param('remove_invalid_attach_references')) {
Status('attachment_reference_deletion_start'); Status('attachment_reference_deletion_start');
$dbh->bz_lock_tables('attachments WRITE', 'attach_data WRITE'); $dbh->bz_start_transaction();
my $attach_ids = my $attach_ids =
$dbh->selectcol_arrayref('SELECT attach_data.id $dbh->selectcol_arrayref('SELECT attach_data.id
...@@ -311,7 +307,7 @@ if ($cgi->param('remove_invalid_attach_references')) { ...@@ -311,7 +307,7 @@ if ($cgi->param('remove_invalid_attach_references')) {
join(',', @$attach_ids) . ')'); join(',', @$attach_ids) . ')');
} }
$dbh->bz_unlock_tables(); $dbh->bz_commit_transaction();
Status('attachment_reference_deletion_end'); Status('attachment_reference_deletion_end');
} }
...@@ -698,7 +694,7 @@ sub _check_keywords { ...@@ -698,7 +694,7 @@ sub _check_keywords {
Status('keyword_cache_start'); Status('keyword_cache_start');
if ($cgi->param('rebuildkeywordcache')) { if ($cgi->param('rebuildkeywordcache')) {
$dbh->bz_lock_tables('bugs write', 'keywords read', 'keyworddefs read'); $dbh->bz_start_transaction();
} }
my $query = q{SELECT keywords.bug_id, keyworddefs.name my $query = q{SELECT keywords.bug_id, keyworddefs.name
...@@ -765,7 +761,7 @@ sub _check_keywords { ...@@ -765,7 +761,7 @@ sub _check_keywords {
} }
if ($cgi->param('rebuildkeywordcache')) { if ($cgi->param('rebuildkeywordcache')) {
$dbh->bz_unlock_tables(); $dbh->bz_commit_transaction();
} }
} }
...@@ -804,10 +800,8 @@ if (scalar(@invalid_flags)) { ...@@ -804,10 +800,8 @@ if (scalar(@invalid_flags)) {
if ($cgi->param('remove_invalid_flags')) { if ($cgi->param('remove_invalid_flags')) {
Status('flag_deletion_start'); Status('flag_deletion_start');
my @flag_ids = map {$_->[0]} @invalid_flags; my @flag_ids = map {$_->[0]} @invalid_flags;
$dbh->bz_lock_tables('flags WRITE');
# Silently delete these flags, with no notification to requesters/setters. # Silently delete these flags, with no notification to requesters/setters.
$dbh->do('DELETE FROM flags WHERE id IN (' . join(',', @flag_ids) .')'); $dbh->do('DELETE FROM flags WHERE id IN (' . join(',', @flag_ids) .')');
$dbh->bz_unlock_tables();
Status('flag_deletion_end'); Status('flag_deletion_end');
} }
else { else {
......
...@@ -215,13 +215,13 @@ sub changePassword { ...@@ -215,13 +215,13 @@ sub changePassword {
# Update the user's password in the profiles table and delete the token # Update the user's password in the profiles table and delete the token
# from the tokens table. # from the tokens table.
$dbh->bz_lock_tables('profiles WRITE', 'tokens WRITE'); $dbh->bz_start_transaction();
$dbh->do(q{UPDATE profiles $dbh->do(q{UPDATE profiles
SET cryptpassword = ? SET cryptpassword = ?
WHERE userid = ?}, WHERE userid = ?},
undef, ($cryptedpassword, $userid) ); undef, ($cryptedpassword, $userid) );
$dbh->do('DELETE FROM tokens WHERE token = ?', undef, $::token); $dbh->do('DELETE FROM tokens WHERE token = ?', undef, $::token);
$dbh->bz_unlock_tables(); $dbh->bz_commit_transaction();
Bugzilla->logout_user_by_id($userid); Bugzilla->logout_user_by_id($userid);
...@@ -265,7 +265,7 @@ sub changeEmail { ...@@ -265,7 +265,7 @@ sub changeEmail {
# Update the user's login name in the profiles table and delete the token # Update the user's login name in the profiles table and delete the token
# from the tokens table. # from the tokens table.
$dbh->bz_lock_tables('profiles WRITE', 'tokens WRITE'); $dbh->bz_start_transaction();
$dbh->do(q{UPDATE profiles $dbh->do(q{UPDATE profiles
SET login_name = ? SET login_name = ?
WHERE userid = ?}, WHERE userid = ?},
...@@ -273,7 +273,7 @@ sub changeEmail { ...@@ -273,7 +273,7 @@ sub changeEmail {
$dbh->do('DELETE FROM tokens WHERE token = ?', undef, $::token); $dbh->do('DELETE FROM tokens WHERE token = ?', undef, $::token);
$dbh->do(q{DELETE FROM tokens WHERE userid = ? $dbh->do(q{DELETE FROM tokens WHERE userid = ?
AND tokentype = 'emailnew'}, undef, $userid); AND tokentype = 'emailnew'}, undef, $userid);
$dbh->bz_unlock_tables(); $dbh->bz_commit_transaction();
# The email address has been changed, so we need to rederive the groups # The email address has been changed, so we need to rederive the groups
my $user = new Bugzilla::User($userid); my $user = new Bugzilla::User($userid);
...@@ -308,12 +308,10 @@ sub cancelChangeEmail { ...@@ -308,12 +308,10 @@ sub cancelChangeEmail {
# check to see if it has been altered # check to see if it has been altered
if($actualemail ne $old_email) { if($actualemail ne $old_email) {
$dbh->bz_lock_tables('profiles WRITE');
$dbh->do(q{UPDATE profiles $dbh->do(q{UPDATE profiles
SET login_name = ? SET login_name = ?
WHERE userid = ?}, WHERE userid = ?},
undef, ($old_email, $userid)); undef, ($old_email, $userid));
$dbh->bz_unlock_tables();
# email has changed, so rederive groups # email has changed, so rederive groups
# Note that this is done _after_ the tables are unlocked # Note that this is done _after_ the tables are unlocked
...@@ -335,11 +333,9 @@ sub cancelChangeEmail { ...@@ -335,11 +333,9 @@ sub cancelChangeEmail {
$vars->{'new_email'} = $new_email; $vars->{'new_email'} = $new_email;
Bugzilla::Token::Cancel($::token, $vars->{'message'}, $vars); Bugzilla::Token::Cancel($::token, $vars->{'message'}, $vars);
$dbh->bz_lock_tables('tokens WRITE');
$dbh->do(q{DELETE FROM tokens WHERE userid = ? $dbh->do(q{DELETE FROM tokens WHERE userid = ?
AND tokentype = 'emailold' OR tokentype = 'emailnew'}, AND tokentype = 'emailold' OR tokentype = 'emailnew'},
undef, $userid); undef, $userid);
$dbh->bz_unlock_tables();
# Return HTTP response headers. # Return HTTP response headers.
print $cgi->header(); print $cgi->header();
......
...@@ -294,9 +294,7 @@ sub record_votes { ...@@ -294,9 +294,7 @@ sub record_votes {
# for products that only allow one vote per bug). In that case, we still # for products that only allow one vote per bug). In that case, we still
# need to clear the user's votes from the database. # need to clear the user's votes from the database.
my %affected; my %affected;
$dbh->bz_lock_tables('bugs WRITE', 'bugs_activity WRITE', $dbh->bz_start_transaction();
'votes WRITE', 'longdescs WRITE',
'products READ', 'fielddefs READ');
# Take note of, and delete the user's old votes from the database. # Take note of, and delete the user's old votes from the database.
my $bug_list = $dbh->selectcol_arrayref('SELECT bug_id FROM votes my $bug_list = $dbh->selectcol_arrayref('SELECT bug_id FROM votes
...@@ -335,7 +333,7 @@ sub record_votes { ...@@ -335,7 +333,7 @@ sub record_votes {
my $confirmed = CheckIfVotedConfirmed($id, $who); my $confirmed = CheckIfVotedConfirmed($id, $who);
push (@updated_bugs, $id) if $confirmed; push (@updated_bugs, $id) if $confirmed;
} }
$dbh->bz_unlock_tables(); $dbh->bz_commit_transaction();
$vars->{'type'} = "votes"; $vars->{'type'} = "votes";
$vars->{'mailrecipients'} = { 'changer' => Bugzilla->user->login }; $vars->{'mailrecipients'} = { 'changer' => Bugzilla->user->login };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment