X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/58e057254087f406ca4146da7031187487b0ddbc..401c2c71179825e6c3350177c0f46c503d66a061:/services/api/lib/update_priorities.rb diff --git a/services/api/lib/update_priorities.rb b/services/api/lib/update_priorities.rb index b59859a82a..94115340df 100644 --- a/services/api/lib/update_priorities.rb +++ b/services/api/lib/update_priorities.rb @@ -3,9 +3,21 @@ # SPDX-License-Identifier: AGPL-3.0 def row_lock_for_priority_update container_uuid + # Locks all the containers under this container, and also any + # immediate parent containers. This ensures we have locked + # everything that gets touched by either a priority update or state + # update. ActiveRecord::Base.connection.exec_query %{ - select 1 from containers where containers.uuid in (select pri_container_uuid from container_tree($1)) order by containers.uuid for update - }, 'select_for_update_priorities', [[nil, container_uuid]] + select 1 from containers where containers.uuid in ( + select pri_container_uuid from container_tree($1) +UNION + select container_requests.requesting_container_uuid from container_requests + where container_requests.container_uuid = $1 + and container_requests.state = 'Committed' + and container_requests.requesting_container_uuid is not NULL +) + order by containers.uuid for update + }, 'select_for_update_priorities', [container_uuid] end def update_priorities starting_container_uuid @@ -15,5 +27,5 @@ def update_priorities starting_container_uuid ActiveRecord::Base.connection.exec_query %{ update containers set priority=computed.upd_priority from container_tree_priorities($1) as computed where containers.uuid = computed.pri_container_uuid and priority != computed.upd_priority -}, 'update_priorities', [[nil, starting_container_uuid]] +}, 'update_priorities', [starting_container_uuid] end