1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
5 def row_lock_for_priority_update container_uuid
6 # Locks all the containers under this container, and also any
7 # immediate parent containers. This ensures we have locked
8 # everything that gets touched by either a priority update or state
10 ActiveRecord::Base.connection.exec_query %{
11 select 1 from containers where containers.uuid in (
12 select pri_container_uuid from container_tree($1)
14 select container_requests.requesting_container_uuid from container_requests
15 where container_requests.container_uuid = $1
16 and container_requests.state = 'Committed'
17 and container_requests.requesting_container_uuid is not NULL
19 order by containers.uuid for update
20 }, 'select_for_update_priorities', [container_uuid]
23 def update_priorities starting_container_uuid
24 # Ensure the row locks were taken in order
25 row_lock_for_priority_update starting_container_uuid
27 ActiveRecord::Base.connection.exec_query %{
28 update containers set priority=computed.upd_priority from container_tree_priorities($1) as computed
29 where containers.uuid = computed.pri_container_uuid and priority != computed.upd_priority
30 }, 'update_priorities', [starting_container_uuid]