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 {
});
Bugzilla::Flag::validate($cgi, $bug->id, $attachment->id);
# Lock database tables in preparation for updating the attachment.
$dbh->bz_lock_tables('attachments WRITE', 'flags WRITE' ,
'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');
# Start a transaction in preparation for updating the attachment.
$dbh->bz_start_transaction();
# Quote the description and content type for use in the SQL UPDATE statement.
my $description = $cgi->param('description');
......@@ -560,8 +550,8 @@ sub update {
$attachment->isprivate, $updated_attachment->isprivate);
}
# Unlock all database tables now that we are finished updating the database.
$dbh->bz_unlock_tables();
# Commit the transaction now that we are finished updating the database.
$dbh->bz_commit_transaction();
# If the user submitted a comment while editing the attachment,
# add the comment to the bug.
......@@ -634,14 +624,14 @@ sub delete_attachment {
$template->process("attachment/delete_reason.txt.tmpl", $vars, \$msg)
|| 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('UPDATE attachments SET mimetype = ?, ispatch = ?, isurl = ?,
isobsolete = ?
WHERE attach_id = ?', undef,
('text/plain', 0, 0, 1, $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 (-e $attachment->_get_local_filename) {
......
......@@ -154,9 +154,8 @@ my $changes = {
profiles => [], # ['userid'],
};
# Lock tables
my @locked_tables = map {"$_ WRITE"} keys(%$changes);
$dbh->bz_lock_tables(@locked_tables);
# Start the transaction
$dbh->bz_start_transaction();
# Delete old records from logincookies and tokens tables.
$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" .
# Delete the old record from the profiles table.
$dbh->do('DELETE FROM profiles WHERE userid = ?', undef, $old_id);
# Unlock tables
$dbh->bz_unlock_tables();
# Commit the transaction
$dbh->bz_commit_transaction();
print "Done.\n";
......@@ -70,7 +70,7 @@ if ($userid) {
# If the query name contains invalid characters, don't import.
$name =~ /[<>&]/ && next;
trick_taint($name);
$dbh->bz_lock_tables('namedqueries WRITE');
$dbh->bz_start_transaction();
my $query = $dbh->selectrow_array(
"SELECT query FROM namedqueries " .
"WHERE userid = ? AND name = ?",
......@@ -80,7 +80,7 @@ if ($userid) {
"(userid, name, query) VALUES " .
"(?, ?, ?)", undef, ($userid, $name, $value));
}
$dbh->bz_unlock_tables();
$dbh->bz_commit_transaction();
}
$cgi->remove_cookie($cookiename);
}
......
......@@ -255,7 +255,7 @@ sub SaveEmail {
###########################################################################
# Role-based preferences
###########################################################################
$dbh->bz_lock_tables("email_setting WRITE");
$dbh->bz_start_transaction();
# Delete all the user's current preferences
$dbh->do("DELETE FROM email_setting WHERE user_id = ?", undef, $user->id);
......@@ -302,7 +302,7 @@ sub SaveEmail {
}
}
$dbh->bz_unlock_tables();
$dbh->bz_commit_transaction();
###########################################################################
# User watching
......@@ -311,11 +311,7 @@ sub SaveEmail {
&& (defined $cgi->param('new_watchedusers')
|| defined $cgi->param('remove_watched_users')))
{
# Just in case. Note that this much locking is actually overkill:
# 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');
$dbh->bz_start_transaction();
# Use this to protect error messages on duplicate submissions
my $old_watch_ids =
......@@ -356,7 +352,7 @@ sub SaveEmail {
}
}
$dbh->bz_unlock_tables();
$dbh->bz_commit_transaction();
}
}
......
......@@ -130,9 +130,7 @@ sub show_user {
my $canedit = (Bugzilla->params->{'usevotes'} && $userid == $who) ? 1 : 0;
$dbh->bz_lock_tables('bugs READ', 'products READ', 'votes WRITE',
'cc READ', 'bug_group_map READ', 'user_group_map READ',
'group_group_map READ', 'groups READ', 'group_control_map READ');
$dbh->bz_start_transaction();
if ($canedit && $bug_id) {
# Make sure there is an entry for this bug
......@@ -197,7 +195,7 @@ sub show_user {
}
$dbh->do('DELETE FROM votes WHERE vote_count <= 0');
$dbh->bz_unlock_tables();
$dbh->bz_commit_transaction();
$vars->{'canedit'} = $canedit;
$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