X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/39c17737ac69d7693684fe2f95bef0ec235a28bf..96609221d1133eb1340c4ef5efb27303181c0b73:/services/api/lib/update_priority.rb diff --git a/services/api/lib/update_priority.rb b/services/api/lib/update_priority.rb index 21cd74bae6..c688ac008b 100644 --- a/services/api/lib/update_priority.rb +++ b/services/api/lib/update_priority.rb @@ -12,14 +12,19 @@ module UpdatePriority # # If container priority=0 but there are committed container requests # for it with priority>0, update priority. - def self.update_priority + # + # Normally, update_priority is a no-op if another thread/process is + # already updating. Test cases that need to check priorities after + # updating can force a (possibly overlapping) update in the current + # thread/transaction by setting the "nolock" flag. See #14878. + def self.update_priority(nolock: false) if !File.owned?(Rails.root.join('tmp')) Rails.logger.warn("UpdatePriority: not owner of #{Rails.root}/tmp, skipping") return end lockfile = Rails.root.join('tmp', 'update_priority.lock') File.open(lockfile, File::RDWR|File::CREAT, 0600) do |f| - return unless f.flock(File::LOCK_NB|File::LOCK_EX) + return unless nolock || f.flock(File::LOCK_NB|File::LOCK_EX) # priority>0 but should be 0: ActiveRecord::Base.connection.