20447: Don't lock containers table for CR name/description updates. 20447-less-table-locking
authorTom Clegg <tom@curii.com>
Sat, 29 Apr 2023 04:23:36 +0000 (00:23 -0400)
committerTom Clegg <tom@curii.com>
Sat, 29 Apr 2023 04:23:36 +0000 (00:23 -0400)
Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tom@curii.com>

services/api/app/controllers/arvados/v1/container_requests_controller.rb

index 75f70b1a2d7a8637cccad16e353b3ee757743171..586567cb293e05efbcd64d18bdb3c383f3cb91de 100644 (file)
@@ -38,10 +38,18 @@ class Arvados::V1::ContainerRequestsController < ApplicationController
   end
 
   def update
-    # Lock containers table to avoid deadlock in cascading priority update (see #20240)
-    Container.transaction do
-      ActiveRecord::Base.connection.execute "LOCK TABLE containers IN EXCLUSIVE MODE"
+    if (resource_attrs.keys - [:owner_uuid, :name, :description, :properties]).empty?
+      # If no attributes are being updated besides these, there are no
+      # cascading changes to other rows/tables, so we should just use
+      # row locking.
+      @object.reload(lock: true)
       super
+    else
+      # Lock containers table to avoid deadlock in cascading priority update (see #20240)
+      Container.transaction do
+        ActiveRecord::Base.connection.execute "LOCK TABLE containers IN EXCLUSIVE MODE"
+        super
+      end
     end
   end
 end