Merge branch '20447-less-table-locking'
authorTom Clegg <tom@curii.com>
Mon, 1 May 2023 16:07:45 +0000 (12:07 -0400)
committerTom Clegg <tom@curii.com>
Mon, 1 May 2023 16:07:45 +0000 (12:07 -0400)
fixes #20447

Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tom@curii.com>

services/api/app/controllers/arvados/v1/container_requests_controller.rb
services/api/app/controllers/arvados/v1/containers_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
index b06d65a36c13bfda924fb40f6408bcfe8363d748..83f99bf920c9e2d63c29f7d52f46a9c2d2d20f5e 100644 (file)
@@ -29,10 +29,19 @@ class Arvados::V1::ContainersController < 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 - [:cost, :gateway_address, :output_properties, :progress, :runtime_status]).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