Replace advisory lock with unique index usage in maven packages upload

Context

To fix Database race condition when uploading maven pa... (#424238 - closed), we introduced Use advisory lock to prevent concurrent inserts... (!172576 - merged) • Moaz Khalifa • 17.7.

The advisory lock solution should be a temp one in favour of an ultimate solution using a database unique index. The unique index was introduced in Replace tmp index with unique index for Maven p... (!190992 - merged) • Moaz Khalifa • 18.1.

Now, we need to replace the usage of the advisory lock when creating new maven packages with the unique index to prevent duplicates.

Solution

  • Remove Packages::Maven::Package#prevent_concurrent_inserts.
  • Update the rescue block in Packages::Maven::CreatePackageService to take into consideration the ActiveRecord::RecordNotUnique error that could be raised because of the unique index in case of a race condition:
    rescue ActiveRecord::RecordInvalid, ActiveRecord::RecordNotUnique => e
      reason = if e.is_a?(ActiveRecord::RecordNotUnique) || e.record.errors&.of_kind?(:name, :taken)
                :name_taken
               else
                :invalid_parameter
               end
Edited by 🤖 GitLab Bot 🤖