Commit 0dadaed4 authored by lpsolit%gmail.com's avatar lpsolit%gmail.com

Bug 403824: Replace table locks in most Bugzilla files with transactions - Patch…

Bug 403824: Replace table locks in most Bugzilla files with transactions - Patch by Emmanuel Seyman <eseyman@linagora.com> r/a=mkanat
parent ec38a93e
...@@ -479,18 +479,8 @@ sub update { ...@@ -479,18 +479,8 @@ sub update {
}); });
Bugzilla::Flag::validate($cgi, $bug->id, $attachment->id); Bugzilla::Flag::validate($cgi, $bug->id, $attachment->id);
# Lock database tables in preparation for updating the attachment. # Start a transaction in preparation for updating the attachment.
$dbh->bz_lock_tables('attachments WRITE', 'flags WRITE' , $dbh->bz_start_transaction();
'flagtypes READ', 'fielddefs READ', 'bugs_activity WRITE',
'flaginclusions AS i READ', 'flagexclusions AS e READ',
# cc, bug_group_map, user_group_map, and groups are in here so we
# can check the permissions of flag requestees and email addresses
# on the flag type cc: lists via the CanSeeBug
# function call in Flag::notify. group_group_map is in here si
# Bugzilla::User can flatten groups.
'bugs WRITE', 'profiles READ', 'email_setting READ',
'cc READ', 'bug_group_map READ', 'user_group_map READ',
'group_group_map READ', 'groups READ', 'group_control_map READ');
# Quote the description and content type for use in the SQL UPDATE statement. # Quote the description and content type for use in the SQL UPDATE statement.
my $description = $cgi->param('description'); my $description = $cgi->param('description');
...@@ -560,8 +550,8 @@ sub update { ...@@ -560,8 +550,8 @@ sub update {
$attachment->isprivate, $updated_attachment->isprivate); $attachment->isprivate, $updated_attachment->isprivate);
} }
# Unlock all database tables now that we are finished updating the database. # Commit the transaction now that we are finished updating the database.
$dbh->bz_unlock_tables(); $dbh->bz_commit_transaction();
# If the user submitted a comment while editing the attachment, # If the user submitted a comment while editing the attachment,
# add the comment to the bug. # add the comment to the bug.
...@@ -634,14 +624,14 @@ sub delete_attachment { ...@@ -634,14 +624,14 @@ sub delete_attachment {
$template->process("attachment/delete_reason.txt.tmpl", $vars, \$msg) $template->process("attachment/delete_reason.txt.tmpl", $vars, \$msg)
|| ThrowTemplateError($template->error()); || ThrowTemplateError($template->error());
$dbh->bz_lock_tables('attachments WRITE', 'attach_data WRITE', 'flags WRITE'); $dbh->bz_start_transaction();
$dbh->do('DELETE FROM attach_data WHERE id = ?', undef, $attachment->id); $dbh->do('DELETE FROM attach_data WHERE id = ?', undef, $attachment->id);
$dbh->do('UPDATE attachments SET mimetype = ?, ispatch = ?, isurl = ?, $dbh->do('UPDATE attachments SET mimetype = ?, ispatch = ?, isurl = ?,
isobsolete = ? isobsolete = ?
WHERE attach_id = ?', undef, WHERE attach_id = ?', undef,
('text/plain', 0, 0, 1, $attachment->id)); ('text/plain', 0, 0, 1, $attachment->id));
$dbh->do('DELETE FROM flags WHERE attach_id = ?', undef, $attachment->id); $dbh->do('DELETE FROM flags WHERE attach_id = ?', undef, $attachment->id);
$dbh->bz_unlock_tables; $dbh->bz_commit_transaction();
# If the attachment is stored locally, remove it. # If the attachment is stored locally, remove it.
if (-e $attachment->_get_local_filename) { if (-e $attachment->_get_local_filename) {
......
...@@ -154,9 +154,8 @@ my $changes = { ...@@ -154,9 +154,8 @@ my $changes = {
profiles => [], # ['userid'], profiles => [], # ['userid'],
}; };
# Lock tables # Start the transaction
my @locked_tables = map {"$_ WRITE"} keys(%$changes); $dbh->bz_start_transaction();
$dbh->bz_lock_tables(@locked_tables);
# Delete old records from logincookies and tokens tables. # Delete old records from logincookies and tokens tables.
$dbh->do('DELETE FROM logincookies WHERE userid = ?', undef, $old_id); $dbh->do('DELETE FROM logincookies WHERE userid = ?', undef, $old_id);
...@@ -230,7 +229,7 @@ print "OK, records in the 'mailto' column of the 'whine_schedules' table\n" . ...@@ -230,7 +229,7 @@ print "OK, records in the 'mailto' column of the 'whine_schedules' table\n" .
# Delete the old record from the profiles table. # Delete the old record from the profiles table.
$dbh->do('DELETE FROM profiles WHERE userid = ?', undef, $old_id); $dbh->do('DELETE FROM profiles WHERE userid = ?', undef, $old_id);
# Unlock tables # Commit the transaction
$dbh->bz_unlock_tables(); $dbh->bz_commit_transaction();
print "Done.\n"; print "Done.\n";
...@@ -70,7 +70,7 @@ if ($userid) { ...@@ -70,7 +70,7 @@ if ($userid) {
# If the query name contains invalid characters, don't import. # If the query name contains invalid characters, don't import.
$name =~ /[<>&]/ && next; $name =~ /[<>&]/ && next;
trick_taint($name); trick_taint($name);
$dbh->bz_lock_tables('namedqueries WRITE'); $dbh->bz_start_transaction();
my $query = $dbh->selectrow_array( my $query = $dbh->selectrow_array(
"SELECT query FROM namedqueries " . "SELECT query FROM namedqueries " .
"WHERE userid = ? AND name = ?", "WHERE userid = ? AND name = ?",
...@@ -80,7 +80,7 @@ if ($userid) { ...@@ -80,7 +80,7 @@ if ($userid) {
"(userid, name, query) VALUES " . "(userid, name, query) VALUES " .
"(?, ?, ?)", undef, ($userid, $name, $value)); "(?, ?, ?)", undef, ($userid, $name, $value));
} }
$dbh->bz_unlock_tables(); $dbh->bz_commit_transaction();
} }
$cgi->remove_cookie($cookiename); $cgi->remove_cookie($cookiename);
} }
......
...@@ -255,7 +255,7 @@ sub SaveEmail { ...@@ -255,7 +255,7 @@ sub SaveEmail {
########################################################################### ###########################################################################
# Role-based preferences # Role-based preferences
########################################################################### ###########################################################################
$dbh->bz_lock_tables("email_setting WRITE"); $dbh->bz_start_transaction();
# Delete all the user's current preferences # Delete all the user's current preferences
$dbh->do("DELETE FROM email_setting WHERE user_id = ?", undef, $user->id); $dbh->do("DELETE FROM email_setting WHERE user_id = ?", undef, $user->id);
...@@ -302,7 +302,7 @@ sub SaveEmail { ...@@ -302,7 +302,7 @@ sub SaveEmail {
} }
} }
$dbh->bz_unlock_tables(); $dbh->bz_commit_transaction();
########################################################################### ###########################################################################
# User watching # User watching
...@@ -311,11 +311,7 @@ sub SaveEmail { ...@@ -311,11 +311,7 @@ sub SaveEmail {
&& (defined $cgi->param('new_watchedusers') && (defined $cgi->param('new_watchedusers')
|| defined $cgi->param('remove_watched_users'))) || defined $cgi->param('remove_watched_users')))
{ {
# Just in case. Note that this much locking is actually overkill: $dbh->bz_start_transaction();
# we don't really care if anyone reads the watch table. So
# some small amount of contention could be gotten rid of by
# using user-defined locks rather than table locking.
$dbh->bz_lock_tables('watch WRITE', 'profiles READ');
# Use this to protect error messages on duplicate submissions # Use this to protect error messages on duplicate submissions
my $old_watch_ids = my $old_watch_ids =
...@@ -356,7 +352,7 @@ sub SaveEmail { ...@@ -356,7 +352,7 @@ sub SaveEmail {
} }
} }
$dbh->bz_unlock_tables(); $dbh->bz_commit_transaction();
} }
} }
......
...@@ -130,9 +130,7 @@ sub show_user { ...@@ -130,9 +130,7 @@ sub show_user {
my $canedit = (Bugzilla->params->{'usevotes'} && $userid == $who) ? 1 : 0; my $canedit = (Bugzilla->params->{'usevotes'} && $userid == $who) ? 1 : 0;
$dbh->bz_lock_tables('bugs READ', 'products READ', 'votes WRITE', $dbh->bz_start_transaction();
'cc READ', 'bug_group_map READ', 'user_group_map READ',
'group_group_map READ', 'groups READ', 'group_control_map READ');
if ($canedit && $bug_id) { if ($canedit && $bug_id) {
# Make sure there is an entry for this bug # Make sure there is an entry for this bug
...@@ -197,7 +195,7 @@ sub show_user { ...@@ -197,7 +195,7 @@ sub show_user {
} }
$dbh->do('DELETE FROM votes WHERE vote_count <= 0'); $dbh->do('DELETE FROM votes WHERE vote_count <= 0');
$dbh->bz_unlock_tables(); $dbh->bz_commit_transaction();
$vars->{'canedit'} = $canedit; $vars->{'canedit'} = $canedit;
$vars->{'voting_user'} = { "login" => $name }; $vars->{'voting_user'} = { "login" => $name };
......
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