Commit bcdb5a0a authored by Stan Hu's avatar Stan Hu

Fix failing MySQL spec due to deadlock condition

`spec/features/uploads/user_uploads_file_to_note_spec.rb` was failing in
master because MySQL detected a deadlock when a DELETE and INSERT for
the same indexed item occurred within a transaction in the `uploads`
table.  Due to InnoDB's next-key locking algorithm
(innodb_locks_unsafe_for_binlog in
https://dev.mysql.com/doc/refman/5.5/en/innodb-parameters.html), InnoDB
sets an exclusive lock for any of the indexed records it encounters, so
the INSERT will fail until the DELETE is committed.

To fix this, we just disable the transaction for MySQL and keep
it for PostgreSQL.

Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/55161
parent 0e510780
...@@ -23,13 +23,23 @@ module RecordsUploads ...@@ -23,13 +23,23 @@ module RecordsUploads
return unless model return unless model
return unless file && file.exists? return unless file && file.exists?
Upload.transaction do # MySQL InnoDB may encounter a deadlock if a deletion and an
uploads.where(path: upload_path).delete_all # insert is in the same transaction due to its next-key locking
upload.delete if upload # algorithm, so we need to skip the transaction.
# https://gitlab.com/gitlab-org/gitlab-ce/issues/55161#note_131556351
self.upload = build_upload.tap(&:save!) if Gitlab::Database.mysql?
readd_upload
else
Upload.transaction { readd_upload }
end end
end end
def readd_upload
uploads.where(path: upload_path).delete_all
upload.delete if upload
self.upload = build_upload.tap(&:save!)
end
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
def upload_path def upload_path
......
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